Free cookie consent management tool by TermsFeed Policy Generator

Ignore:
Timestamp:
10/17/18 17:51:26 (6 years ago)
Author:
ddorfmei
Message:

#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:
1 edited

Legend:

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

    r16172 r16233  
    11#region License Information
     2
    23/* HeuristicLab
    34 * Copyright (C) 2002-2018 Heuristic and Evolutionary Algorithms Laboratory (HEAL)
     
    1819 * along with HeuristicLab. If not, see <http://www.gnu.org/licenses/>.
    1920 */
    20 #endregion
     21
     22#endregion License Information
    2123
    2224using System;
     
    3234
    3335namespace HeuristicLab.MathematicalOptimization.LinearProgramming.Problems {
     36
    3437  [Item("Single-objective Problem Definition Script", "Script that defines the parameter vector and evaluates the solution for a programmable problem.")]
    3538  [StorableClass]
     
    3942    [Storable]
    4043    private VariableStore variableStore;
     44
    4145    public VariableStore VariableStore => variableStore;
    4246
     
    4650    [StorableConstructor]
    4751    protected LinearProgrammingProblemDefinitionScript(bool deserializing) : base(deserializing) { }
     52
    4853    protected LinearProgrammingProblemDefinitionScript(LinearProgrammingProblemDefinitionScript original, Cloner cloner)
    4954      : base(original, cloner) {
     
    5964    private readonly object compileLock = new object();
    6065    private volatile ILinearProgrammingProblemDefinition compiledProblemDefinition;
     66
    6167    protected ILinearProgrammingProblemDefinition CompiledProblemDefinition {
    6268      get {
     
    6571          lock (compileLock) {
    6672            if (compiledProblemDefinition == null) {
    67               if (codeChanged) throw new ProblemDefinitionScriptException("The code has been changed, but was not recompiled.");
     73              if (codeChanged)
     74                throw new ProblemDefinitionScriptException("The code has been changed, but was not recompiled.");
    6875              Compile(false);
    6976            }
     
    7380      }
    7481    }
     82
    7583    public dynamic Instance => compiledProblemDefinition;
    7684
    77     public override Assembly Compile() {
    78       return Compile(true);
    79     }
     85    public override Assembly Compile() => Compile(true);
    8086
    8187    private Assembly Compile(bool fireChanged) {
     
    8389      var types = assembly.GetTypes();
    8490      if (!types.Any(x => typeof(CompiledProblemDefinition).IsAssignableFrom(x)))
    85         throw new ProblemDefinitionScriptException("The compiled code doesn't contain a problem definition." + Environment.NewLine + "The problem definition must be a subclass of CompiledProblemDefinition.");
     91        throw new ProblemDefinitionScriptException("The compiled code doesn't contain a problem definition." +
     92                                                   Environment.NewLine +
     93                                                   "The problem definition must be a subclass of CompiledProblemDefinition.");
    8694      if (types.Count(x => typeof(CompiledProblemDefinition).IsAssignableFrom(x)) > 1)
    87         throw new ProblemDefinitionScriptException("The compiled code contains multiple problem definitions." + Environment.NewLine + "Only one subclass of CompiledProblemDefinition is allowed.");
     95        throw new ProblemDefinitionScriptException("The compiled code contains multiple problem definitions." +
     96                                                   Environment.NewLine +
     97                                                   "Only one subclass of CompiledProblemDefinition is allowed.");
    8898
    8999      CompiledProblemDefinition inst;
    90100      try {
    91         inst = (CompiledProblemDefinition)Activator.CreateInstance(types.Single(x => typeof(CompiledProblemDefinition).IsAssignableFrom(x)));
     101        inst = (CompiledProblemDefinition)Activator.CreateInstance(types.Single(x =>
     102         typeof(CompiledProblemDefinition).IsAssignableFrom(x)));
    92103      } catch (Exception e) {
    93104        compiledProblemDefinition = null;
    94         throw new ProblemDefinitionScriptException("Instantiating the problem definition failed." + Environment.NewLine + "Check your default constructor.", e);
     105        throw new ProblemDefinitionScriptException(
     106          "Instantiating the problem definition failed." + Environment.NewLine + "Check your default constructor.", e);
    95107      }
    96108
     
    100112      } catch (Exception e) {
    101113        compiledProblemDefinition = null;
    102         throw new ProblemDefinitionScriptException("Initializing the problem definition failed." + Environment.NewLine + "Check your Initialize() method.", e);
     114        throw new ProblemDefinitionScriptException(
     115          "Initializing the problem definition failed." + Environment.NewLine + "Check your Initialize() method.", e);
    103116      }
    104117
     
    108121      } catch (Exception e) {
    109122        compiledProblemDefinition = null;
    110         throw new ProblemDefinitionScriptException("Using the problem definition in the problem failed." + Environment.NewLine + "Examine this error message carefully (often there is an issue with the defined encoding).", e);
     123        throw new ProblemDefinitionScriptException(
     124          "Using the problem definition in the problem failed." + Environment.NewLine +
     125          "Examine this error message carefully (often there is an issue with the defined encoding).", e);
    111126      }
    112127
     
    122137
    123138    public event EventHandler ProblemDefinitionChanged;
    124     private void OnProblemDefinitionChanged() {
    125       var handler = ProblemDefinitionChanged;
    126       if (handler != null) handler(this, EventArgs.Empty);
    127     }
     139
     140    private void OnProblemDefinitionChanged() => ProblemDefinitionChanged?.Invoke(this, EventArgs.Empty);
    128141
    129142    public string Filename { get; set; }
Note: See TracChangeset for help on using the changeset viewer.