Free cookie consent management tool by TermsFeed Policy Generator

source: branches/2864_PermutationProblems/HeuristicLab.Problems.PFSP.Views/3.3/JobShopSchedulingProblemView.cs @ 15639

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

#2864: Adapted PFSP and LOP to the new BasicProblem

File size: 4.1 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  [View("Permutation Flowshop Scheduling Problem View")]
33  [Content(typeof(PermutationFlowshopSchedulingProblem), true)]
34  public partial class JobShopSchedulingProblemView : ProblemView {
35
36    public new PermutationFlowshopSchedulingProblem Content
37    {
38      get { return (PermutationFlowshopSchedulingProblem)base.Content; }
39      set { base.Content = value; }
40    }
41
42    public JobShopSchedulingProblemView() {
43      InitializeComponent();
44      Controls.Remove(parameterCollectionView);
45      parameterCollectionView.Dock = DockStyle.Fill;
46      problemTabPage.Controls.Add(parameterCollectionView);
47    }
48
49    protected override void OnContentChanged() {
50      base.OnContentChanged();
51      FillGanttChart();
52    }
53
54    protected override void DeregisterContentEvents() {
55      Content.BestKnownSolutionChanged -= Content_PermutationChanged;
56      base.DeregisterContentEvents();
57    }
58    protected override void RegisterContentEvents() {
59      base.RegisterContentEvents();
60      Content.BestKnownSolutionChanged += new EventHandler(Content_PermutationChanged);
61    }
62
63    private void Content_PermutationChanged(object sender, EventArgs e) {
64      if (InvokeRequired) {
65        Invoke(new EventHandler(Content_PermutationChanged), sender, e);
66      } else {
67        FillGanttChart();
68      }
69    }
70
71    private void FillGanttChart() {
72      ganttChart.Reset();
73      if (Content != null) {
74        var matrix = Content.JobMatrix;
75        var perm = Content.BestKnownSolution;
76        if (matrix == null) { return; }
77
78        if (perm == null) {
79          perm = new Encodings.PermutationEncoding.Permutation(Encodings.PermutationEncoding.PermutationTypes.Absolute, Enumerable.Range(0, matrix.Columns).ToArray());
80        }
81
82        int[] permutation = perm.ToArray();
83
84        if (!permutation.Contains(0)) { permutation = permutation.Select(v => v - 1).ToArray(); }
85        DoubleMatrix calculatedTime = new DoubleMatrix(matrix.Rows, matrix.Columns);
86
87        for (var machineIdx = 0; machineIdx < matrix.Rows; machineIdx++) {
88          for (var jobIdx = 0; jobIdx < matrix.Columns; jobIdx++) {
89            double runtimeCur = matrix[machineIdx, permutation[jobIdx]];
90            double runtimePrev = 0;
91
92            if (jobIdx == 0 && machineIdx == 0) { } else if (machineIdx == 0) { runtimePrev = calculatedTime[machineIdx, jobIdx - 1]; } else if (jobIdx == 0) { runtimePrev = calculatedTime[machineIdx - 1, jobIdx]; } else {
93              double runtimePrevMachine = calculatedTime[machineIdx - 1, jobIdx];
94              double runtimePrevJobOnThisMachine = calculatedTime[machineIdx, jobIdx - 1];
95              runtimePrev = runtimePrevMachine > runtimePrevJobOnThisMachine ? runtimePrevMachine : runtimePrevJobOnThisMachine;
96            }
97
98            calculatedTime[machineIdx, jobIdx] = runtimeCur + runtimePrev;
99            ganttChart.AddData("Machine " + machineIdx, permutation[jobIdx], jobIdx, runtimePrev, calculatedTime[machineIdx, jobIdx], "");
100          }
101        }
102      }
103    }
104  }
105}
Note: See TracBrowser for help on using the repository browser.