Ignore:
Timestamp:
12/19/18 14:15:49 (5 months ago)
Author:
ddorfmei
Message:

#2931:

  • moved views to separate plugin HeuristicLab.MathematicalOptimization.Views
  • added button in LinearProgrammingProblemView to select the problem definition type
  • added views for problem definitions
  • added ExportFile parameter to LinearProgrammingAlgorithm
  • extended FileValue and FileValueView by the option to save a file
  • code cleanup
File:
1 moved

Legend:

Unmodified
Added
Removed
  • branches/2931_OR-Tools_LP_MIP/HeuristicLab.MathematicalOptimization/3.3/LinearProgramming/Problems/ProgrammableLinearProgrammingProblemDefinition.cs

    r16404 r16405  
    3131using HeuristicLab.Scripting;
    3232
    33 namespace HeuristicLab.MathematicalOptimization.LinearProgramming.Problems {
     33namespace HeuristicLab.MathematicalOptimization.LinearProgramming {
    3434
    35   [Item("Linear/Mixed Integer Programming Problem Definition Script", "Script that defines the model and evaluates the solution for a linear/mixed integer programming problem.")]
     35  [Item("Programmable Linear/Mixed Integer Programming Problem Definition",
     36    "Script that defines the model and evaluates the solution for a linear/mixed integer programming problem.")]
    3637  [StorableClass]
    37   public sealed class LinearProgrammingProblemDefinitionScript : Script, ILinearProgrammingProblemDefinition, IStorableContent {
    38     private bool SuppressEvents { get; set; }
     38  public sealed class ProgrammableLinearProgrammingProblemDefinition : Script, ILinearProgrammingProblemDefinition,
     39    IStorableContent {
     40    private readonly object compileLock = new object();
    3941
    40     [Storable]
    41     private readonly VariableStore variableStore;
     42    [Storable] private readonly VariableStore variableStore;
    4243
    43     public VariableStore VariableStore => variableStore;
     44    [Storable] private bool codeChanged;
    4445
    45     [Storable]
    46     private bool codeChanged;
     46    private volatile ILinearProgrammingProblemDefinition compiledProblemDefinition;
     47
     48    public ProgrammableLinearProgrammingProblemDefinition()
     49      : base(ScriptTemplates.CompiledLinearProgrammingProblemDefinition) {
     50      Name = "Programmable Linear/Mixed Integer Programming Problem Definition";
     51      variableStore = new VariableStore();
     52    }
    4753
    4854    [StorableConstructor]
    49     private LinearProgrammingProblemDefinitionScript(bool deserializing) : base(deserializing) { }
     55    private ProgrammableLinearProgrammingProblemDefinition(bool deserializing) : base(deserializing) {
     56    }
    5057
    51     private LinearProgrammingProblemDefinitionScript(LinearProgrammingProblemDefinitionScript original, Cloner cloner)
    52       : base(original, cloner) {
     58    private ProgrammableLinearProgrammingProblemDefinition(ProgrammableLinearProgrammingProblemDefinition original,
     59      Cloner cloner) : base(original, cloner) {
    5360      variableStore = cloner.Clone(original.variableStore);
    5461      codeChanged = original.codeChanged;
    5562    }
    5663
    57     public LinearProgrammingProblemDefinitionScript()
    58       : base(ScriptTemplates.CompiledLinearProgrammingProblemDefinition) {
    59       variableStore = new VariableStore();
    60     }
     64    public event EventHandler ProblemDefinitionChanged;
    6165
    62     private readonly object compileLock = new object();
    63     private volatile ILinearProgrammingProblemDefinition compiledProblemDefinition;
     66    public string Filename { get; set; }
     67    public dynamic Instance => compiledProblemDefinition;
     68    public VariableStore VariableStore => variableStore;
    6469
    6570    private ILinearProgrammingProblemDefinition CompiledProblemDefinition {
     
    7580          }
    7681        }
     82
    7783        return compiledProblemDefinition;
    7884      }
    7985    }
    8086
    81     public dynamic Instance => compiledProblemDefinition;
     87    private bool SuppressEvents { get; set; }
     88
     89    public void Analyze(Solver solver, ResultCollection results) => CompiledProblemDefinition.Analyze(solver, results);
     90
     91    public void BuildModel(Solver solver) => CompiledProblemDefinition.BuildModel(solver);
     92
     93    public override IDeepCloneable Clone(Cloner cloner) {
     94      return new ProgrammableLinearProgrammingProblemDefinition(this, cloner);
     95    }
    8296
    8397    public override Assembly Compile() => Compile(true);
     98
     99    protected override void OnCodeChanged() {
     100      base.OnCodeChanged();
     101      compiledProblemDefinition = null;
     102      codeChanged = true;
     103    }
    84104
    85105    private Assembly Compile(bool fireChanged) {
     
    87107      var types = assembly.GetTypes();
    88108      if (!types.Any(x => typeof(CompiledProblemDefinition).IsAssignableFrom(x)))
    89         throw new ProblemDefinitionScriptException("The compiled code doesn't contain a problem definition." +
    90                                                    Environment.NewLine +
     109        throw new ProblemDefinitionScriptException("The compiled code doesn't contain a problem definition." + Environment.NewLine +
    91110                                                   "The problem definition must be a subclass of CompiledProblemDefinition.");
    92111      if (types.Count(x => typeof(CompiledProblemDefinition).IsAssignableFrom(x)) > 1)
    93         throw new ProblemDefinitionScriptException("The compiled code contains multiple problem definitions." +
    94                                                    Environment.NewLine +
     112        throw new ProblemDefinitionScriptException("The compiled code contains multiple problem definitions." + Environment.NewLine +
    95113                                                   "Only one subclass of CompiledProblemDefinition is allowed.");
    96114
     
    128146    }
    129147
    130     protected override void OnCodeChanged() {
    131       base.OnCodeChanged();
    132       compiledProblemDefinition = null;
    133       codeChanged = true;
    134     }
    135 
    136     public event EventHandler ProblemDefinitionChanged;
    137 
    138148    private void OnProblemDefinitionChanged() => ProblemDefinitionChanged?.Invoke(this, EventArgs.Empty);
    139 
    140     public string Filename { get; set; }
    141 
    142     public override IDeepCloneable Clone(Cloner cloner) {
    143       return new LinearProgrammingProblemDefinitionScript(this, cloner);
    144     }
    145 
    146     public bool BuildModel(Solver solver) => CompiledProblemDefinition.BuildModel(solver);
    147 
    148     public void Analyze(Solver solver, ResultCollection results) => CompiledProblemDefinition.Analyze(solver, results);
    149149  }
    150150}
Note: See TracChangeset for help on using the changeset viewer.