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 System;
|
---|
23 | using System.Drawing;
|
---|
24 | using System.Linq;
|
---|
25 | using HeuristicLab.Common;
|
---|
26 | using HeuristicLab.Core;
|
---|
27 | using HeuristicLab.Data;
|
---|
28 | using HeuristicLab.Encodings.PermutationEncoding;
|
---|
29 | using HeuristicLab.Parameters;
|
---|
30 | using HeuristicLab.Persistence.Default.CompositeSerializers.Storable;
|
---|
31 | using HeuristicLab.PluginInfrastructure;
|
---|
32 | using HeuristicLab.Problems.Instances;
|
---|
33 | using HeuristicLab.Optimization;
|
---|
34 | using System.Collections.Generic;
|
---|
35 |
|
---|
36 | namespace HeuristicLab.Problems.PFSP
|
---|
37 | {
|
---|
38 | [Item("Permutation Flowshop Scheduling Problem (PFSP)", "Represents a Permutation Flowshop Scheduling Problem")]
|
---|
39 | [Creatable(CreatableAttribute.Categories.CombinatorialProblems, Priority = 999)]
|
---|
40 | [StorableClass]
|
---|
41 | public sealed class PermutationFlowshopSchedulingProblem : SingleObjectiveHeuristicOptimizationProblem<IPFSPEvaluator, IPermutationCreator>, IProblemInstanceConsumer<FSSPData>, IProblemInstanceExporter<FSSPData>, IStorableContent
|
---|
42 | {
|
---|
43 | #region Default Instance
|
---|
44 | private static readonly FSSPData DefaultInstance = new FSSPData()
|
---|
45 | {
|
---|
46 | Name = "Permutation Flowshop Scheduling Problem (PFSP)",
|
---|
47 | Description = "The default instance of the PFSP problem in HeuristicLab",
|
---|
48 | Jobs = 4,
|
---|
49 | Machines = 4,
|
---|
50 | //BestKnownQuality = 328,
|
---|
51 | ProcessingTimes = new double[,] {
|
---|
52 | {5 ,3, 6 ,6 },
|
---|
53 | {2 ,4, 8 ,4},
|
---|
54 | {4 ,2, 7 ,4},
|
---|
55 | {5 ,3, 8 ,6}
|
---|
56 | }
|
---|
57 | };
|
---|
58 | #endregion
|
---|
59 |
|
---|
60 | public string Filename { get; set; }
|
---|
61 |
|
---|
62 | #region Parameter Properties
|
---|
63 | public OptionalValueParameter<Permutation> BestKnownSolutionParameter
|
---|
64 | {
|
---|
65 | get { return (OptionalValueParameter<Permutation>)Parameters["BestKnownSolution"]; }
|
---|
66 | }
|
---|
67 |
|
---|
68 | public OptionalValueParameter<JobMatrix> JobMatrixParameter
|
---|
69 | {
|
---|
70 | get { return (OptionalValueParameter<JobMatrix>)Parameters["JobMatrix"]; }
|
---|
71 | }
|
---|
72 | #endregion
|
---|
73 |
|
---|
74 | #region Properties
|
---|
75 | public Permutation BestKnownSolution
|
---|
76 | {
|
---|
77 | get { return BestKnownSolutionParameter.Value; }
|
---|
78 | set
|
---|
79 | {
|
---|
80 | BestKnownSolutionParameter.Value = value;
|
---|
81 | if (BestKnownSolutionChanged != null) { OnBestKnownSolutionChanged(); }
|
---|
82 | }
|
---|
83 | }
|
---|
84 | public JobMatrix JobMatrix
|
---|
85 | {
|
---|
86 | get { return JobMatrixParameter.Value; }
|
---|
87 | set { JobMatrixParameter.Value = value; }
|
---|
88 | }
|
---|
89 | #endregion
|
---|
90 |
|
---|
91 | public event EventHandler BestKnownSolutionChanged;
|
---|
92 | private void OnBestKnownSolutionChanged()
|
---|
93 | {
|
---|
94 | var changed = BestKnownSolutionChanged;
|
---|
95 | if (changed != null)
|
---|
96 | changed(this, EventArgs.Empty);
|
---|
97 | }
|
---|
98 |
|
---|
99 | [StorableConstructor]
|
---|
100 | private PermutationFlowshopSchedulingProblem(bool deserializing) : base(deserializing) { }
|
---|
101 | private PermutationFlowshopSchedulingProblem(PermutationFlowshopSchedulingProblem original, Cloner cloner)
|
---|
102 | : base(original, cloner)
|
---|
103 | {
|
---|
104 | }
|
---|
105 | public PermutationFlowshopSchedulingProblem()
|
---|
106 | : base(new CmaxMakeSpanEvaluator(), new RandomPermutationCreator())
|
---|
107 | {
|
---|
108 | Parameters.Add(new OptionalValueParameter<Permutation>("BestKnownSolution", "The best known solution of this FSSP instance."));
|
---|
109 | Parameters.Add(new OptionalValueParameter<JobMatrix>("JobMatrix", "The matrix which contains the jobs,machines and duration."));
|
---|
110 |
|
---|
111 | Load(DefaultInstance);
|
---|
112 | EvaluatorParameter.GetsCollected = false;
|
---|
113 | EvaluatorParameter.Hidden = true;
|
---|
114 |
|
---|
115 | Maximization.Value = false;
|
---|
116 | MaximizationParameter.Hidden = true;
|
---|
117 |
|
---|
118 | SolutionCreator.PermutationParameter.ActualName = "PFSPOrder";
|
---|
119 | Evaluator.QualityParameter.ActualName = "Makespan";
|
---|
120 | ParameterizeSolutionCreator();
|
---|
121 | ParameterizeEvaluator();
|
---|
122 |
|
---|
123 | InitializeOperators();
|
---|
124 | }
|
---|
125 |
|
---|
126 | public override IDeepCloneable Clone(Cloner cloner)
|
---|
127 | {
|
---|
128 | return new PermutationFlowshopSchedulingProblem(this, cloner);
|
---|
129 | }
|
---|
130 |
|
---|
131 | [StorableHook(HookType.AfterDeserialization)]
|
---|
132 | private void AfterDeserialization() { }
|
---|
133 |
|
---|
134 | #region Problem Instance Handling
|
---|
135 | public void Load(FSSPData data)
|
---|
136 | {
|
---|
137 |
|
---|
138 | BestKnownQuality = data.BestKnownQuality.HasValue ? new DoubleValue(data.BestKnownQuality.Value) : null;
|
---|
139 | Name = data.Name;
|
---|
140 | Description = data.Description;
|
---|
141 | JobMatrix = new JobMatrix(data.ProcessingTimes);
|
---|
142 |
|
---|
143 | if (data.BestKnownSchedule != null)
|
---|
144 | {
|
---|
145 | int[] permut = data.BestKnownSchedule;
|
---|
146 | //Clean up if the first index = 1
|
---|
147 | if (!permut.Contains(0)) { permut = permut.Select(v => v - 1).ToArray(); }
|
---|
148 | double bestKnownQuality = MakeSpanEvaluator.Apply(
|
---|
149 | new CmaxMakeSpanEvaluator(),
|
---|
150 | new DoubleMatrix(data.ProcessingTimes),
|
---|
151 | new Permutation(PermutationTypes.Absolute, permut)
|
---|
152 | );
|
---|
153 |
|
---|
154 | BestKnownSolution = new Permutation(PermutationTypes.Absolute, data.BestKnownSchedule);
|
---|
155 | BestKnownQuality = new DoubleValue(bestKnownQuality);
|
---|
156 | }
|
---|
157 |
|
---|
158 | ParameterizeSolutionCreator();
|
---|
159 | }
|
---|
160 | public FSSPData Export()
|
---|
161 | {
|
---|
162 | var result = new FSSPData
|
---|
163 | {
|
---|
164 | Name = Name,
|
---|
165 | Description = Description,
|
---|
166 | ProcessingTimes = new double[JobMatrix.Rows, JobMatrix.Columns]
|
---|
167 | };
|
---|
168 |
|
---|
169 | if (BestKnownQuality != null)
|
---|
170 | {
|
---|
171 | result.BestKnownQuality = BestKnownQuality.Value;
|
---|
172 | }
|
---|
173 |
|
---|
174 | if (JobMatrix != null)
|
---|
175 | {
|
---|
176 | result.Jobs = JobMatrix.Rows;
|
---|
177 | result.Machines = JobMatrix.Columns;
|
---|
178 | }
|
---|
179 |
|
---|
180 | for (int i = 0; i < JobMatrix.Rows; i++)
|
---|
181 | {
|
---|
182 | for (int j = 0; j < JobMatrix.Columns; j++)
|
---|
183 | {
|
---|
184 | result.ProcessingTimes[i, j] = JobMatrix[i, j];
|
---|
185 | }
|
---|
186 | }
|
---|
187 |
|
---|
188 | result.BestKnownSchedule = BestKnownSolution != null ? (BestKnownSolution as IntArray).ToArray() : null;
|
---|
189 |
|
---|
190 | return result;
|
---|
191 | }
|
---|
192 | #endregion
|
---|
193 |
|
---|
194 | #region Helpers
|
---|
195 | private void InitializeOperators()
|
---|
196 | {
|
---|
197 | Operators.AddRange(ApplicationManager.Manager.GetInstances<IPermutationOperator>());
|
---|
198 | ParameterizeOperators();
|
---|
199 | }
|
---|
200 | private void ParameterizeOperators()
|
---|
201 | {
|
---|
202 | foreach (IPermutationCrossover op in Operators.OfType<IPermutationCrossover>())
|
---|
203 | {
|
---|
204 | op.ParentsParameter.ActualName = SolutionCreator.PermutationParameter.ActualName;
|
---|
205 | op.ParentsParameter.Hidden = true;
|
---|
206 | op.ChildParameter.ActualName = SolutionCreator.PermutationParameter.ActualName;
|
---|
207 | op.ChildParameter.Hidden = true;
|
---|
208 | }
|
---|
209 | foreach (IPermutationManipulator op in Operators.OfType<IPermutationManipulator>())
|
---|
210 | {
|
---|
211 | op.PermutationParameter.ActualName = SolutionCreator.PermutationParameter.ActualName;
|
---|
212 | op.PermutationParameter.Hidden = true;
|
---|
213 | }
|
---|
214 | foreach (IPermutationMoveOperator op in Operators.OfType<IPermutationMoveOperator>())
|
---|
215 | {
|
---|
216 | op.PermutationParameter.ActualName = SolutionCreator.PermutationParameter.ActualName;
|
---|
217 | op.PermutationParameter.Hidden = true;
|
---|
218 | }
|
---|
219 | foreach (IPermutationMultiNeighborhoodShakingOperator op in Operators.OfType<IPermutationMultiNeighborhoodShakingOperator>())
|
---|
220 | {
|
---|
221 | op.PermutationParameter.ActualName = SolutionCreator.PermutationParameter.ActualName;
|
---|
222 | op.PermutationParameter.Hidden = true;
|
---|
223 | }
|
---|
224 | foreach (ISingleObjectiveImprovementOperator op in Operators.OfType<ISingleObjectiveImprovementOperator>())
|
---|
225 | {
|
---|
226 | op.SolutionParameter.ActualName = SolutionCreator.PermutationParameter.ActualName;
|
---|
227 | op.SolutionParameter.Hidden = true;
|
---|
228 | }
|
---|
229 | foreach (ISingleObjectivePathRelinker op in Operators.OfType<ISingleObjectivePathRelinker>())
|
---|
230 | {
|
---|
231 | op.ParentsParameter.ActualName = SolutionCreator.PermutationParameter.ActualName;
|
---|
232 | op.ParentsParameter.Hidden = true;
|
---|
233 | }
|
---|
234 | foreach (ISolutionSimilarityCalculator op in Operators.OfType<ISolutionSimilarityCalculator>())
|
---|
235 | {
|
---|
236 | op.SolutionVariableName = SolutionCreator.PermutationParameter.ActualName;
|
---|
237 | op.QualityVariableName = Evaluator.QualityParameter.ActualName;
|
---|
238 | }
|
---|
239 | }
|
---|
240 | private void ParameterizeSolutionCreator()
|
---|
241 | {
|
---|
242 | SolutionCreator.LengthParameter.Value = new IntValue(JobMatrix.Columns);
|
---|
243 |
|
---|
244 | SolutionCreator.LengthParameter.Hidden = SolutionCreator.LengthParameter.Value != null;
|
---|
245 | SolutionCreator.PermutationTypeParameter.Value = new PermutationType(PermutationTypes.RelativeUndirected);
|
---|
246 | SolutionCreator.PermutationTypeParameter.Hidden = true;
|
---|
247 | }
|
---|
248 | private void ParameterizeEvaluator()
|
---|
249 | {
|
---|
250 | if (Evaluator is CmaxMakeSpanEvaluator)
|
---|
251 | {
|
---|
252 | IMakespanEvaluator evaluator = (IMakespanEvaluator)Evaluator;
|
---|
253 | evaluator.PermutationParameter.ActualName = SolutionCreator.PermutationParameter.ActualName;
|
---|
254 | evaluator.PermutationParameter.Hidden = true;
|
---|
255 | }
|
---|
256 | }
|
---|
257 | #endregion
|
---|
258 | }
|
---|
259 | }
|
---|