Free cookie consent management tool by TermsFeed Policy Generator

Ignore:
Timestamp:
01/22/18 17:15:29 (6 years ago)
Author:
fholzing
Message:

#2864: Adapted PFSP and LOP to the new BasicProblem

File:
1 edited

Legend:

Unmodified
Added
Removed
  • branches/2864_PermutationProblems/HeuristicLab.Problems.PFSP.Views/3.3/JobShopSchedulingProblemView.cs

    r15541 r15639  
    2929using System.Linq;
    3030
    31 namespace HeuristicLab.Problems.PFSP.Views
    32 {
    33     [View("Permutation Flowshop Scheduling Problem View")]
    34     [Content(typeof(PermutationFlowshopSchedulingProblem), true)]
    35     public partial class JobShopSchedulingProblemView : ProblemView
     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
    3637    {
     38      get { return (PermutationFlowshopSchedulingProblem)base.Content; }
     39      set { base.Content = value; }
     40    }
    3741
    38         public new PermutationFlowshopSchedulingProblem Content
    39         {
    40             get { return (PermutationFlowshopSchedulingProblem)base.Content; }
    41             set { base.Content = value; }
     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());
    4280        }
    4381
    44         public JobShopSchedulingProblemView()
    45         {
    46             InitializeComponent();
    47             Controls.Remove(parameterCollectionView);
    48             parameterCollectionView.Dock = DockStyle.Fill;
    49             problemTabPage.Controls.Add(parameterCollectionView);
     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          }
    50101        }
    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         }
     102      }
    123103    }
     104  }
    124105}
Note: See TracChangeset for help on using the changeset viewer.