Changeset 9363 for branches/OaaS/HeuristicLab.Problems.ExternalEvaluation
- Timestamp:
- 04/16/13 13:13:41 (12 years ago)
- Location:
- branches/OaaS
- Files:
-
- 14 edited
Legend:
- Unmodified
- Added
- Removed
-
branches/OaaS
- Property svn:ignore
-
old new 21 21 protoc.exe 22 22 _ReSharper.HeuristicLab 3.3 Tests 23 Google.ProtocolBuffers-2.4.1.473.dll 23 24 packages
-
- Property svn:mergeinfo changed
- Property svn:ignore
-
branches/OaaS/HeuristicLab.Problems.ExternalEvaluation/3.3/Drivers/EvaluationChannel.cs
r7259 r9363 51 51 public abstract void Send(IMessage message); 52 52 53 public abstract IMessage Receive(IBuilder builder );53 public abstract IMessage Receive(IBuilder builder, ExtensionRegistry extensions); 54 54 55 55 public virtual void Close() { -
branches/OaaS/HeuristicLab.Problems.ExternalEvaluation/3.3/Drivers/EvaluationProcessChannel.cs
r7259 r9363 111 111 try { 112 112 streamingChannel.Send(message); 113 } 114 catch { 113 } catch { 115 114 Close(); 116 115 throw; … … 118 117 } 119 118 120 public override IMessage Receive(IBuilder builder ) {119 public override IMessage Receive(IBuilder builder, ExtensionRegistry extensions) { 121 120 try { 122 return streamingChannel.Receive(builder); 123 } 124 catch { 121 return streamingChannel.Receive(builder, extensions); 122 } catch { 125 123 Close(); 126 124 throw; … … 138 136 process.WaitForExit(1000); 139 137 process.Close(); 140 } 141 catch { } 138 } catch { } 142 139 } 143 140 // for some reasons the event process_Exited does not fire -
branches/OaaS/HeuristicLab.Problems.ExternalEvaluation/3.3/Drivers/EvaluationServiceClient.cs
r7259 r9363 21 21 22 22 using System; 23 using System.IO; 24 using Google.ProtocolBuffers; 23 25 using HeuristicLab.Common; 24 26 using HeuristicLab.Core; … … 73 75 74 76 #region IEvaluationServiceClient Members 75 public QualityMessage Evaluate(SolutionMessage solution ) {77 public QualityMessage Evaluate(SolutionMessage solution, ExtensionRegistry qualityExtensions) { 76 78 int tries = 0, maxTries = RetryParameter.Value.Value; 77 79 bool success = false; … … 82 84 CheckAndOpenChannel(); 83 85 Channel.Send(solution); 84 result = (QualityMessage)Channel.Receive(QualityMessage.CreateBuilder() );86 result = (QualityMessage)Channel.Receive(QualityMessage.CreateBuilder(), qualityExtensions); 85 87 success = true; 86 88 } catch (InvalidOperationException) { … … 91 93 } 92 94 } 95 if (result != null && result.SolutionId != solution.SolutionId) throw new InvalidDataException(Name + ": Received a quality for a different solution."); 93 96 return result; 94 97 } 95 98 96 public void EvaluateAsync(SolutionMessage solution, Action<QualityMessage> callback) {99 public void EvaluateAsync(SolutionMessage solution, ExtensionRegistry qualityExtensions, Action<QualityMessage> callback) { 97 100 int tries = 0, maxTries = RetryParameter.Value.Value; 98 101 bool success = false; … … 110 113 } 111 114 } 112 System.Threading.ThreadPool.QueueUserWorkItem(new System.Threading.WaitCallback(ReceiveAsync), callback);115 System.Threading.ThreadPool.QueueUserWorkItem(new System.Threading.WaitCallback(ReceiveAsync), new ReceiveAsyncInfo(solution, callback, qualityExtensions)); 113 116 } 114 117 #endregion … … 126 129 } 127 130 128 private void ReceiveAsync(object callback) { 131 private void ReceiveAsync(object callbackInfo) { 132 var info = (ReceiveAsyncInfo)callbackInfo; 129 133 QualityMessage message = null; 130 134 try { 131 message = (QualityMessage)Channel.Receive(QualityMessage.CreateBuilder() );135 message = (QualityMessage)Channel.Receive(QualityMessage.CreateBuilder(), info.QualityExtensions); 132 136 } catch { } 133 ((Action<QualityMessage>)callback).Invoke(message); 137 if (message != null && message.SolutionId != info.SolutionMessage.SolutionId) throw new InvalidDataException(Name + ": Received a quality for a different solution."); 138 info.CallbackDelegate.Invoke(message); 134 139 } 135 140 … … 146 151 } 147 152 #endregion 153 154 private class ReceiveAsyncInfo { 155 public SolutionMessage SolutionMessage { get; set; } 156 public Action<QualityMessage> CallbackDelegate { get; set; } 157 public ExtensionRegistry QualityExtensions { get; set; } 158 public ReceiveAsyncInfo(SolutionMessage solutionMessage, Action<QualityMessage> callbackDelegate, ExtensionRegistry qualityExtensions) { 159 SolutionMessage = solutionMessage; 160 CallbackDelegate = callbackDelegate; 161 QualityExtensions = qualityExtensions; 162 } 163 } 148 164 } 149 165 } -
branches/OaaS/HeuristicLab.Problems.ExternalEvaluation/3.3/Drivers/EvaluationStreamChannel.cs
r7259 r9363 60 60 } 61 61 62 public override IMessage Receive(IBuilder builder ) {62 public override IMessage Receive(IBuilder builder, ExtensionRegistry extensions) { 63 63 QualityMessage message; 64 64 lock (input) { // only one thread can read from the stream at one time 65 message = QualityMessage.ParseDelimitedFrom(input );65 message = QualityMessage.ParseDelimitedFrom(input, extensions); 66 66 } 67 67 return message; -
branches/OaaS/HeuristicLab.Problems.ExternalEvaluation/3.3/Drivers/EvaluationTCPChannel.cs
r7259 r9363 88 88 #endregion 89 89 90 90 91 91 92 92 #region IExternalEvaluationChannel Members … … 105 105 byte[] buffer = EncodeDelimited(message); 106 106 socket.Send(buffer); 107 } 108 catch (SocketException) { 109 Close(); 110 throw; 111 } 112 catch (ObjectDisposedException) { 107 } catch (SocketException) { 108 Close(); 109 throw; 110 } catch (ObjectDisposedException) { 113 111 socket = null; 114 112 Close(); … … 138 136 } 139 137 140 public override IMessage Receive(IBuilder builder ) {138 public override IMessage Receive(IBuilder builder, ExtensionRegistry extensions) { 141 139 try { 142 140 byte[] buffer = GetMessageBuffer(); 143 return builder.WeakMergeFrom(ByteString.CopyFrom(buffer)).WeakBuild(); 144 } 145 catch (SocketException) { 146 Close(); 147 throw; 148 } 149 catch (ObjectDisposedException) { 141 return builder.WeakMergeFrom(ByteString.CopyFrom(buffer), extensions).WeakBuild(); 142 } catch (SocketException) { 143 Close(); 144 throw; 145 } catch (ObjectDisposedException) { 150 146 socket = null; 151 147 Close(); … … 186 182 socket.Disconnect(false); 187 183 socket.Close(); 188 } 189 catch { } 184 } catch { } 190 185 socket = null; 191 186 } -
branches/OaaS/HeuristicLab.Problems.ExternalEvaluation/3.3/ExternalEvaluator.cs
r7259 r9363 24 24 using System.Linq; 25 25 using System.Threading; 26 using Google.ProtocolBuffers; 26 27 using HeuristicLab.Common; 27 28 using HeuristicLab.Core; … … 35 36 [StorableClass] 36 37 public class ExternalEvaluator : ValuesCollector, IExternalEvaluationProblemEvaluator { 38 protected HashSet<IEvaluationServiceClient> activeClients = new HashSet<IEvaluationServiceClient>(); 39 protected object clientLock = new object(); 37 40 38 41 #region Parameters … … 48 51 #endregion 49 52 50 #region Parameter Values53 #region Parameter Properties 51 54 protected SolutionMessageBuilder MessageBuilder { 52 55 get { return MessageBuilderParameter.Value; } … … 55 58 get { return ClientsParameter.ActualValue; } 56 59 } 57 #endregion58 59 #region Fields60 protected HashSet<IEvaluationServiceClient> activeClients = new HashSet<IEvaluationServiceClient>();61 protected object clientLock = new object();62 60 #endregion 63 61 … … 103 101 } 104 102 105 protected QualityMessage EvaluateOnNextAvailableClient(SolutionMessage message) {103 protected virtual QualityMessage EvaluateOnNextAvailableClient(SolutionMessage message) { 106 104 IEvaluationServiceClient client = null; 107 105 lock (clientLock) { … … 115 113 } 116 114 try { 117 return client.Evaluate(message );115 return client.Evaluate(message, GetQualityMessageExtensions()); 118 116 } finally { 119 117 lock (clientLock) { … … 124 122 } 125 123 126 protected SolutionMessage BuildSolutionMessage() { 124 protected virtual ExtensionRegistry GetQualityMessageExtensions() { 125 return ExtensionRegistry.CreateInstance(); 126 } 127 128 protected virtual SolutionMessage BuildSolutionMessage() { 127 129 lock (clientLock) { 128 130 SolutionMessage.Builder protobufBuilder = SolutionMessage.CreateBuilder(); -
branches/OaaS/HeuristicLab.Problems.ExternalEvaluation/3.3/HeuristicLab.Problems.ExternalEvaluation-3.3.csproj
r7021 r9363 95 95 </PropertyGroup> 96 96 <ItemGroup> 97 <Reference Include="Google.ProtocolBuffers- 0.9.1, Version=0.9.0.0, Culture=neutral, PublicKeyToken=17b3b1f090c3ea48, processorArchitecture=MSIL">98 <HintPath>..\..\bin\Google.ProtocolBuffers- 0.9.1.dll</HintPath>97 <Reference Include="Google.ProtocolBuffers-2.4.1.473, Version=2.4.1.473"> 98 <HintPath>..\..\bin\Google.ProtocolBuffers-2.4.1.473.dll</HintPath> 99 99 <Private>False</Private> 100 100 </Reference> … … 250 250 --> 251 251 <PropertyGroup> 252 <PreBuildEvent>set Path=%25Path%25;$(ProjectDir);$(SolutionDir)252 <PreBuildEvent Condition=" '$(OS)' == 'Windows_NT' ">set Path=%25Path%25;$(ProjectDir);$(SolutionDir) 253 253 set ProjectDir=$(ProjectDir) 254 254 set SolutionDir=$(SolutionDir) 255 255 256 call "$(ProjectDir)\Protos\ProcessProtos.cmd" 256 257 257 call PreBuildEvent.cmd 258 258 </PreBuildEvent> 259 <PreBuildEvent Condition=" '$(OS)' != 'Windows_NT' "> 260 export ProjectDir=$(ProjectDir) 261 export SolutionDir=$(SolutionDir) 262 263 $SolutionDir/PreBuildEvent.sh 264 </PreBuildEvent> 259 265 </PropertyGroup> 260 266 </Project> -
branches/OaaS/HeuristicLab.Problems.ExternalEvaluation/3.3/Interfaces/IEvaluationChannel.cs
r7259 r9363 48 48 /// <param name="builder">The builder that must match the message type that is to be received.</param> 49 49 /// <returns>The received message.</returns> 50 IMessage Receive(IBuilder builder );50 IMessage Receive(IBuilder builder, ExtensionRegistry extensions); 51 51 /// <summary> 52 52 /// Tells the channel to close down and terminate open connections. -
branches/OaaS/HeuristicLab.Problems.ExternalEvaluation/3.3/Interfaces/IEvaluationServiceClient.cs
r7259 r9363 21 21 22 22 using System; 23 using Google.ProtocolBuffers; 23 24 using HeuristicLab.Core; 24 25 … … 29 30 /// </summary> 30 31 /// <param name="solution">The solution message that should be evaluated.</param> 32 /// <param name="qualityExtensions">An extension registry for the quality message that specifies additional custom fields.</param> 31 33 /// <returns>The resulting quality message from the external process.</returns> 32 QualityMessage Evaluate(SolutionMessage solution );34 QualityMessage Evaluate(SolutionMessage solution, ExtensionRegistry qualityExtensions); 33 35 /// <summary> 34 36 /// Evaluates a given solution in a non-blocking manner. 35 37 /// </summary> 36 38 /// <param name="solution">The solution message that should be evaluated.</param> 39 /// <param name="qualityExtensions">An extension registry for the quality message that specifies additional custom fields.</param> 37 40 /// <param name="callback">The callback method that is invoked when evaluation is finished.</param> 38 void EvaluateAsync(SolutionMessage solution, Action<QualityMessage> callback);41 void EvaluateAsync(SolutionMessage solution, ExtensionRegistry qualityExtensions, Action<QualityMessage> callback); 39 42 } 40 43 } -
branches/OaaS/HeuristicLab.Problems.ExternalEvaluation/3.3/Plugin.cs.frame
r7259 r9363 23 23 24 24 namespace HeuristicLab.Problems.ExternalEvaluation { 25 [Plugin("HeuristicLab.Problems.ExternalEvaluation", "3.3. 6.$WCREV$")]25 [Plugin("HeuristicLab.Problems.ExternalEvaluation", "3.3.7.$WCREV$")] 26 26 [PluginFile("HeuristicLab.Problems.ExternalEvaluation-3.3.dll", PluginFileType.Assembly)] 27 27 [PluginDependency("HeuristicLab.Analysis", "3.3")] … … 36 36 [PluginDependency("HeuristicLab.Parameters", "3.3")] 37 37 [PluginDependency("HeuristicLab.Persistence", "3.3")] 38 [PluginDependency("HeuristicLab.ProtobufCS", " 0.9.1")]38 [PluginDependency("HeuristicLab.ProtobufCS", "2.4.1.473")] 39 39 public class HeuristicLabProblemsExternalEvaluationPlugin : PluginBase { 40 40 } -
branches/OaaS/HeuristicLab.Problems.ExternalEvaluation/3.3/Properties/AssemblyInfo.cs.frame
r7259 r9363 34 34 // [assembly: AssemblyVersion("1.0.*")] 35 35 [assembly: AssemblyVersion("3.3.0.0")] 36 [assembly: AssemblyFileVersion("3.3. 6.$WCREV$")]36 [assembly: AssemblyFileVersion("3.3.7.$WCREV$")] -
branches/OaaS/HeuristicLab.Problems.ExternalEvaluation/3.3/Protos/ExternalEvaluationMessages.proto
r3881 r9363 67 67 required int32 solutionId = 1; 68 68 required double quality = 2; 69 70 extensions 1000 to max; 69 71 } 70 72 -
branches/OaaS/HeuristicLab.Problems.ExternalEvaluation/3.3/Protos/ProcessProtos.cmd
r3859 r9363 1 cd "%ProjectDir%"Protos 2 3 for %%i in (*.proto) do ( 4 "%SolutionDir%"protoc -otmp %%i 5 "%SolutionDir%"ProtoGen tmp 6 del tmp) 1 for %%i in ("%ProjectDir%Protos\*.proto") do ( 2 echo Processing %%i 3 ProtoGen --proto_path="%ProjectDir%\Protos" "%%i" --include_imports -output_directory="%ProjectDir%Protos" 4 )
Note: See TracChangeset
for help on using the changeset viewer.