Changeset 3870
- Timestamp:
- 05/30/10 18:58:01 (15 years ago)
- Location:
- trunk/sources/HeuristicLab.Problems.ExternalEvaluation/3.3
- Files:
-
- 2 added
- 3 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/sources/HeuristicLab.Problems.ExternalEvaluation/3.3/Drivers/ExternalEvaluationStreamDriver.cs
r3865 r3870 33 33 public override bool CanChangeDescription { get { return false; } } 34 34 35 private CodedInputStream inputStream;36 35 private Stream input; 37 private CodedOutputStream outputStream;38 36 private Stream output; 39 37 … … 42 40 : base() { 43 41 if (!input.CanRead) throw new ArgumentException("Input stream cannot be read", "input"); 44 this.inputStream = CodedInputStream.CreateInstance(input);45 42 this.input = input; 46 43 if (!output.CanWrite) throw new ArgumentException("Output stream cannot be written", "output"); 47 this.outputStream = CodedOutputStream.CreateInstance(output);48 44 this.output = output; 49 45 } … … 51 47 #region Overrides 52 48 public override QualityMessage Evaluate(SolutionMessage solution) { 53 solution.WriteTo(outputStream); 54 outputStream.Flush(); 55 output.Flush(); 56 QualityMessage message = QualityMessage.ParseFrom(inputStream); 49 Send(solution); 50 QualityMessage message = QualityMessage.ParseDelimitedFrom(input); 57 51 return message; 58 52 } 59 53 60 54 public override void EvaluateAsync(SolutionMessage solution, Action<QualityMessage> callback) { 61 solution.WriteTo(outputStream); 62 outputStream.Flush(); 63 output.Flush(); 55 Send(solution); 64 56 System.Threading.ThreadPool.QueueUserWorkItem(new System.Threading.WaitCallback(ReceiveAsync), callback); 57 } 58 59 private void Send(SolutionMessage solution) { 60 lock (output) { 61 solution.WriteDelimitedTo(output); 62 output.Flush(); 63 } 65 64 } 66 65 67 66 public override void Stop() { 68 67 base.Stop(); 69 inputStream = null;70 68 input.Close(); 71 outputStream = null;72 69 output.Close(); 73 70 } … … 76 73 private void ReceiveAsync(object callback) { 77 74 QualityMessage message; 78 lock (input Stream) { // only one thread can read from the stream at one time79 message = QualityMessage.Parse From(inputStream);75 lock (input) { // only one thread can read from the stream at one time 76 message = QualityMessage.ParseDelimitedFrom(input); 80 77 } 81 78 ((Action<QualityMessage>)callback).Invoke(message); -
trunk/sources/HeuristicLab.Problems.ExternalEvaluation/3.3/HeuristicLab.Problems.ExternalEvaluation-3.3.csproj
r3864 r3870 84 84 <Compile Include="Analyzers\BestExternalEvaluationSolutionAnalyzer.cs" /> 85 85 <None Include="HeuristicLabProblemsExternalEvaluationPlugin.cs.frame" /> 86 <Compile Include="ExternalEvaluationManipulator.cs" /> 86 87 <Compile Include="Drivers\ExternalEvaluationDriver.cs" /> 87 88 <Compile Include="Drivers\ExternalEvaluationProcessDriver.cs" /> 88 89 <Compile Include="Drivers\ExternalEvaluationStreamDriver.cs" /> 90 <Compile Include="ExternalEvaluationCrossover.cs" /> 89 91 <Compile Include="ExternalEvaluationProblem.cs" /> 90 92 <Compile Include="ExternalEvaluationSolutionCreator.cs" /> -
trunk/sources/HeuristicLab.Problems.ExternalEvaluation/3.3/SolutionMessageBuilding.cs
r3862 r3870 87 87 tmp.SetName(name); 88 88 for (int i = 0; i < valueTypeArray.Length; i++) 89 tmp. SetData(i,valueTypeArray[i]);89 tmp.AddData(valueTypeArray[i]); 90 90 builder.AddIntegerArrayVars(tmp.Build()); 91 91 } … … 94 94 tmp.SetName(name); 95 95 for (int i = 0; i < valueTypeArray.Length; i++) 96 tmp. SetData(i,valueTypeArray[i]);96 tmp.AddData(valueTypeArray[i]); 97 97 builder.AddDoubleArrayVars(tmp.Build()); 98 98 } … … 101 101 tmp.SetName(name); 102 102 for (int i = 0; i < valueTypeArray.Length; i++) 103 tmp. SetData(i,valueTypeArray[i]);103 tmp.AddData(valueTypeArray[i]); 104 104 builder.AddBoolArrayVars(tmp.Build()); 105 105 }
Note: See TracChangeset
for help on using the changeset viewer.