Changeset 16233 for branches/2931_OR-Tools_LP_MIP/HeuristicLab.MathematicalOptimization/3.3/LinearProgramming/Problems/LinearProgrammingProblemDefinitionScript.cs
- Timestamp:
- 10/17/18 17:51:26 (6 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
branches/2931_OR-Tools_LP_MIP/HeuristicLab.MathematicalOptimization/3.3/LinearProgramming/Problems/LinearProgrammingProblemDefinitionScript.cs
r16172 r16233 1 1 #region License Information 2 2 3 /* HeuristicLab 3 4 * Copyright (C) 2002-2018 Heuristic and Evolutionary Algorithms Laboratory (HEAL) … … 18 19 * along with HeuristicLab. If not, see <http://www.gnu.org/licenses/>. 19 20 */ 20 #endregion 21 22 #endregion License Information 21 23 22 24 using System; … … 32 34 33 35 namespace HeuristicLab.MathematicalOptimization.LinearProgramming.Problems { 36 34 37 [Item("Single-objective Problem Definition Script", "Script that defines the parameter vector and evaluates the solution for a programmable problem.")] 35 38 [StorableClass] … … 39 42 [Storable] 40 43 private VariableStore variableStore; 44 41 45 public VariableStore VariableStore => variableStore; 42 46 … … 46 50 [StorableConstructor] 47 51 protected LinearProgrammingProblemDefinitionScript(bool deserializing) : base(deserializing) { } 52 48 53 protected LinearProgrammingProblemDefinitionScript(LinearProgrammingProblemDefinitionScript original, Cloner cloner) 49 54 : base(original, cloner) { … … 59 64 private readonly object compileLock = new object(); 60 65 private volatile ILinearProgrammingProblemDefinition compiledProblemDefinition; 66 61 67 protected ILinearProgrammingProblemDefinition CompiledProblemDefinition { 62 68 get { … … 65 71 lock (compileLock) { 66 72 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."); 68 75 Compile(false); 69 76 } … … 73 80 } 74 81 } 82 75 83 public dynamic Instance => compiledProblemDefinition; 76 84 77 public override Assembly Compile() { 78 return Compile(true); 79 } 85 public override Assembly Compile() => Compile(true); 80 86 81 87 private Assembly Compile(bool fireChanged) { … … 83 89 var types = assembly.GetTypes(); 84 90 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."); 86 94 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."); 88 98 89 99 CompiledProblemDefinition inst; 90 100 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))); 92 103 } catch (Exception e) { 93 104 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); 95 107 } 96 108 … … 100 112 } catch (Exception e) { 101 113 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); 103 116 } 104 117 … … 108 121 } catch (Exception e) { 109 122 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); 111 126 } 112 127 … … 122 137 123 138 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); 128 141 129 142 public string Filename { get; set; }
Note: See TracChangeset
for help on using the changeset viewer.