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

Last change on this file since 16172 was 16172, checked in by ddorfmei, 9 months ago

#2931:

  • created LinearProgrammingAlgorithm
    • created definitions for all LP/MIP solvers supported by OR-Tools
  • created LinearProgrammingProblem
    • created classes required for scripting: LinearProgrammingProblemDefinition, LinearProgrammingProblemDefinitionScript, CompiledLinearProgrammingProblemDefinition
    • created views: LinearProgrammingProblemView, LinearProgrammingProblemDefinitionScriptView
  • updated OR-Tools version in ExtLibs to 6.9
File size: 4.4 KB
Line 
1#region License Information
2/* HeuristicLab
3 * Copyright (C) 2002-2018 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.Drawing;
23using Google.OrTools.LinearSolver;
24using HeuristicLab.Common;
25using HeuristicLab.Common.Resources;
26using HeuristicLab.Core;
27using HeuristicLab.Optimization;
28using HeuristicLab.Parameters;
29using HeuristicLab.Persistence.Default.CompositeSerializers.Storable;
30
31namespace HeuristicLab.MathematicalOptimization.LinearProgramming.Problems {
32  [Item("Linear Programming Programmable Problem (single-objective)", "Represents a single-objective problem that can be programmed with a script.")]
33  [Creatable(CreatableAttribute.Categories.Problems, Priority = 100)]
34  [StorableClass]
35  public class LinearProgrammingProblem : Problem, IProgrammableItem {
36
37    public new static Image StaticItemImage => VSImageLibrary.Script;
38
39    private FixedValueParameter<LinearProgrammingProblemDefinitionScript> LinearProgrammingProblemScriptParameter => (FixedValueParameter<LinearProgrammingProblemDefinitionScript>)Parameters["ProblemScript"];
40
41    public LinearProgrammingProblemDefinitionScript ProblemScript => LinearProgrammingProblemScriptParameter.Value;
42
43    public ILinearProgrammingProblemDefinition ProblemDefinition => LinearProgrammingProblemScriptParameter.Value;
44
45    private LinearProgrammingProblem(LinearProgrammingProblem original, Cloner cloner)
46      : base(original, cloner) {
47      RegisterEvents();
48    }
49    public override IDeepCloneable Clone(Cloner cloner) { return new LinearProgrammingProblem(this, cloner); }
50
51    [StorableConstructor]
52    private LinearProgrammingProblem(bool deserializing) : base(deserializing) { }
53    public LinearProgrammingProblem() {
54      Parameters.Add(new FixedValueParameter<LinearProgrammingProblemDefinitionScript>("ProblemScript", "Defines the problem.", new LinearProgrammingProblemDefinitionScript { Name = Name }) { GetsCollected = false });
55      //Operators.Add(new BestScopeSolutionAnalyzer());
56      RegisterEvents();
57    }
58
59    [StorableHook(HookType.AfterDeserialization)]
60    private void AfterDeserialization() {
61      RegisterEvents();
62    }
63
64    private void RegisterEvents() {
65      ProblemScript.ProblemDefinitionChanged += (o, e) => OnProblemDefinitionChanged();
66      ProblemScript.NameChanged += (o, e) => OnProblemScriptNameChanged();
67    }
68
69    private void OnProblemDefinitionChanged() {
70      //Parameters.Remove("Maximization");
71      //Parameters.Add(new FixedValueParameter<BoolValue>("Maximization", "Set to false if the problem should be minimized.", (BoolValue)new BoolValue(Maximization).AsReadOnly()) { Hidden = true });
72
73      //Encoding = ProblemDefinition.Encoding;
74      OnOperatorsChanged();
75      OnReset();
76    }
77    protected override void OnNameChanged() {
78      base.OnNameChanged();
79      ProblemScript.Name = Name;
80    }
81    private void OnProblemScriptNameChanged() {
82      Name = ProblemScript.Name;
83    }
84
85    public void BuildModel(Solver solver) => ProblemDefinition.BuildModel(solver);
86
87    //public override bool Maximization {
88    //  get { return Parameters.ContainsKey("ProblemScript") ? ProblemDefinition.Maximization : false; }
89    //}
90
91    //public override double Evaluate(Individual individual, IRandom random) {
92    //  return ProblemDefinition.Evaluate(individual, random);
93    //}
94
95    //public override void Analyze(Individual[] individuals, double[] qualities, ResultCollection results, IRandom random) {
96    //  ProblemDefinition.Analyze(individuals, qualities, results, random);
97    //}
98
99    //public override IEnumerable<Individual> GetNeighbors(Individual individual, IRandom random) {
100    //  return ProblemDefinition.GetNeighbors(individual, random);
101    //}
102  }
103}
Note: See TracBrowser for help on using the repository browser.