Free cookie consent management tool by TermsFeed Policy Generator

source: branches/2864_PermutationProblems/HeuristicLab.Problems.PFSP/3.3/Evaluators/CmaxMakeSpanEvaluator.cs @ 15541

Last change on this file since 15541 was 15541, checked in by fholzing, 6 years ago

#2864: CleanUp of old code, added LOP benchmark instances

File size: 4.2 KB
Line 
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
22using HeuristicLab.Common;
23using HeuristicLab.Core;
24using HeuristicLab.Data;
25using HeuristicLab.Encodings.PermutationEncoding;
26using HeuristicLab.Persistence.Default.CompositeSerializers.Storable;
27using System;
28using System.Collections.Generic;
29using System.Linq;
30using System.Text;
31using System.Threading.Tasks;
32
33namespace 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}
Note: See TracBrowser for help on using the repository browser.