#region License Information /* HeuristicLab * Copyright (C) 2002-2018 Heuristic and Evolutionary Algorithms Laboratory (HEAL) * * This file is part of HeuristicLab. * * HeuristicLab is free software: you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by * the Free Software Foundation, either version 3 of the License, or * (at your option) any later version. * * HeuristicLab is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU General Public License * along with HeuristicLab. If not, see . */ #endregion using System; using System.Linq; using System.Windows.Forms; using HeuristicLab.Data; using HeuristicLab.MainForm; using HeuristicLab.Optimization.Views; namespace HeuristicLab.Problems.PermutationProblems.Views { [View("Permutation Flowshop Scheduling Problem View")] [Content(typeof(PermutationFlowshopSchedulingProblem), true)] public partial class PermutationFlowshopSchedulingProblemView : ProblemView { public new PermutationFlowshopSchedulingProblem Content { get { return (PermutationFlowshopSchedulingProblem)base.Content; } set { base.Content = value; } } public PermutationFlowshopSchedulingProblemView() { InitializeComponent(); Controls.Remove(parameterCollectionView); parameterCollectionView.Dock = DockStyle.Fill; problemTabPage.Controls.Add(parameterCollectionView); } protected override void OnContentChanged() { base.OnContentChanged(); FillGanttChart(); } protected override void DeregisterContentEvents() { Content.BestKnownSolutionChanged -= Content_PermutationChanged; base.DeregisterContentEvents(); } protected override void RegisterContentEvents() { base.RegisterContentEvents(); Content.BestKnownSolutionChanged += new EventHandler(Content_PermutationChanged); } private void Content_PermutationChanged(object sender, EventArgs e) { if (InvokeRequired) { Invoke(new EventHandler(Content_PermutationChanged), sender, e); } else { FillGanttChart(); } } private void FillGanttChart() { ganttChart.Reset(); if (Content != null) { var matrix = Content.JobMatrix; var perm = Content.BestKnownSolution; if (matrix == null) { return; } if (perm == null) { perm = new Encodings.PermutationEncoding.Permutation(Encodings.PermutationEncoding.PermutationTypes.Absolute, Enumerable.Range(0, matrix.Columns).ToArray()); } int[] permutation = perm.ToArray(); if (!permutation.Contains(0)) { permutation = permutation.Select(v => v - 1).ToArray(); } DoubleMatrix calculatedTime = new DoubleMatrix(matrix.Rows, matrix.Columns); for (var machineIdx = 0; machineIdx < matrix.Rows; machineIdx++) { for (var jobIdx = 0; jobIdx < matrix.Columns; jobIdx++) { double runtimeCur = matrix[machineIdx, permutation[jobIdx]]; double runtimePrev = 0; if (jobIdx == 0 && machineIdx == 0) { } else if (machineIdx == 0) { runtimePrev = calculatedTime[machineIdx, jobIdx - 1]; } else if (jobIdx == 0) { runtimePrev = calculatedTime[machineIdx - 1, jobIdx]; } else { double runtimePrevMachine = calculatedTime[machineIdx - 1, jobIdx]; double runtimePrevJobOnThisMachine = calculatedTime[machineIdx, jobIdx - 1]; runtimePrev = runtimePrevMachine > runtimePrevJobOnThisMachine ? runtimePrevMachine : runtimePrevJobOnThisMachine; } calculatedTime[machineIdx, jobIdx] = runtimeCur + runtimePrev; ganttChart.AddData("Machine " + machineIdx, permutation[jobIdx], jobIdx, runtimePrev, calculatedTime[machineIdx, jobIdx], ""); } } } } } }