Free cookie consent management tool by TermsFeed Policy Generator

source: branches/2931_OR-Tools_LP_MIP/HeuristicLab.MathematicalOptimization/3.3/LinearProgramming/Problems/LinearProgrammingProblem.cs @ 16233

Last change on this file since 16233 was 16233, checked in by ddorfmei, 5 years ago

#2931:

  • added all available parameters OR-Tools's linear_solver to LinearProgrammingAlgorithm
    • added necessary parameter enums
  • moved solving logic to Solver
    • created IncrementalSolver, ExternalSolver, ExternalIncrementalSolver
    • added logic for solvers that can be stopped and resumed
  • added SupportsStop property to BasicAlgorithm
  • added quality per time chart for incremental solvers
File size: 3.4 KB
Line 
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
24using System.Drawing;
25using Google.OrTools.LinearSolver;
26using HeuristicLab.Common;
27using HeuristicLab.Common.Resources;
28using HeuristicLab.Core;
29using HeuristicLab.Optimization;
30using HeuristicLab.Parameters;
31using HeuristicLab.Persistence.Default.CompositeSerializers.Storable;
32
33namespace 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}
Note: See TracBrowser for help on using the repository browser.