コード例 #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());
            }
        }
コード例 #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;
 }
コード例 #3
0
ファイル: JSMJOXCrossover.cs プロジェクト: t-h-e/HeuristicLab
    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;
    }
コード例 #4
0
ファイル: TestUtils.cs プロジェクト: thunder176/HeuristicLab
 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;
 }
コード例 #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;
 }
コード例 #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;
 }
コード例 #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);
        }
コード例 #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;
    }
コード例 #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;
 }
コード例 #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);
        }
コード例 #11
0
    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));
    }
コード例 #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);
        }
コード例 #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));
    }
コード例 #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);
        }
コード例 #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());
   }
 }
コード例 #16
0
 public override JSMEncoding Cross(IRandom random, JSMEncoding parent1, JSMEncoding parent2)
 {
     return(Apply(random, parent1, parent2));
 }
コード例 #17
0
ファイル: JSMDecoder.cs プロジェクト: thunder176/HeuristicLab
    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;
    }
コード例 #18
0
ファイル: JSMCrossover.cs プロジェクト: t-h-e/HeuristicLab
 public abstract JSMEncoding Cross(IRandom random, JSMEncoding parent1, JSMEncoding parent2);
コード例 #19
0
 public override JSMEncoding Cross(IRandom random, JSMEncoding parent1, JSMEncoding parent2) {
   return Apply(random, parent1, parent2);
 }
コード例 #20
0
 protected JSMEncoding(JSMEncoding original, Cloner cloner)
     : base(original, cloner)
 {
     this.JobSequenceMatrix = cloner.Clone(original.JobSequenceMatrix);
 }
コード例 #21
0
 public abstract JSMEncoding Cross(IRandom random, JSMEncoding parent1, JSMEncoding parent2);
コード例 #22
0
ファイル: TestUtils.cs プロジェクト: thunder176/HeuristicLab
 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;
 }
コード例 #23
0
ファイル: JSMEncoding.cs プロジェクト: t-h-e/HeuristicLab
 protected JSMEncoding(JSMEncoding original, Cloner cloner)
   : base(original, cloner) {
   this.JobSequenceMatrix = cloner.Clone(original.JobSequenceMatrix);
 }