1 | #region License Information
|
---|
2 | /* HeuristicLab
|
---|
3 | * Copyright (C) 2002-2016 Heuristic and Evolutionary Algorithms Laboratory (HEAL)
|
---|
4 | *
|
---|
5 | * This file is part of HeuristicLab.
|
---|
6 | *
|
---|
7 | * HeuristicLab is free software: you can redistribute it and/or modify
|
---|
8 | * it under the terms of the GNU General Public License as published by
|
---|
9 | * the Free Software Foundation, either version 3 of the License, or
|
---|
10 | * (at your option) any later version.
|
---|
11 | *
|
---|
12 | * HeuristicLab is distributed in the hope that it will be useful,
|
---|
13 | * but WITHOUT ANY WARRANTY; without even the implied warranty of
|
---|
14 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
---|
15 | * GNU General Public License for more details.
|
---|
16 | *
|
---|
17 | * You should have received a copy of the GNU General Public License
|
---|
18 | * along with HeuristicLab. If not, see <http://www.gnu.org/licenses/>.
|
---|
19 | */
|
---|
20 | #endregion
|
---|
21 |
|
---|
22 | using HeuristicLab.Common;
|
---|
23 | using HeuristicLab.Core;
|
---|
24 | using HeuristicLab.Data;
|
---|
25 | using HeuristicLab.Encodings.PermutationEncoding;
|
---|
26 | using HeuristicLab.Persistence.Default.CompositeSerializers.Storable;
|
---|
27 | using System;
|
---|
28 | using System.Collections.Generic;
|
---|
29 | using System.Linq;
|
---|
30 | using System.Text;
|
---|
31 | using System.Threading.Tasks;
|
---|
32 |
|
---|
33 | namespace HeuristicLab.Problems.PFSP
|
---|
34 | { /// <summary>
|
---|
35 | /// An operator which evaluates PFSP solutions given in path representation using the rounded Euclidean distance metric.
|
---|
36 | /// </summary>
|
---|
37 | [Item("CmaxMakeSpanEvaluator", "An operator which evaluates PFSP solutions given in matrix representation using Cmax")]
|
---|
38 | [StorableClass]
|
---|
39 | public sealed class CmaxMakeSpanEvaluator : MakeSpanEvaluator
|
---|
40 | {
|
---|
41 | [StorableConstructor]
|
---|
42 | private CmaxMakeSpanEvaluator(bool deserializing) : base(deserializing) { }
|
---|
43 | private CmaxMakeSpanEvaluator(CmaxMakeSpanEvaluator original, Cloner cloner) : base(original, cloner) { }
|
---|
44 | public CmaxMakeSpanEvaluator() : base() { }
|
---|
45 |
|
---|
46 | public override IDeepCloneable Clone(Cloner cloner)
|
---|
47 | {
|
---|
48 | return new CmaxMakeSpanEvaluator(this, cloner);
|
---|
49 | }
|
---|
50 |
|
---|
51 | protected override double CalculateMakespan(DoubleMatrix m, Permutation p)
|
---|
52 | {
|
---|
53 | DoubleMatrix calculatedTime = new DoubleMatrix(m.Rows, m.Columns);
|
---|
54 | double runtimeCur;
|
---|
55 | double runtimePrev = 0;
|
---|
56 |
|
---|
57 | double runtimePrevMachine;
|
---|
58 | double runtimePrevJobOnThisMachine;
|
---|
59 |
|
---|
60 | int[] permutation = p.ToArray();
|
---|
61 |
|
---|
62 | for (var machineIdx = 0; machineIdx < m.Rows; machineIdx++)
|
---|
63 | {
|
---|
64 | for (var jobIdx = 0; jobIdx < m.Columns; jobIdx++)
|
---|
65 | {
|
---|
66 | runtimeCur = m[machineIdx, permutation[jobIdx]];
|
---|
67 | runtimePrev = 0;
|
---|
68 |
|
---|
69 | //Simply add to calculatedTimeMatrix
|
---|
70 | if (jobIdx == 0 && machineIdx == 0)
|
---|
71 | {
|
---|
72 | //Take default (runtimePrev = 0)
|
---|
73 | }
|
---|
74 | //Add the time + the previous time
|
---|
75 | else if (machineIdx == 0)
|
---|
76 | {
|
---|
77 | runtimePrev = calculatedTime[machineIdx, jobIdx - 1];
|
---|
78 | }
|
---|
79 | //Check the job-time from the previous machine and previos job and take the greater
|
---|
80 | else if (jobIdx == 0)
|
---|
81 | {
|
---|
82 | runtimePrev = calculatedTime[machineIdx - 1, jobIdx];
|
---|
83 | }
|
---|
84 | //X X X X X
|
---|
85 | //X O O O O
|
---|
86 | //X O O O O
|
---|
87 | //X O O O O
|
---|
88 | else
|
---|
89 | {
|
---|
90 | runtimePrevMachine = calculatedTime[machineIdx - 1, jobIdx];
|
---|
91 | runtimePrevJobOnThisMachine = calculatedTime[machineIdx, jobIdx - 1];
|
---|
92 | runtimePrev = runtimePrevMachine > runtimePrevJobOnThisMachine ? runtimePrevMachine : runtimePrevJobOnThisMachine;
|
---|
93 | }
|
---|
94 | calculatedTime[machineIdx, jobIdx] = runtimeCur + runtimePrev;
|
---|
95 | }
|
---|
96 | }
|
---|
97 | //return the makespan(the total runtime from start till the last job is finished)
|
---|
98 | return calculatedTime[calculatedTime.Rows - 1, calculatedTime.Columns - 1];
|
---|
99 | }
|
---|
100 | }
|
---|
101 | }
|
---|