1 | #region License Information
|
---|
2 |
|
---|
3 | /* HeuristicLab
|
---|
4 | * Copyright (C) 2002-2018 Heuristic and Evolutionary Algorithms Laboratory (HEAL)
|
---|
5 | *
|
---|
6 | * This file is part of HeuristicLab.
|
---|
7 | *
|
---|
8 | * HeuristicLab is free software: you can redistribute it and/or modify
|
---|
9 | * it under the terms of the GNU General Public License as published by
|
---|
10 | * the Free Software Foundation, either version 3 of the License, or
|
---|
11 | * (at your option) any later version.
|
---|
12 | *
|
---|
13 | * HeuristicLab is distributed in the hope that it will be useful,
|
---|
14 | * but WITHOUT ANY WARRANTY; without even the implied warranty of
|
---|
15 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
---|
16 | * GNU General Public License for more details.
|
---|
17 | *
|
---|
18 | * You should have received a copy of the GNU General Public License
|
---|
19 | * along with HeuristicLab. If not, see <http://www.gnu.org/licenses/>.
|
---|
20 | */
|
---|
21 |
|
---|
22 | #endregion License Information
|
---|
23 |
|
---|
24 | using System.Drawing;
|
---|
25 | using Google.OrTools.LinearSolver;
|
---|
26 | using HeuristicLab.Common;
|
---|
27 | using HeuristicLab.Common.Resources;
|
---|
28 | using HeuristicLab.Core;
|
---|
29 | using HeuristicLab.Optimization;
|
---|
30 | using HeuristicLab.Parameters;
|
---|
31 | using HeuristicLab.Persistence.Default.CompositeSerializers.Storable;
|
---|
32 |
|
---|
33 | namespace HeuristicLab.MathematicalOptimization.LinearProgramming.Problems {
|
---|
34 |
|
---|
35 | [Item("Linear/Mixed Integer Programming Problem (LP/MIP)", "")]
|
---|
36 | [Creatable(CreatableAttribute.Categories.CombinatorialProblems)]
|
---|
37 | [StorableClass]
|
---|
38 | public class LinearProgrammingProblem : Problem, IProgrammableItem {
|
---|
39 |
|
---|
40 | public LinearProgrammingProblem() {
|
---|
41 | Parameters.Add(new FixedValueParameter<LinearProgrammingProblemDefinitionScript>("ProblemScript",
|
---|
42 | "Defines the problem.", new LinearProgrammingProblemDefinitionScript { Name = Name }) { GetsCollected = false });
|
---|
43 | RegisterEvents();
|
---|
44 | }
|
---|
45 |
|
---|
46 | private LinearProgrammingProblem(LinearProgrammingProblem original, Cloner cloner)
|
---|
47 | : base(original, cloner) {
|
---|
48 | RegisterEvents();
|
---|
49 | }
|
---|
50 |
|
---|
51 | [StorableConstructor]
|
---|
52 | private LinearProgrammingProblem(bool deserializing) : base(deserializing) { }
|
---|
53 |
|
---|
54 | public new static Image StaticItemImage => VSImageLibrary.Script;
|
---|
55 | public ILinearProgrammingProblemDefinition ProblemDefinition => LinearProgrammingProblemScriptParameter.Value;
|
---|
56 | public LinearProgrammingProblemDefinitionScript ProblemScript => LinearProgrammingProblemScriptParameter.Value;
|
---|
57 |
|
---|
58 | private FixedValueParameter<LinearProgrammingProblemDefinitionScript> LinearProgrammingProblemScriptParameter =>
|
---|
59 | (FixedValueParameter<LinearProgrammingProblemDefinitionScript>)Parameters["ProblemScript"];
|
---|
60 |
|
---|
61 | public void BuildModel(Solver solver) => ProblemDefinition.BuildModel(solver);
|
---|
62 |
|
---|
63 | public override IDeepCloneable Clone(Cloner cloner) {
|
---|
64 | return new LinearProgrammingProblem(this, cloner);
|
---|
65 | }
|
---|
66 |
|
---|
67 | protected override void OnNameChanged() {
|
---|
68 | base.OnNameChanged();
|
---|
69 | ProblemScript.Name = Name;
|
---|
70 | }
|
---|
71 |
|
---|
72 | [StorableHook(HookType.AfterDeserialization)]
|
---|
73 | private void AfterDeserialization() {
|
---|
74 | RegisterEvents();
|
---|
75 | }
|
---|
76 |
|
---|
77 | private void OnProblemDefinitionChanged() {
|
---|
78 | OnOperatorsChanged();
|
---|
79 | OnReset();
|
---|
80 | }
|
---|
81 |
|
---|
82 | private void OnProblemScriptNameChanged() {
|
---|
83 | Name = ProblemScript.Name;
|
---|
84 | }
|
---|
85 |
|
---|
86 | private void RegisterEvents() {
|
---|
87 | ProblemScript.ProblemDefinitionChanged += (o, e) => OnProblemDefinitionChanged();
|
---|
88 | ProblemScript.NameChanged += (o, e) => OnProblemScriptNameChanged();
|
---|
89 | }
|
---|
90 | }
|
---|
91 | } |
---|