Free cookie consent management tool by TermsFeed Policy Generator

source: branches/2864_PermutationProblems/HeuristicLab.Problems.PFSP.Views/3.3/JobShopSchedulingProblemView.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.8 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 System;
23using System.Windows.Forms;
24using HeuristicLab.Collections;
25using HeuristicLab.Encodings.ScheduleEncoding;
26using HeuristicLab.MainForm;
27using HeuristicLab.Optimization.Views;
28using HeuristicLab.Data;
29using System.Linq;
30
31namespace HeuristicLab.Problems.PFSP.Views
32{
33    [View("Permutation Flowshop Scheduling Problem View")]
34    [Content(typeof(PermutationFlowshopSchedulingProblem), true)]
35    public partial class JobShopSchedulingProblemView : ProblemView
36    {
37
38        public new PermutationFlowshopSchedulingProblem Content
39        {
40            get { return (PermutationFlowshopSchedulingProblem)base.Content; }
41            set { base.Content = value; }
42        }
43
44        public JobShopSchedulingProblemView()
45        {
46            InitializeComponent();
47            Controls.Remove(parameterCollectionView);
48            parameterCollectionView.Dock = DockStyle.Fill;
49            problemTabPage.Controls.Add(parameterCollectionView);
50        }
51
52        protected override void OnContentChanged()
53        {
54            base.OnContentChanged();
55            FillGanttChart();
56        }
57
58        protected override void DeregisterContentEvents()
59        {
60            Content.BestKnownSolutionChanged -= Content_PermutationChanged;
61            base.DeregisterContentEvents();
62        }
63        protected override void RegisterContentEvents()
64        {
65            base.RegisterContentEvents();
66            Content.BestKnownSolutionChanged += new EventHandler(Content_PermutationChanged);
67        }
68
69        private void Content_PermutationChanged(object sender, EventArgs e)
70        {
71            if (InvokeRequired)
72            {
73                Invoke(new EventHandler(Content_PermutationChanged), sender, e);
74            }
75            else
76            {
77                FillGanttChart();
78            }
79        }
80
81        private void FillGanttChart()
82        {
83            ganttChart.Reset();
84            if (Content != null)
85            {
86                var matrix = Content.JobMatrix;
87                var perm = Content.BestKnownSolution;
88                if (matrix == null) { return; }
89
90                if (perm == null)
91                {
92                    perm = new Encodings.PermutationEncoding.Permutation(Encodings.PermutationEncoding.PermutationTypes.Absolute, Enumerable.Range(0, matrix.Columns).ToArray());
93                }
94
95                int[] permutation = perm.ToArray();
96
97                if (!permutation.Contains(0)) { permutation = permutation.Select(v => v - 1).ToArray(); }
98                DoubleMatrix calculatedTime = new DoubleMatrix(matrix.Rows, matrix.Columns);
99
100                for (var machineIdx = 0; machineIdx < matrix.Rows; machineIdx++)
101                {
102                    for (var jobIdx = 0; jobIdx < matrix.Columns; jobIdx++)
103                    {
104                        double runtimeCur = matrix[machineIdx, permutation[jobIdx]];
105                        double runtimePrev = 0;
106
107                        if (jobIdx == 0 && machineIdx == 0) { }
108                        else if (machineIdx == 0) { runtimePrev = calculatedTime[machineIdx, jobIdx - 1]; }
109                        else if (jobIdx == 0) { runtimePrev = calculatedTime[machineIdx - 1, jobIdx]; }
110                        else
111                        {
112                            double runtimePrevMachine = calculatedTime[machineIdx - 1, jobIdx];
113                            double runtimePrevJobOnThisMachine = calculatedTime[machineIdx, jobIdx - 1];
114                            runtimePrev = runtimePrevMachine > runtimePrevJobOnThisMachine ? runtimePrevMachine : runtimePrevJobOnThisMachine;
115                        }
116
117                        calculatedTime[machineIdx, jobIdx] = runtimeCur + runtimePrev;
118                        ganttChart.AddData("Machine " + machineIdx, permutation[jobIdx], jobIdx, runtimePrev, calculatedTime[machineIdx, jobIdx], "");
119                    }
120                }
121            }
122        }
123    }
124}
Note: See TracBrowser for help on using the repository browser.