Free cookie consent management tool by TermsFeed Policy Generator

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

Last change on this file since 6177 was 6177, checked in by jhelm, 13 years ago

#1329: Implemented PriorityRulesVector based encoding and added new operators to the JSMEncoding. Added Gantt-Charts for visualization of schedules and problems.

File size: 3.7 KB
Line 
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;
30using System.Drawing;
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;
50        ganttChart.Reset();
51      } else {
52        parameterCollectionView.Content = ((IParameterizedNamedItem)Content).Parameters;
53        FillGanttChart(Content);
54      }
55    }
56
57    private void FillGanttChart(JobShopSchedulingProblem content) {
58      //Add Jobs as Categories
59      int jobCount = 0;
60      Random random = new Random();
61      foreach (JSSPJob j in content.Jobs) {
62        foreach (JSSPTask t in content.Jobs[jobCount].Tasks) {
63          string categoryName = "ScheduleTasks";
64          categoryName = "Job" + t.Job.Index;
65          ganttChart.AddCategory(categoryName, Color.FromArgb(random.Next(255), random.Next(255), random.Next(255)));
66          ganttChart.AddData(categoryName,
67            categoryName,
68            t.StartTime.Value,
69            t.EndTime.Value,
70            "Job" + t.Job.Index + " - " + "Task#" + t.TaskNr.Value.ToString(),
71            false);
72        }
73        jobCount++;
74      }
75    }
76
77    protected override void SetEnabledStateOfControls() {
78      base.SetEnabledStateOfControls();
79      parameterCollectionView.Enabled = Content != null;
80      importButton.Enabled = Content != null && !ReadOnly;
81    }
82
83    private void importButton_Click(object sender, EventArgs e) {
84      if (spImportDialog == null) spImportDialog = new SchedulingProblemImportDialog();
85
86      if (spImportDialog.ShowDialog(this) == DialogResult.OK) {
87        try {
88          switch (spImportDialog.Format) {
89            case SPFormat.ORLib:
90              Content.ImportFromORLibrary(spImportDialog.SPFileName);
91              break;
92          }
93
94          /* TODO: Implement solution-import in problem-class
95          if (!string.IsNullOrEmpty(spImportDialog.OptimalScheduleFileName))
96            Content.ImportSolution(spImportDialog.OptimalScheduleFileName);
97           * */
98          OnContentChanged();
99        }
100        catch (Exception ex) {
101          ErrorHandling.ShowErrorDialog(this, ex);
102        }
103      }
104    }
105  }
106}
Note: See TracBrowser for help on using the repository browser.