Changeset 10754 for branches/SimSharp/HeuristicLab.Problems.Programmable/3.3/ProgrammableProblemScript.cs
- Timestamp:
- 04/15/14 22:34:05 (11 years ago)
- File:
-
- 1 copied
Legend:
- Unmodified
- Added
- Removed
-
branches/SimSharp/HeuristicLab.Problems.Programmable/3.3/ProgrammableProblemScript.cs
r10753 r10754 29 29 30 30 namespace HeuristicLab.Problems.Programmable { 31 [Item("ProgrammableProblemScript", "Script that defines the parameter vector and evaluates the solution .")]31 [Item("ProgrammableProblemScript", "Script that defines the parameter vector and evaluates the solution for a programmable problem.")] 32 32 [StorableClass] 33 public class ProgrammableProblemScript : Script, IStorableContent { 34 public string Filename { get; set; } 33 public abstract class ProgrammableProblemScript : Script { 35 34 protected bool SuppressEvents { get; set; } 36 35 … … 41 40 public ProgrammableProblemScript() { } 42 41 43 public override IDeepCloneable Clone(Cloner cloner) { 44 return new ProgrammableProblemScript(this, cloner); 45 } 46 47 private volatile ProgrammableProblemBase instance; 42 private volatile ProblemBase instance; 48 43 private object locker = new object(); 49 public Pro grammableProblemBase Instance {44 public ProblemBase Instance { 50 45 get { 51 46 SuppressEvents = true; … … 70 65 protected set { 71 66 instance = value; 72 OnInstanceChanged(); 73 } 74 } 75 76 protected override string CodeTemplate { 77 get { 78 return @"using System; 79 using System.Linq; 80 using System.Collections.Generic; 81 using HeuristicLab.Common; 82 using HeuristicLab.Core; 83 using HeuristicLab.Data; 84 using HeuristicLab.Encodings.ParameterVectorEncoding; 85 using HeuristicLab.Encodings.PermutationEncoding; 86 87 public class MyProblem : HeuristicLab.Problems.Programmable.ProgrammableProblemBase { 88 public MyProblem() { 89 // initialize private fields 90 } 91 public override bool IsMaximizationProblem { get { return false; } } 92 public override ParameterVector GetParametersToOptimize() { 93 return new ParameterVectorBuilder() 94 // .AddBoolean(""Parameter"") 95 // .AddInteger(""Parameter"", min: 5, max: 15, step: 3) 96 // .AddReal(""Parameter"", min: 0.0, max: 1.0) 97 // .SetPermutation(type: PermutationTypes.Absolute, length: 10) 98 .Build(); 99 } 100 101 public override void EvaluateFeasibility(ParameterVector vector) { 102 vector.IsFeasible = true 103 // && vector.Integer(""Parameter1"") < vector.Integer(""Parameter2""); 104 // && (vector.Real(""Parameter3"") >= 1.0 || (vector.Real(""Parameter3"") < 1.0 && vector.Integer(""Parameter1"") < 5)); 105 ; 106 } 107 108 public override double Evaluate(IRandom random, ParameterVector vector) { 109 var quality = 0.0; 110 return quality; 111 } 112 113 // implement further classes and methods 114 }"; 67 if (!SuppressEvents) OnInstanceChanged(); 115 68 } 116 69 } … … 120 73 var types = assembly.GetTypes(); 121 74 try { 122 instance = (ProgrammableProblemBase)Activator.CreateInstance(types.First(x => typeof(ProgrammableProblemBase).IsAssignableFrom(x)));75 Instance = (ProblemBase)Activator.CreateInstance(types.First(x => typeof(ProblemBase).IsAssignableFrom(x))); 123 76 } catch { 124 instance = null;77 Instance = null; 125 78 } 126 if (!SuppressEvents) OnInstanceChanged();127 79 return assembly; 128 80 }
Note: See TracChangeset
for help on using the changeset viewer.