Free cookie consent management tool by TermsFeed Policy Generator

source: branches/2864_PermutationProblems/HeuristicLab.Problems.PermutationProblems.Views/3.3/PermutationFlowshopSchedulingProblemView.cs @ 16690

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

#2864: Double-checked the namespaces and ordering of imports

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