Free cookie consent management tool by TermsFeed Policy Generator

Ignore:
Timestamp:
05/10/11 17:25:35 (14 years ago)
Author:
jhelm
Message:

#1329: Implemented PriorityRulesVector based encoding and added new operators to the JSMEncoding. Added Gantt-Charts for visualization of schedules and problems.

Location:
branches/Scheduling/HeuristicLab.Problems.Scheduling/3.3/Encodings/JobSequenceMatrix
Files:
6 added
1 deleted
6 edited

Legend:

Unmodified
Added
Removed
  • branches/Scheduling/HeuristicLab.Problems.Scheduling/3.3/Encodings/JobSequenceMatrix/Crossovers/JSMCrossover.cs

    r6121 r6177  
    3030  [Item("JSMCrossover", "An operator which crosses two JSM representations.")]
    3131  [StorableClass]
    32   public abstract class JSMCrossover : JSSPCrossover, IStochasticOperator, IJSMOperator {
    33     public ILookupParameter<IRandom> RandomParameter {
    34       get { return (LookupParameter<IRandom>)Parameters["Random"]; }
    35     }
     32  public abstract class JSMCrossover : JSSPCrossover, IJSMOperator {
    3633
    3734    [StorableConstructor]
     
    4037    public JSMCrossover()
    4138      : base() {
    42       Parameters.Add(new LookupParameter<IRandom>("Random", "The pseudo random number generator which should be used for stochastic manipulation operators."));
    4339    }
    4440
    45     protected abstract JSSPEncoding Crossover(IRandom random, JSMEncoding parent1, JSMEncoding parent2);
     41    public abstract IJSSPEncoding Crossover(IRandom random, JSMEncoding parent1, JSMEncoding parent2);
    4642
    4743    public override IOperation Apply() {
    48       ItemArray<JSSPEncoding> parents = ParentsParameter.ActualValue;
     44      ItemArray<IJSSPEncoding> parents = ParentsParameter.ActualValue;
    4945
    5046      ChildParameter.ActualValue =
  • branches/Scheduling/HeuristicLab.Problems.Scheduling/3.3/Encodings/JobSequenceMatrix/Crossovers/JSMSXXCrossover.cs

    r6121 r6177  
    2727using HeuristicLab.Persistence.Default.CompositeSerializers.Storable;
    2828using HeuristicLab.Core;
     29using HeuristicLab.Problems.Scheduling.Interfaces;
     30using HeuristicLab.Encodings.PermutationEncoding;
    2931
    3032namespace HeuristicLab.Problems.Scheduling.Encodings.JobSequenceMatrix.Crossovers {
    31   [Item("JSM Subsequence Exchange Crossover", "Represents a crossover operation swapping subsequences of the parents to generate offspring.")]
     33  [Item("JSM Subsequence Exchange Crossover", "Represents a crossover operation identifiying and exchanging equal subsequences of the parents to generate offspring.")]
    3234  [StorableClass]
    3335  public class JSMSXXCrossover : JSMCrossover {
     
    4345    public JSMSXXCrossover () : base () {}
    4446
    45     protected override JSSPEncoding Crossover(IRandom random, JSMEncoding parent1, JSMEncoding parent2) {
    46       JSSPEncoding result = parent1;
     47    public static IJSSPEncoding Cross(IRandom random, JSMEncoding parent1, JSMEncoding parent2) {
     48      JSMEncoding result = new JSMEncoding();
    4749
     50      int subSequenceLength = 3;
     51
     52      for (int i = 0; i < parent1.JobSequenceMatrix.Count; i++) {
     53        Permutation p1 = (Permutation)parent1.JobSequenceMatrix[i].Clone();
     54        Permutation p2 = (Permutation)parent2.JobSequenceMatrix[i].Clone();
     55        FindAndExchangeSubsequences(p1, p2, subSequenceLength);
     56        //parent1.JobSequenceMatrix[i] = p1;
     57        //parent2.JobSequenceMatrix[i] = p2;
     58
     59        result.JobSequenceMatrix.Add(p1);
     60      }
    4861
    4962      return result;
    5063    }
     64
     65    private static void FindAndExchangeSubsequences(Permutation p1, Permutation p2, int subSequenceLength) {
     66      for (int i = 0; i <= p1.Length - subSequenceLength; i++) {
     67        for (int j = 0; j <= p2.Length - subSequenceLength; j++) {
     68          int[] ss1 = GetSubSequenceAtPosition(p1, i, subSequenceLength);
     69          int[] ss2 = GetSubSequenceAtPosition(p2, j, subSequenceLength);
     70          if (AreEqualSubsequences(ss1, ss2)) {
     71            ExchangeSubsequences(p1, i, p2, j, subSequenceLength);
     72            break;
     73          }
     74        }
     75      }
     76    }
     77    private static void ExchangeSubsequences(Permutation p1, int index1, Permutation p2, int index2, int subSequenceLength) {
     78      Permutation aux = (Permutation)p1.Clone();
     79      for (int i = 0; i < subSequenceLength; i++) {
     80        p1[i + index1] = p2[i + index2];
     81        p2[i + index2] = aux[i + index1];
     82      }
     83    }
     84    private static bool AreEqualSubsequences(int[] ss1, int[] ss2) {
     85      int counter = 0;
     86      for (int i = 0; i < ss1.Length; i++) {
     87        for (int j = 0; j < ss2.Length; j++) {
     88          if (ss1[i] == ss2[j])
     89            counter++;
     90        }
     91      }
     92      return counter == ss1.Length;
     93    }
     94    private static int[] GetSubSequenceAtPosition(Permutation p1, int index, int subSequenceLength) {
     95      int[] result = new int[subSequenceLength];
     96      for (int i = 0; i < subSequenceLength; i++)
     97        result[i] = p1[i + index];
     98
     99      return result;
     100    }
     101
     102
     103
     104    public override IJSSPEncoding Crossover(IRandom random, JSMEncoding parent1, JSMEncoding parent2) {
     105      return Cross(random, parent1, parent2);
     106    }
    51107  }
    52108}
  • branches/Scheduling/HeuristicLab.Problems.Scheduling/3.3/Encodings/JobSequenceMatrix/JSMDecoder.cs

    r6121 r6177  
    3535  [Item("Job Sequencing Matrix Decoder", "Applies the GifflerThompson algorithm to create an active schedule from a JobSequencing Matrix.")]
    3636  [StorableClass]
    37   public class JSMDecoder : NamedItem {
     37  public class JSMDecoder : JSSPDecoder<JSMEncoding>, IStochasticOperator {
    3838    [StorableConstructor]
    3939    protected JSMDecoder(bool deserializing) : base(deserializing) { }
     
    4141      : base(original, cloner) {
    4242        this.resultingSchedule = cloner.Clone(original.resultingSchedule);
     43        this.decodingErrorPolicy = original.decodingErrorPolicy;
     44        this.forcingStrategy = original.forcingStrategy;
    4345    }
    4446    public override IDeepCloneable Clone(Cloner cloner) {
     
    4648    }
    4749
     50    public ILookupParameter<IRandom> RandomParameter {
     51      get { return (LookupParameter<IRandom>)Parameters["Random"]; }
     52    }
     53
    4854    [Storable]
    4955    private Schedule resultingSchedule;
    5056
    5157    [Storable]
    52     private IRandom random;
    53 
    54     public JSMDecoder(IntValue nrOfResources, IRandom r)
     58    private JSMDecodingErrorPolicyTypes decodingErrorPolicy = JSMDecodingErrorPolicyTypes.GuidedPolicy;
     59
     60    [Storable]
     61    private JSMForcingStrategyTypes forcingStrategy = JSMForcingStrategyTypes.ShiftForcing;
     62
     63    public JSMDecoder()
    5564      : base() {
    56       resultingSchedule = new Schedule(nrOfResources);
    57       random = r;
    58     }
    59 
    60 
    61     public Schedule CreateScheduleFromJSM(ItemList<JSSPJob> jobs, ItemList<Permutation> jobSequenceMatrix) {
    62       //Reset scheduled tasks in result
    63       foreach (JSSPJob j in jobs) {
    64         foreach (JSSPTask t in j.Tasks) {
    65           t.IsScheduled.Value = false;
    66         }
    67       }
    68 
    69       //GT-Algorithm
    70       //STEP 0 - Compute a list of "earliest operations"
    71       ItemList<JSSPTask> earliestTasksList = GetEarliestNotScheduledTasks(jobs);
    72       while (earliestTasksList.Count > 0) {
    73         //STEP 1 - Get earliest not scheduled operation with minimal earliest completing time
    74         JSSPTask minimal = GetTaskWithMinimalEC(earliestTasksList);
    75 
    76         //STEP 2 - Compute a conflict set of all operations that can be scheduled on the machine the previously selected operation runs on
    77         ItemList<JSSPTask> conflictSet = GetConflictSetForTask(minimal, earliestTasksList);
    78 
    79         //STEP 3 - Select an operation from the conflict set (various methods depending on how the algorithm should work..)
    80         JSSPTask selectedTask = SelectTaskFromConflictSet(minimal.ResourceNr, conflictSet, jobSequenceMatrix);
    81 
    82         //STEP 4 - Adding the selected operation to the current schedule
    83         AddTaskToSchedule(selectedTask);
    84 
    85         //STEP 5 - Back to STEP 1
    86         earliestTasksList = GetEarliestNotScheduledTasks(jobs);
    87       }
    88 
    89       return resultingSchedule;
    90     }
     65      Parameters.Add(new LookupParameter<IRandom>("Random", "The pseudo random number generator which should be used for stochastic manipulation operators."));
     66    }
     67
    9168    private ItemList<JSSPTask> GetEarliestNotScheduledTasks(ItemList<JSSPJob> jobs) {
    9269      ItemList<JSSPTask> result = new ItemList<JSSPTask>();
     
    132109        IntValue solutionCandidateJobNr = new IntValue(jsm[conflictedResource.Value][progressOnResource.Value]);
    133110        foreach (JSSPTask t in conflictSet) {
    134           if (t.Job.JobIndex == solutionCandidateJobNr)
     111          if (t.Job.Index.Value == solutionCandidateJobNr.Value)
    135112            result = t;
    136113        }
     
    141118      //Repairing happens here
    142119      if (result == null) {
    143         result = conflictSet[random.Next(conflictSet.Count - 1)];
     120        //Decoding Error Policy BEGIN
     121        //CHOOSE OTHER RESOLUTION FOR CONFLICT SET
     122        result = ApplyDecodingErrorPolicy(conflictSet);
     123        //result = conflictSet[RandomParameter.ActualValue.Next(conflictSet.Count - 1)];
     124        //Decoding Error Policy END
     125
     126
     127        //Determine index of new resolution
    144128        int index = 0;
    145         foreach (int jobAssignment in jsm[conflictedResource.Value]) {
    146           if (jobAssignment == result.Job.JobIndex.Value)
    147             break;
     129        while (index < jsm[conflictedResource.Value].Length &&
     130          jsm[conflictedResource.Value][index] != result.Job.Index.Value)
    148131          index++;
    149         }
    150         jsm[conflictedResource.Value][index] = jsm[conflictedResource.Value][progressOnResource.Value];
    151         jsm[conflictedResource.Value][progressOnResource.Value] = result.Job.JobIndex.Value;
    152       }
    153        
    154 
    155       return result;
     132
     133
     134        //Forcing Strategy BEGIN
     135        ApplyForcingStrategy(jsm, conflictedResource.Value, index, progressOnResource.Value, result.Job.Index.Value);
     136       
     137        //ForcingStrategy END
     138      }
     139      return result;
     140    }
     141
     142    private void ApplyForcingStrategy(ItemList<Permutation> jsm, int conflictedResource, int newResolutionIndex, int progressOnResource, int newResolution) {
     143      //if (forcingStrategy == JSMForcingStrategyTypes.SwapForcing) {
     144        //SwapForcing
     145        jsm[conflictedResource][newResolutionIndex] = jsm[conflictedResource][progressOnResource];
     146        jsm[conflictedResource][progressOnResource] = newResolution;
     147      /*} else {
     148        //ShiftForcing
     149
     150      } */
     151    }
     152
     153    private JSSPTask ApplyDecodingErrorPolicy(ItemList<JSSPTask> conflictSet) {
     154      //if (decodingErrorPolicy == JSMDecodingErrorPolicyTypes.RandomPolicy) {
     155        //Random
     156        return conflictSet[RandomParameter.ActualValue.Next(conflictSet.Count - 1)];
     157      /*} else {
     158        //Guided
     159
     160      }    */
    156161    }
    157162    private DoubleValue ComputeEarliestStartTime(JSSPTask t) {
     
    174179      affectedResource.Tasks.Add(selectedTask);
    175180    }
     181
     182    public override Schedule CreateScheduleFromEncoding(JSMEncoding solution) {
     183      ItemList<Permutation> jobSequenceMatrix = solution.JobSequenceMatrix;
     184
     185      resultingSchedule = new Schedule(new IntValue(Jobs[0].Tasks.Count));
     186
     187      //Reset scheduled tasks in result
     188      foreach (JSSPJob j in Jobs) {
     189        foreach (JSSPTask t in j.Tasks) {
     190          t.IsScheduled.Value = false;
     191        }
     192      }
     193
     194      //GT-Algorithm
     195      //STEP 0 - Compute a list of "earliest operations"
     196      ItemList<JSSPTask> earliestTasksList = GetEarliestNotScheduledTasks(Jobs);
     197      while (earliestTasksList.Count > 0) {
     198        //STEP 1 - Get earliest not scheduled operation with minimal earliest completing time
     199        JSSPTask minimal = GetTaskWithMinimalEC(earliestTasksList);
     200
     201        //STEP 2 - Compute a conflict set of all operations that can be scheduled on the machine the previously selected operation runs on
     202        ItemList<JSSPTask> conflictSet = GetConflictSetForTask(minimal, earliestTasksList);
     203
     204        //STEP 3 - Select an operation from the conflict set (various methods depending on how the algorithm should work..)
     205        JSSPTask selectedTask = SelectTaskFromConflictSet(minimal.ResourceNr, conflictSet, jobSequenceMatrix);
     206
     207        //STEP 4 - Adding the selected operation to the current schedule
     208        AddTaskToSchedule(selectedTask);
     209
     210        //STEP 5 - Back to STEP 1
     211        earliestTasksList = GetEarliestNotScheduledTasks(Jobs);
     212      }
     213
     214      return resultingSchedule;
     215    }
     216
     217    public override IOperation Apply() {
     218      return base.Apply();
     219    }
    176220  }
    177221}
  • branches/Scheduling/HeuristicLab.Problems.Scheduling/3.3/Encodings/JobSequenceMatrix/JSMEncoding.cs

    r6121 r6177  
    2929using HeuristicLab.Encodings.PermutationEncoding;
    3030using HeuristicLab.Data;
    31 using HeuristicLab.Problems.Scheduling.Encodings;
     31using HeuristicLab.Problems.Scheduling.Interfaces;
     32using HeuristicLab.Problems.Scheduling.Encodings.JobSequenceMatrix.Crossovers;
     33using HeuristicLab.Problems.Scheduling.Encodings.JobSequenceMatrix.Manipulators;
    3234
    3335namespace HeuristicLab.Problems.Scheduling.Encodings.JobSequenceMatrix {
    3436  [Item("Job Sequencing Matrix Encoding", "Represents a solution for a standard JobShop Scheduling Problem.")]
    3537  [StorableClass]
    36   public class JSMEncoding : JSSPEncoding{
     38  public class JSMEncoding : ParameterizedNamedItem, IJSSPEncoding{
    3739    [StorableConstructor]
    3840    protected JSMEncoding(bool deserializing) : base(deserializing) { }
     
    5254    }
    5355
    54     public override Schedule ToSchedule(IntValue nrOfResources, ItemList<JSSPJob> jobs, IRandom random) {
    55       JSMDecoder decoder = new JSMDecoder(nrOfResources, random);
    56       return decoder.CreateScheduleFromJSM (jobs, JobSequenceMatrix);
    57     }
    58 
    5956    public override string ToString() {
    6057      StringBuilder sb = new StringBuilder();
  • branches/Scheduling/HeuristicLab.Problems.Scheduling/3.3/Encodings/JobSequenceMatrix/JSMRandomCreator.cs

    r6121 r6177  
    6464      JSMEncoding solution = new JSMEncoding();
    6565      IntValue nrOfJobs = new IntValue (Jobs.Count);
    66       IntValue nrOfResources = NrOfResources;
     66      IntValue nrOfResources = new IntValue (Jobs[0].Tasks.Count);
    6767
    6868      for (int i = 0; i < nrOfResources.Value; i++) {
  • branches/Scheduling/HeuristicLab.Problems.Scheduling/3.3/Encodings/JobSequenceMatrix/Manipulators/JSMManipulator.cs

    r6121 r6177  
    3232  [Item("AlbaManipulator", "An operator which manipulates a VRP representation.")]
    3333  [StorableClass]
    34   public abstract class JSMManipulator : JSSPManipulator, IStochasticOperator, IJSMOperator {
    35     public ILookupParameter<IRandom> RandomParameter {
    36       get { return (LookupParameter<IRandom>)Parameters["Random"]; }
    37     }
    38 
     34  public abstract class JSMManipulator : JSSPManipulator, IJSMOperator {
    3935    [StorableConstructor]
    4036    protected JSMManipulator(bool deserializing) : base(deserializing) { }
     
    4238    public JSMManipulator()
    4339      : base() {
    44       Parameters.Add(new LookupParameter<IRandom>("Random", "The pseudo random number generator which should be used for stochastic manipulation operators."));
    4540    }
    4641
     
    4944
    5045    public override IOperation Apply() {
    51       JSSPEncoding solution = SchedulingSolutionParameter.ActualValue;
     46      IJSSPEncoding solution = SchedulingSolutionParameter.ActualValue;
    5247
    5348      SchedulingSolutionParameter.ActualValue = Manipulate(RandomParameter.ActualValue, solution as JSMEncoding);
Note: See TracChangeset for help on using the changeset viewer.