Free cookie consent management tool by TermsFeed Policy Generator

Changeset 3870


Ignore:
Timestamp:
05/30/10 18:58:01 (15 years ago)
Author:
abeham
Message:

#866

  • Updated external evaluation problem
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  
    3333    public override bool CanChangeDescription { get { return false; } }
    3434
    35     private CodedInputStream inputStream;
    3635    private Stream input;
    37     private CodedOutputStream outputStream;
    3836    private Stream output;
    3937
     
    4240      : base() {
    4341      if (!input.CanRead) throw new ArgumentException("Input stream cannot be read", "input");
    44       this.inputStream = CodedInputStream.CreateInstance(input);
    4542      this.input = input;
    4643      if (!output.CanWrite) throw new ArgumentException("Output stream cannot be written", "output");
    47       this.outputStream = CodedOutputStream.CreateInstance(output);
    4844      this.output = output;
    4945    }
     
    5147    #region Overrides
    5248    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);
    5751      return message;
    5852    }
    5953
    6054    public override void EvaluateAsync(SolutionMessage solution, Action<QualityMessage> callback) {
    61       solution.WriteTo(outputStream);
    62       outputStream.Flush();
    63       output.Flush();
     55      Send(solution);
    6456      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      }
    6564    }
    6665
    6766    public override void Stop() {
    6867      base.Stop();
    69       inputStream = null;
    7068      input.Close();
    71       outputStream = null;
    7269      output.Close();
    7370    }
     
    7673    private void ReceiveAsync(object callback) {
    7774      QualityMessage message;
    78       lock (inputStream) { // only one thread can read from the stream at one time
    79         message = QualityMessage.ParseFrom(inputStream);
     75      lock (input) { // only one thread can read from the stream at one time
     76        message = QualityMessage.ParseDelimitedFrom(input);
    8077      }
    8178      ((Action<QualityMessage>)callback).Invoke(message);
  • trunk/sources/HeuristicLab.Problems.ExternalEvaluation/3.3/HeuristicLab.Problems.ExternalEvaluation-3.3.csproj

    r3864 r3870  
    8484    <Compile Include="Analyzers\BestExternalEvaluationSolutionAnalyzer.cs" />
    8585    <None Include="HeuristicLabProblemsExternalEvaluationPlugin.cs.frame" />
     86    <Compile Include="ExternalEvaluationManipulator.cs" />
    8687    <Compile Include="Drivers\ExternalEvaluationDriver.cs" />
    8788    <Compile Include="Drivers\ExternalEvaluationProcessDriver.cs" />
    8889    <Compile Include="Drivers\ExternalEvaluationStreamDriver.cs" />
     90    <Compile Include="ExternalEvaluationCrossover.cs" />
    8991    <Compile Include="ExternalEvaluationProblem.cs" />
    9092    <Compile Include="ExternalEvaluationSolutionCreator.cs" />
  • trunk/sources/HeuristicLab.Problems.ExternalEvaluation/3.3/SolutionMessageBuilding.cs

    r3862 r3870  
    8787      tmp.SetName(name);
    8888      for (int i = 0; i < valueTypeArray.Length; i++)
    89         tmp.SetData(i, valueTypeArray[i]);
     89        tmp.AddData(valueTypeArray[i]);
    9090      builder.AddIntegerArrayVars(tmp.Build());
    9191    }
     
    9494      tmp.SetName(name);
    9595      for (int i = 0; i < valueTypeArray.Length; i++)
    96         tmp.SetData(i, valueTypeArray[i]);
     96        tmp.AddData(valueTypeArray[i]);
    9797      builder.AddDoubleArrayVars(tmp.Build());
    9898    }
     
    101101      tmp.SetName(name);
    102102      for (int i = 0; i < valueTypeArray.Length; i++)
    103         tmp.SetData(i, valueTypeArray[i]);
     103        tmp.AddData(valueTypeArray[i]);
    104104      builder.AddBoolArrayVars(tmp.Build());
    105105    }
Note: See TracChangeset for help on using the changeset viewer.