Free cookie consent management tool by TermsFeed Policy Generator

source: branches/Scheduling/HeuristicLab.Problems.Scheduling.Views/3.3/JobShopSchedulingProblemView.cs @ 6347

Last change on this file since 6347 was 6294, checked in by jhelm, 14 years ago

#1329: Did some heavy refactoring after "code-review meeting". Added Encodings.SchedulingEncoding plugin to store encodings used in scheduling problems.

File size: 3.7 KB
RevLine 
[6121]1#region License Information
2/* HeuristicLab
3 * Copyright (C) 2002-2011 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.Core;
25using HeuristicLab.Core.Views;
26using HeuristicLab.Data;
27using HeuristicLab.MainForm;
28using HeuristicLab.Parameters;
29using HeuristicLab.PluginInfrastructure;
[6177]30using System.Drawing;
[6121]31
32namespace HeuristicLab.Problems.Scheduling.Views {
33  [View("JobShop Scheduling Problem View")]
34  [Content(typeof(JobShopSchedulingProblem), true)]
35  public partial class JobShopSchedulingProblemView : NamedItemView {
36    public JobShopSchedulingProblemView() {
37      InitializeComponent();
38    }
39    private SchedulingProblemImportDialog spImportDialog;
40
41    public new JobShopSchedulingProblem Content {
42      get { return (JobShopSchedulingProblem)base.Content; }
43      set { base.Content = value; }
44    }
45
46    protected override void OnContentChanged() {
47      base.OnContentChanged();
48      if (Content == null) {
49        parameterCollectionView.Content = null;
[6177]50        ganttChart.Reset();
[6121]51      } else {
52        parameterCollectionView.Content = ((IParameterizedNamedItem)Content).Parameters;
[6177]53        FillGanttChart(Content);
[6121]54      }
55    }
56
[6177]57    private void FillGanttChart(JobShopSchedulingProblem content) {
58      //Add Jobs as Categories
[6260]59      ganttChart.Reset();
[6177]60      int jobCount = 0;
[6260]61      Random random = new Random(1);
[6294]62      foreach (Job j in content.JobData) {
63        double lastEndTime = 0;
64        foreach (Task t in content.JobData[jobCount].Tasks) {
[6260]65          int categoryNr = t.JobNr.Value;
66          string categoryName = "Job" + categoryNr;
67          ganttChart.AddJobColor(categoryNr);
[6177]68          ganttChart.AddData(categoryName,
[6260]69            categoryNr,
[6294]70            lastEndTime + 1,
71            lastEndTime + t.Duration.Value,
[6260]72            "Job" + t.JobNr + " - " + "Task#" + t.TaskNr.Value.ToString());
[6294]73          lastEndTime += t.Duration.Value;
[6177]74        }
75        jobCount++;
76      }
77    }
78
[6121]79    protected override void SetEnabledStateOfControls() {
80      base.SetEnabledStateOfControls();
81      parameterCollectionView.Enabled = Content != null;
82      importButton.Enabled = Content != null && !ReadOnly;
83    }
84
85    private void importButton_Click(object sender, EventArgs e) {
86      if (spImportDialog == null) spImportDialog = new SchedulingProblemImportDialog();
87
88      if (spImportDialog.ShowDialog(this) == DialogResult.OK) {
89        try {
90          switch (spImportDialog.Format) {
91            case SPFormat.ORLib:
92              Content.ImportFromORLibrary(spImportDialog.SPFileName);
93              break;
94          }
95
[6260]96
[6121]97          if (!string.IsNullOrEmpty(spImportDialog.OptimalScheduleFileName))
[6260]98            Content.ImportJSMSolution(spImportDialog.OptimalScheduleFileName);
[6177]99          OnContentChanged();
[6121]100        }
101        catch (Exception ex) {
102          ErrorHandling.ShowErrorDialog(this, ex);
103        }
104      }
105    }
106  }
107}
Note: See TracBrowser for help on using the repository browser.