- Timestamp:
- 03/07/16 10:18:05 (9 years ago)
- Location:
- branches/WebJobManager
- Files:
-
- 3 edited
- 1 copied
Legend:
- Unmodified
- Added
- Removed
-
branches/WebJobManager/HeuristicLab.Problems.ExternalEvaluation/3.4/EvaluationCache.cs
r13203 r13656 32 32 using Google.ProtocolBuffers; 33 33 using HeuristicLab.Common; 34 using HeuristicLab.Common.Resources;35 34 using HeuristicLab.Core; 36 35 using HeuristicLab.Data; … … 54 53 private object lockObject = new object(); 55 54 56 public byte[] RawMessage { 55 public byte[] RawMessage 56 { 57 57 get { return rawMessage; } 58 set { 58 set 59 { 59 60 lock (lockObject) { 60 61 rawMessage = value; … … 130 131 131 132 #region Properties 132 public static new System.Drawing.Image StaticItemImage { 133 get { return VSImageLibrary.Database; } 134 } 133 135 134 public int Size { get { lock (cacheLock) return index.Count; } } 136 135 public int ActiveEvaluations { get { lock (cacheLock) return activeEvaluations.Count; } } … … 151 150 152 151 #region Parameters 153 public FixedValueParameter<IntValue> CapacityParameter { 152 public FixedValueParameter<IntValue> CapacityParameter 153 { 154 154 get { return (FixedValueParameter<IntValue>)Parameters["Capacity"]; } 155 155 } 156 public FixedValueParameter<BoolValue> PersistentCacheParameter { 156 public FixedValueParameter<BoolValue> PersistentCacheParameter 157 { 157 158 get { return (FixedValueParameter<BoolValue>)Parameters["PersistentCache"]; } 158 159 } … … 160 161 161 162 #region Parameter Values 162 public int Capacity { 163 public int Capacity 164 { 163 165 get { return CapacityParameter.Value.Value; } 164 166 set { CapacityParameter.Value.Value = value; } 165 167 } 166 public bool IsPersistent { 168 public bool IsPersistent 169 { 167 170 get { return PersistentCacheParameter.Value.Value; } 168 171 } … … 172 175 #region BackwardsCompatibility3.4 173 176 [Storable(Name = "Cache")] 174 private IEnumerable<KeyValuePair<string, double>> Cache_Persistence_backwardscompatability { 177 private IEnumerable<KeyValuePair<string, double>> Cache_Persistence_backwardscompatability 178 { 175 179 get { return Enumerable.Empty<KeyValuePair<string, double>>(); } 176 set { 180 set 181 { 177 182 var rawMessages = value.ToDictionary(kvp => kvp.Key, 178 183 kvp => QualityMessage.CreateBuilder() … … 187 192 #endregion 188 193 [Storable(Name = "CacheNew")] 189 private IEnumerable<KeyValuePair<string, byte[]>> Cache_Persistence { 194 private IEnumerable<KeyValuePair<string, byte[]>> Cache_Persistence 195 { 190 196 get { return IsPersistent ? GetCacheValues() : Enumerable.Empty<KeyValuePair<string, byte[]>>(); } 191 197 set { SetCacheValues(value); } … … 273 279 index[entry] = list.AddLast(entry); 274 280 Trim(); 275 } finally { 281 } 282 finally { 276 283 if (!lockTaken) 277 284 Monitor.Enter(cacheLock, ref lockTaken); … … 286 293 } 287 294 } 288 } finally { 295 } 296 finally { 289 297 if (lockTaken) 290 298 Monitor.Exit(cacheLock); -
branches/WebJobManager/HeuristicLab.Problems.ExternalEvaluation/3.4/ExternalEvaluationProblem.cs
r13500 r13656 22 22 using System; 23 23 using System.Collections.Generic; 24 using System.Drawing;25 24 using System.Linq; 26 25 using System.Threading; … … 42 41 public class ExternalEvaluationProblem : SingleObjectiveBasicProblem<IEncoding>, IExternalEvaluationProblem { 43 42 44 public static new Image StaticItemImage { 45 get { return HeuristicLab.Common.Resources.VSImageLibrary.Type; } 46 } 43 47 44 48 45 #region Parameters 49 public OptionalValueParameter<EvaluationCache> CacheParameter { 46 public OptionalValueParameter<EvaluationCache> CacheParameter 47 { 50 48 get { return (OptionalValueParameter<EvaluationCache>)Parameters["Cache"]; } 51 49 } 52 public IValueParameter<CheckedItemCollection<IEvaluationServiceClient>> ClientsParameter { 50 public IValueParameter<CheckedItemCollection<IEvaluationServiceClient>> ClientsParameter 51 { 53 52 get { return (IValueParameter<CheckedItemCollection<IEvaluationServiceClient>>)Parameters["Clients"]; } 54 53 } 55 public IValueParameter<SolutionMessageBuilder> MessageBuilderParameter { 54 public IValueParameter<SolutionMessageBuilder> MessageBuilderParameter 55 { 56 56 get { return (IValueParameter<SolutionMessageBuilder>)Parameters["MessageBuilder"]; } 57 57 } 58 public IFixedValueParameter<SingleObjectiveOptimizationSupportScript> SupportScriptParameter { 58 public IFixedValueParameter<SingleObjectiveOptimizationSupportScript> SupportScriptParameter 59 { 59 60 get { return (IFixedValueParameter<SingleObjectiveOptimizationSupportScript>)Parameters["SupportScript"]; } 60 61 } 61 62 62 private IFixedValueParameter<BoolValue> MaximizationParameter { 63 private IFixedValueParameter<BoolValue> MaximizationParameter 64 { 63 65 get { return (IFixedValueParameter<BoolValue>)Parameters["Maximization"]; } 64 66 } … … 66 68 67 69 #region Properties 68 public new IEncoding Encoding { 70 public new IEncoding Encoding 71 { 69 72 get { return base.Encoding; } 70 73 set { base.Encoding = value; } 71 74 } 72 public EvaluationCache Cache { 75 public EvaluationCache Cache 76 { 73 77 get { return CacheParameter.Value; } 74 78 } 75 public CheckedItemCollection<IEvaluationServiceClient> Clients { 79 public CheckedItemCollection<IEvaluationServiceClient> Clients 80 { 76 81 get { return ClientsParameter.Value; } 77 82 } 78 public SolutionMessageBuilder MessageBuilder { 83 public SolutionMessageBuilder MessageBuilder 84 { 79 85 get { return MessageBuilderParameter.Value; } 80 86 } 81 public SingleObjectiveOptimizationSupportScript OptimizationSupportScript { 87 public SingleObjectiveOptimizationSupportScript OptimizationSupportScript 88 { 82 89 get { return SupportScriptParameter.Value; } 83 90 } 84 private ISingleObjectiveOptimizationSupport OptimizationSupport { 91 private ISingleObjectiveOptimizationSupport OptimizationSupport 92 { 85 93 get { return SupportScriptParameter.Value; } 86 94 } … … 106 114 107 115 #region Single Objective Problem Overrides 108 public override bool Maximization { 116 public override bool Maximization 117 { 109 118 get { return Parameters.ContainsKey("Maximization") && ((IValueParameter<BoolValue>)Parameters["Maximization"]).Value.Value; } 110 119 } … … 158 167 try { 159 168 return client.Evaluate(message, GetQualityMessageExtensions()); 160 } finally { 169 } 170 finally { 161 171 lock (clientLock) { 162 172 activeClients.Remove(client); … … 175 185 try { 176 186 MessageBuilder.AddToMessage(variable.Value, variable.Name, protobufBuilder); 177 } catch (ArgumentException ex) { 187 } 188 catch (ArgumentException ex) { 178 189 throw new InvalidOperationException(string.Format("ERROR while building solution message: Parameter {0} cannot be added to the message", Name), ex); 179 190 } -
branches/WebJobManager/HeuristicLab.Problems.ExternalEvaluation/3.4/MultiObjectiveExternalEvaluationProblem.cs
r13500 r13656 22 22 using System; 23 23 using System.Collections.Generic; 24 using System.Drawing;25 24 using System.Linq; 26 25 using System.Threading; … … 39 38 public class MultiObjectiveExternalEvaluationProblem : MultiObjectiveBasicProblem<IEncoding>, IExternalEvaluationProblem { 40 39 41 public static new Image StaticItemImage { 42 get { return HeuristicLab.Common.Resources.VSImageLibrary.Type; } 43 } 40 44 41 45 42 #region Parameters 46 public OptionalValueParameter<EvaluationCache> CacheParameter { 43 public OptionalValueParameter<EvaluationCache> CacheParameter 44 { 47 45 get { return (OptionalValueParameter<EvaluationCache>)Parameters["Cache"]; } 48 46 } 49 public IValueParameter<CheckedItemCollection<IEvaluationServiceClient>> ClientsParameter { 47 public IValueParameter<CheckedItemCollection<IEvaluationServiceClient>> ClientsParameter 48 { 50 49 get { return (IValueParameter<CheckedItemCollection<IEvaluationServiceClient>>)Parameters["Clients"]; } 51 50 } 52 public IValueParameter<SolutionMessageBuilder> MessageBuilderParameter { 51 public IValueParameter<SolutionMessageBuilder> MessageBuilderParameter 52 { 53 53 get { return (IValueParameter<SolutionMessageBuilder>)Parameters["MessageBuilder"]; } 54 54 } 55 public IFixedValueParameter<MultiObjectiveOptimizationSupportScript> SupportScriptParameter { 55 public IFixedValueParameter<MultiObjectiveOptimizationSupportScript> SupportScriptParameter 56 { 56 57 get { return (IFixedValueParameter<MultiObjectiveOptimizationSupportScript>)Parameters["SupportScript"]; } 57 58 } 58 59 59 private IFixedValueParameter<BoolArray> MaximizationParameter { 60 private IFixedValueParameter<BoolArray> MaximizationParameter 61 { 60 62 get { return (IFixedValueParameter<BoolArray>)Parameters["Maximization"]; } 61 63 } … … 63 65 64 66 #region Properties 65 public new IEncoding Encoding { 67 public new IEncoding Encoding 68 { 66 69 get { return base.Encoding; } 67 70 set { base.Encoding = value; } 68 71 } 69 public EvaluationCache Cache { 72 public EvaluationCache Cache 73 { 70 74 get { return CacheParameter.Value; } 71 75 } 72 public CheckedItemCollection<IEvaluationServiceClient> Clients { 76 public CheckedItemCollection<IEvaluationServiceClient> Clients 77 { 73 78 get { return ClientsParameter.Value; } 74 79 } 75 public SolutionMessageBuilder MessageBuilder { 80 public SolutionMessageBuilder MessageBuilder 81 { 76 82 get { return MessageBuilderParameter.Value; } 77 83 } 78 public MultiObjectiveOptimizationSupportScript OptimizationSupportScript { 84 public MultiObjectiveOptimizationSupportScript OptimizationSupportScript 85 { 79 86 get { return SupportScriptParameter.Value; } 80 87 } 81 private IMultiObjectiveOptimizationSupport OptimizationSupport { 88 private IMultiObjectiveOptimizationSupport OptimizationSupport 89 { 82 90 get { return SupportScriptParameter.Value; } 83 91 } … … 101 109 102 110 #region Multi Objective Problem Overrides 103 public override bool[] Maximization { 104 get { 111 public override bool[] Maximization 112 { 113 get 114 { 105 115 return Parameters.ContainsKey("Maximization") ? ((IValueParameter<BoolArray>)Parameters["Maximization"]).Value.ToArray() : new bool[0]; 106 116 } … … 155 165 try { 156 166 return client.Evaluate(message, GetQualityMessageExtensions()); 157 } finally { 167 } 168 finally { 158 169 lock (clientLock) { 159 170 activeClients.Remove(client); … … 172 183 try { 173 184 MessageBuilder.AddToMessage(variable.Value, variable.Name, protobufBuilder); 174 } catch (ArgumentException ex) { 185 } 186 catch (ArgumentException ex) { 175 187 throw new InvalidOperationException(string.Format("ERROR while building solution message: Parameter {0} cannot be added to the message", Name), ex); 176 188 }
Note: See TracChangeset
for help on using the changeset viewer.