Ejemplo n.º 1
0
        public static void Apply(IRandom random, JSMEncoding individual)
        {
            int nrOfJobs     = individual.JobSequenceMatrix[0].Length;
            int jobIndex     = random.Next(nrOfJobs);
            int signedFactor = random.Next(2);

            for (int permutationIndex = 0; permutationIndex < individual.JobSequenceMatrix.Count; permutationIndex++)
            {
                int         i = 0;
                Permutation currentPermutation = individual.JobSequenceMatrix[permutationIndex];
                while (i < currentPermutation.Length && currentPermutation[i] != jobIndex)
                {
                    i++;
                }
                int shift    = (signedFactor == 0) ? random.Next(nrOfJobs / 2) * -1 : random.Next(nrOfJobs / 2);
                int newIndex = shift + i;
                if (newIndex < 0)
                {
                    newIndex = 0;
                }
                if (newIndex >= nrOfJobs)
                {
                    newIndex = nrOfJobs - 1;
                }
                List <int> aux  = currentPermutation.ToList <int>();
                int        swap = currentPermutation[i];
                aux.RemoveAt(i);
                aux.Insert(newIndex, swap);
                individual.JobSequenceMatrix[permutationIndex] = new Permutation(PermutationTypes.Absolute, aux.ToArray());
            }
        }
Ejemplo n.º 2
0
 public static JSMEncoding Apply(int jobs, int resources, IRandom random) {
   var solution = new JSMEncoding();
   for (int i = 0; i < resources; i++) {
     solution.JobSequenceMatrix.Add(new Permutation(PermutationTypes.Absolute, jobs, random));
   }
   return solution;
 }
Ejemplo n.º 3
0
    public static JSMEncoding Apply(IRandom random, JSMEncoding p1, JSMEncoding p2) {
      var result = new JSMEncoding();

      int nrOfResources = p1.JobSequenceMatrix.Count;
      int nrOfJobs = p1.JobSequenceMatrix[0].Length;

      //Determine randomly which jobindexes persist
      var persist = new BoolArray(nrOfJobs);
      for (int i = 0; i < persist.Length; i++) {
        persist[i] = random.Next(2) == 1;
      }

      bool dominantParent = random.Next(2) == 1;
      JSMEncoding parent1 = dominantParent ? p1 : p2;
      JSMEncoding parent2 = dominantParent ? p2 : p1;

      //Fill childmatrix with values
      for (int resIndex = 0; resIndex < nrOfResources; resIndex++) {
        result.JobSequenceMatrix.Add(new Permutation(PermutationTypes.Absolute, nrOfJobs));
        int parent2index = 0;
        for (int jobIndex = 0; jobIndex < nrOfJobs; jobIndex++) {
          if (persist[parent1.JobSequenceMatrix[resIndex][jobIndex]])
            result.JobSequenceMatrix[resIndex][jobIndex] = parent1.JobSequenceMatrix[resIndex][jobIndex];
          else {
            while (persist[parent2.JobSequenceMatrix[resIndex][parent2index]])
              parent2index++;
            result.JobSequenceMatrix[resIndex][jobIndex] = parent2.JobSequenceMatrix[resIndex][parent2index];
            parent2index++;
          }
        }
      }

      return result;
    }
Ejemplo n.º 4
0
 public static JSMEncoding CreateTestJSM2() {
   JSMEncoding result = new JSMEncoding();
   ItemList<Permutation> jsm = new ItemList<Permutation>();
   for (int i = 0; i < 6; i++)
     jsm.Add(new Permutation(PermutationTypes.Absolute, new int[] { 5, 4, 3, 2, 1, 0 }));
   result.JobSequenceMatrix = jsm;
   return result;
 }
Ejemplo n.º 5
0
 public static void Apply(IRandom random, JSMEncoding individual) {
   int resourceIndex = random.Next(individual.JobSequenceMatrix.Count);
   Permutation p = individual.JobSequenceMatrix[resourceIndex];
   int seqIndex1 = random.Next(p.Length);
   int seqIndex2 = random.Next(p.Length);
   int aux = p[seqIndex1];
   p[seqIndex1] = p[seqIndex2];
   p[seqIndex2] = aux;
 }
Ejemplo n.º 6
0
 public static void Apply(IRandom random, JSMEncoding individual) {
   int resourceIndex = random.Next(individual.JobSequenceMatrix.Count);
   Permutation p = individual.JobSequenceMatrix[resourceIndex];
   int seqIndex1 = random.Next(p.Length);
   int seqIndex2 = random.Next(p.Length);
   int aux = p[seqIndex1];
   p[seqIndex1] = p[seqIndex2];
   p[seqIndex2] = aux;
 }
Ejemplo n.º 7
0
        public static JSMEncoding Apply(int jobs, int resources, IRandom random)
        {
            var solution = new JSMEncoding();

            for (int i = 0; i < resources; i++)
            {
                solution.JobSequenceMatrix.Add(new Permutation(PermutationTypes.Absolute, jobs, random));
            }
            return(solution);
        }
Ejemplo n.º 8
0
    public static JSMEncoding Apply(IRandom random, JSMEncoding parent1, JSMEncoding parent2) {
      var result = new JSMEncoding();

      for (int i = 0; i < parent1.JobSequenceMatrix.Count; i++) {
        result.JobSequenceMatrix.Add(
          HeuristicLab.Encodings.PermutationEncoding.OrderCrossover.Apply(random,
          parent1.JobSequenceMatrix[i], parent2.JobSequenceMatrix[i]));
      }

      return result;
    }
Ejemplo n.º 9
0
 public static JSMEncoding Apply(IRandom random, JSMEncoding parent1, JSMEncoding parent2) {
   var result = new JSMEncoding();
   int subSequenceLength = random.Next(parent1.JobSequenceMatrix[0].Length);
   for (int i = 0; i < parent1.JobSequenceMatrix.Count; i++) {
     var p1 = (Permutation)parent1.JobSequenceMatrix[i].Clone();
     var p2 = (Permutation)parent2.JobSequenceMatrix[i].Clone();
     FindAndExchangeSubsequences(p1, p2, subSequenceLength);
     result.JobSequenceMatrix.Add(p1);
   }
   return result;
 }
Ejemplo n.º 10
0
        public static JSMEncoding Apply(IRandom random, JSMEncoding parent1, JSMEncoding parent2)
        {
            var result = new JSMEncoding();

            for (int i = 0; i < parent1.JobSequenceMatrix.Count; i++)
            {
                result.JobSequenceMatrix.Add(
                    HeuristicLab.Encodings.PermutationEncoding.OrderCrossover.Apply(random,
                                                                                    parent1.JobSequenceMatrix[i], parent2.JobSequenceMatrix[i]));
            }

            return(result);
        }
    public void ApplyTest() {
      IRandom random = new TestRandom(new int[] { 2, 1, 1, 2, 1, 2, 1, 2, 1, 2, 1, 2 }, null);
      JSMEncoding individual = TestUtils.CreateTestJSM1();
      JSMShiftChangeManipulator.Apply(random, individual);
      JSMEncoding expected = new JSMEncoding();
      ItemList<Permutation> jsm = new ItemList<Permutation>();
      for (int i = 0; i < 3; i++) {
        jsm.Add(new Permutation(PermutationTypes.Absolute, new int[] { 0, 1, 3, 2, 4, 5 }));
        jsm.Add(new Permutation(PermutationTypes.Absolute, new int[] { 0, 1, 3, 4, 2, 5 }));
      }
      expected.JobSequenceMatrix = jsm;

      Assert.IsTrue(TestUtils.JSMEncodingEquals(expected, individual));
    }
Ejemplo n.º 12
0
        public static JSMEncoding Apply(IRandom random, JSMEncoding parent1, JSMEncoding parent2)
        {
            var result            = new JSMEncoding();
            int subSequenceLength = random.Next(parent1.JobSequenceMatrix[0].Length);

            for (int i = 0; i < parent1.JobSequenceMatrix.Count; i++)
            {
                var p1 = (Permutation)parent1.JobSequenceMatrix[i].Clone();
                var p2 = (Permutation)parent2.JobSequenceMatrix[i].Clone();
                FindAndExchangeSubsequences(p1, p2, subSequenceLength);
                result.JobSequenceMatrix.Add(p1);
            }
            return(result);
        }
Ejemplo n.º 13
0
    public void ApplyTest() {
      IRandom random = new TestRandom(new int[] { 3 }, null);
      JSMEncoding p1 = TestUtils.CreateTestJSM1();
      JSMEncoding p2 = TestUtils.CreateTestJSM2();
      JSMEncoding expected = new JSMEncoding();
      ItemList<Permutation> jsm = new ItemList<Permutation>();
      for (int i = 0; i < 6; i++) {
        jsm.Add(new Permutation(PermutationTypes.Absolute, new int[] { 2, 1, 0, 3, 4, 5 }));
      }
      expected.JobSequenceMatrix = jsm;

      JSMEncoding actual;
      actual = JSMSXXCrossover.Apply(random, p1, p2);

      Assert.IsTrue(TestUtils.JSMEncodingEquals(expected, actual));
    }
Ejemplo n.º 14
0
        public static JSMEncoding Apply(IRandom random, JSMEncoding p1, JSMEncoding p2)
        {
            var result = new JSMEncoding();

            int nrOfResources = p1.JobSequenceMatrix.Count;
            int nrOfJobs      = p1.JobSequenceMatrix[0].Length;

            //Determine randomly which jobindexes persist
            var persist = new BoolArray(nrOfJobs);

            for (int i = 0; i < persist.Length; i++)
            {
                persist[i] = random.Next(2) == 1;
            }

            bool        dominantParent = random.Next(2) == 1;
            JSMEncoding parent1        = dominantParent ? p1 : p2;
            JSMEncoding parent2        = dominantParent ? p2 : p1;

            //Fill childmatrix with values
            for (int resIndex = 0; resIndex < nrOfResources; resIndex++)
            {
                result.JobSequenceMatrix.Add(new Permutation(PermutationTypes.Absolute, nrOfJobs));
                int parent2index = 0;
                for (int jobIndex = 0; jobIndex < nrOfJobs; jobIndex++)
                {
                    if (persist[parent1.JobSequenceMatrix[resIndex][jobIndex]])
                    {
                        result.JobSequenceMatrix[resIndex][jobIndex] = parent1.JobSequenceMatrix[resIndex][jobIndex];
                    }
                    else
                    {
                        while (persist[parent2.JobSequenceMatrix[resIndex][parent2index]])
                        {
                            parent2index++;
                        }
                        result.JobSequenceMatrix[resIndex][jobIndex] = parent2.JobSequenceMatrix[resIndex][parent2index];
                        parent2index++;
                    }
                }
            }

            return(result);
        }
Ejemplo n.º 15
0
 public static void Apply(IRandom random, JSMEncoding individual) {
   int nrOfJobs = individual.JobSequenceMatrix[0].Length;
   int jobIndex = random.Next(nrOfJobs);
   int signedFactor = random.Next(2);
   for (int permutationIndex = 0; permutationIndex < individual.JobSequenceMatrix.Count; permutationIndex++) {
     int i = 0;
     Permutation currentPermutation = individual.JobSequenceMatrix[permutationIndex];
     while (i < currentPermutation.Length && currentPermutation[i] != jobIndex)
       i++;
     int shift = (signedFactor == 0) ? random.Next(nrOfJobs / 2) * -1 : random.Next(nrOfJobs / 2);
     int newIndex = shift + i;
     if (newIndex < 0) newIndex = 0;
     if (newIndex >= nrOfJobs) newIndex = nrOfJobs - 1;
     List<int> aux = currentPermutation.ToList<int>();
     int swap = currentPermutation[i];
     aux.RemoveAt(i);
     aux.Insert(newIndex, swap);
     individual.JobSequenceMatrix[permutationIndex] = new Permutation(PermutationTypes.Absolute, aux.ToArray());
   }
 }
Ejemplo n.º 16
0
 public override JSMEncoding Cross(IRandom random, JSMEncoding parent1, JSMEncoding parent2)
 {
     return(Apply(random, parent1, parent2));
 }
Ejemplo n.º 17
0
    public Schedule CreateScheduleFromEncoding(JSMEncoding solution, ItemList<Job> jobData) {
      ItemList<Permutation> jobSequenceMatrix = solution.JobSequenceMatrix;

      var jobs = (ItemList<Job>)jobData.Clone();
      var resultingSchedule = new Schedule(jobs[0].Tasks.Count);

      //Reset scheduled tasks in result
      foreach (Job j in jobs) {
        foreach (Task t in j.Tasks) {
          t.IsScheduled = false;
        }
      }

      //GT-Algorithm
      //STEP 0 - Compute a list of "earliest operations"
      ItemList<Task> earliestTasksList = GTAlgorithmUtils.GetEarliestNotScheduledTasks(jobs);
      while (earliestTasksList.Count > 0) {
        //STEP 1 - Get earliest not scheduled operation with minimal earliest completing time
        Task minimal = GTAlgorithmUtils.GetTaskWithMinimalEC(earliestTasksList, resultingSchedule);
        int conflictedResourceNr = minimal.ResourceNr;
        Resource conflictedResource = resultingSchedule.Resources[conflictedResourceNr];

        //STEP 2 - Compute a conflict set of all operations that can be scheduled on the conflicted resource
        ItemList<Task> conflictSet = GTAlgorithmUtils.GetConflictSetForTask(minimal, earliestTasksList, jobs, resultingSchedule);

        //STEP 3 - Select a task from the conflict set
        int progressOnResource = conflictedResource.Tasks.Count;
        Task selectedTask = SelectTaskFromConflictSet(conflictedResourceNr, progressOnResource, conflictSet, jobSequenceMatrix);

        //STEP 4 - Add the selected task to the current schedule 
        selectedTask.IsScheduled = true;
        double startTime = GTAlgorithmUtils.ComputeEarliestStartTime(selectedTask, resultingSchedule);
        resultingSchedule.ScheduleTask(selectedTask.ResourceNr, startTime, selectedTask.Duration, selectedTask.JobNr);

        //STEP 5 - Back to STEP 1
        earliestTasksList = GTAlgorithmUtils.GetEarliestNotScheduledTasks(jobs);
      }

      return resultingSchedule;
    }
Ejemplo n.º 18
0
 public abstract JSMEncoding Cross(IRandom random, JSMEncoding parent1, JSMEncoding parent2);
Ejemplo n.º 19
0
 public override JSMEncoding Cross(IRandom random, JSMEncoding parent1, JSMEncoding parent2) {
   return Apply(random, parent1, parent2);
 }
Ejemplo n.º 20
0
 protected JSMEncoding(JSMEncoding original, Cloner cloner)
     : base(original, cloner)
 {
     this.JobSequenceMatrix = cloner.Clone(original.JobSequenceMatrix);
 }
Ejemplo n.º 21
0
 public abstract JSMEncoding Cross(IRandom random, JSMEncoding parent1, JSMEncoding parent2);
Ejemplo n.º 22
0
 public static bool JSMEncodingEquals(JSMEncoding expected, JSMEncoding actual) {
   if (expected.JobSequenceMatrix.Count != actual.JobSequenceMatrix.Count)
     return false;
   for (int i = 0; i < expected.JobSequenceMatrix.Count; i++) {
     if (!PermutationEquals(expected.JobSequenceMatrix[i], actual.JobSequenceMatrix[i]))
       return false;
   }
   return true;
 }
Ejemplo n.º 23
0
 protected JSMEncoding(JSMEncoding original, Cloner cloner)
   : base(original, cloner) {
   this.JobSequenceMatrix = cloner.Clone(original.JobSequenceMatrix);
 }