Free cookie consent management tool by TermsFeed Policy Generator

Ignore:
Timestamp:
09/14/12 18:58:15 (12 years ago)
Author:
gkronber
Message:

#1847 merged r8205:8635 from trunk into branch

Location:
branches/GP-MoveOperators
Files:
14 edited

Legend:

Unmodified
Added
Removed
  • branches/GP-MoveOperators

  • branches/GP-MoveOperators/HeuristicLab.Problems.ExternalEvaluation/3.3/Drivers/EvaluationChannel.cs

    r7259 r8660  
    5151    public abstract void Send(IMessage message);
    5252
    53     public abstract IMessage Receive(IBuilder builder);
     53    public abstract IMessage Receive(IBuilder builder, ExtensionRegistry extensions);
    5454
    5555    public virtual void Close() {
  • branches/GP-MoveOperators/HeuristicLab.Problems.ExternalEvaluation/3.3/Drivers/EvaluationProcessChannel.cs

    r7259 r8660  
    111111      try {
    112112        streamingChannel.Send(message);
    113       }
    114       catch {
     113      } catch {
    115114        Close();
    116115        throw;
     
    118117    }
    119118
    120     public override IMessage Receive(IBuilder builder) {
     119    public override IMessage Receive(IBuilder builder, ExtensionRegistry extensions) {
    121120      try {
    122         return streamingChannel.Receive(builder);
    123       }
    124       catch {
     121        return streamingChannel.Receive(builder, extensions);
     122      } catch {
    125123        Close();
    126124        throw;
     
    138136              process.WaitForExit(1000);
    139137              process.Close();
    140             }
    141             catch { }
     138            } catch { }
    142139          }
    143140          // for some reasons the event process_Exited does not fire
  • branches/GP-MoveOperators/HeuristicLab.Problems.ExternalEvaluation/3.3/Drivers/EvaluationServiceClient.cs

    r7259 r8660  
    2121
    2222using System;
     23using System.IO;
     24using Google.ProtocolBuffers;
    2325using HeuristicLab.Common;
    2426using HeuristicLab.Core;
     
    7375
    7476    #region IEvaluationServiceClient Members
    75     public QualityMessage Evaluate(SolutionMessage solution) {
     77    public QualityMessage Evaluate(SolutionMessage solution, ExtensionRegistry qualityExtensions) {
    7678      int tries = 0, maxTries = RetryParameter.Value.Value;
    7779      bool success = false;
     
    8284          CheckAndOpenChannel();
    8385          Channel.Send(solution);
    84           result = (QualityMessage)Channel.Receive(QualityMessage.CreateBuilder());
     86          result = (QualityMessage)Channel.Receive(QualityMessage.CreateBuilder(), qualityExtensions);
    8587          success = true;
    8688        } catch (InvalidOperationException) {
     
    9193        }
    9294      }
     95      if (result != null && result.SolutionId != solution.SolutionId) throw new InvalidDataException(Name + ": Received a quality for a different solution.");
    9396      return result;
    9497    }
    9598
    96     public void EvaluateAsync(SolutionMessage solution, Action<QualityMessage> callback) {
     99    public void EvaluateAsync(SolutionMessage solution, ExtensionRegistry qualityExtensions, Action<QualityMessage> callback) {
    97100      int tries = 0, maxTries = RetryParameter.Value.Value;
    98101      bool success = false;
     
    110113        }
    111114      }
    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));
    113116    }
    114117    #endregion
     
    126129    }
    127130
    128     private void ReceiveAsync(object callback) {
     131    private void ReceiveAsync(object callbackInfo) {
     132      var info = (ReceiveAsyncInfo)callbackInfo;
    129133      QualityMessage message = null;
    130134      try {
    131         message = (QualityMessage)Channel.Receive(QualityMessage.CreateBuilder());
     135        message = (QualityMessage)Channel.Receive(QualityMessage.CreateBuilder(), info.QualityExtensions);
    132136      } 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);
    134139    }
    135140
     
    146151    }
    147152    #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    }
    148164  }
    149165}
  • branches/GP-MoveOperators/HeuristicLab.Problems.ExternalEvaluation/3.3/Drivers/EvaluationStreamChannel.cs

    r7259 r8660  
    6060    }
    6161
    62     public override IMessage Receive(IBuilder builder) {
     62    public override IMessage Receive(IBuilder builder, ExtensionRegistry extensions) {
    6363      QualityMessage message;
    6464      lock (input) { // only one thread can read from the stream at one time
    65         message = QualityMessage.ParseDelimitedFrom(input);
     65        message = QualityMessage.ParseDelimitedFrom(input, extensions);
    6666      }
    6767      return message;
  • branches/GP-MoveOperators/HeuristicLab.Problems.ExternalEvaluation/3.3/Drivers/EvaluationTCPChannel.cs

    r7259 r8660  
    8888    #endregion
    8989
    90    
     90
    9191
    9292    #region IExternalEvaluationChannel Members
     
    105105        byte[] buffer = EncodeDelimited(message);
    106106        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) {
    113111        socket = null;
    114112        Close();
     
    138136    }
    139137
    140     public override IMessage Receive(IBuilder builder) {
     138    public override IMessage Receive(IBuilder builder, ExtensionRegistry extensions) {
    141139      try {
    142140        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) {
    150146        socket = null;
    151147        Close();
     
    186182            socket.Disconnect(false);
    187183          socket.Close();
    188         }
    189         catch { }
     184        } catch { }
    190185        socket = null;
    191186      }
  • branches/GP-MoveOperators/HeuristicLab.Problems.ExternalEvaluation/3.3/ExternalEvaluator.cs

    r7259 r8660  
    2424using System.Linq;
    2525using System.Threading;
     26using Google.ProtocolBuffers;
    2627using HeuristicLab.Common;
    2728using HeuristicLab.Core;
     
    3536  [StorableClass]
    3637  public class ExternalEvaluator : ValuesCollector, IExternalEvaluationProblemEvaluator {
     38    protected HashSet<IEvaluationServiceClient> activeClients = new HashSet<IEvaluationServiceClient>();
     39    protected object clientLock = new object();
    3740
    3841    #region Parameters
     
    4851    #endregion
    4952
    50     #region Parameter Values
     53    #region Parameter Properties
    5154    protected SolutionMessageBuilder MessageBuilder {
    5255      get { return MessageBuilderParameter.Value; }
     
    5558      get { return ClientsParameter.ActualValue; }
    5659    }
    57     #endregion
    58 
    59     #region Fields
    60     protected HashSet<IEvaluationServiceClient> activeClients = new HashSet<IEvaluationServiceClient>();
    61     protected object clientLock = new object();
    6260    #endregion
    6361
     
    103101    }
    104102
    105     protected QualityMessage EvaluateOnNextAvailableClient(SolutionMessage message) {
     103    protected virtual QualityMessage EvaluateOnNextAvailableClient(SolutionMessage message) {
    106104      IEvaluationServiceClient client = null;
    107105      lock (clientLock) {
     
    115113      }
    116114      try {
    117         return client.Evaluate(message);
     115        return client.Evaluate(message, GetQualityMessageExtensions());
    118116      } finally {
    119117        lock (clientLock) {
     
    124122    }
    125123
    126     protected SolutionMessage BuildSolutionMessage() {
     124    protected virtual ExtensionRegistry GetQualityMessageExtensions() {
     125      return ExtensionRegistry.CreateInstance();
     126    }
     127
     128    protected virtual SolutionMessage BuildSolutionMessage() {
    127129      lock (clientLock) {
    128130        SolutionMessage.Builder protobufBuilder = SolutionMessage.CreateBuilder();
  • branches/GP-MoveOperators/HeuristicLab.Problems.ExternalEvaluation/3.3/HeuristicLab.Problems.ExternalEvaluation-3.3.csproj

    r7021 r8660  
    9595  </PropertyGroup>
    9696  <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, Culture=neutral, PublicKeyToken=17b3b1f090c3ea48, processorArchitecture=MSIL">
     98      <HintPath>..\..\bin\Google.ProtocolBuffers-2.4.1.473.dll</HintPath>
    9999      <Private>False</Private>
    100100    </Reference>
     
    250250  -->
    251251  <PropertyGroup>
    252     <PreBuildEvent>set Path=%25Path%25;$(ProjectDir);$(SolutionDir)
     252   <PreBuildEvent Condition=" '$(OS)' == 'Windows_NT' ">set Path=%25Path%25;$(ProjectDir);$(SolutionDir)
    253253set ProjectDir=$(ProjectDir)
    254254set SolutionDir=$(SolutionDir)
     255
    255256call "$(ProjectDir)\Protos\ProcessProtos.cmd"
    256 
    257257call PreBuildEvent.cmd
    258258</PreBuildEvent>
     259<PreBuildEvent Condition=" '$(OS)' != 'Windows_NT' ">
     260export ProjectDir=$(ProjectDir)
     261export SolutionDir=$(SolutionDir)
     262
     263$SolutionDir/PreBuildEvent.sh
     264</PreBuildEvent>
    259265  </PropertyGroup>
    260266</Project>
  • branches/GP-MoveOperators/HeuristicLab.Problems.ExternalEvaluation/3.3/Interfaces/IEvaluationChannel.cs

    r7259 r8660  
    4848    /// <param name="builder">The builder that must match the message type that is to be received.</param>
    4949    /// <returns>The received message.</returns>
    50     IMessage Receive(IBuilder builder);
     50    IMessage Receive(IBuilder builder, ExtensionRegistry extensions);
    5151    /// <summary>
    5252    /// Tells the channel to close down and terminate open connections.
  • branches/GP-MoveOperators/HeuristicLab.Problems.ExternalEvaluation/3.3/Interfaces/IEvaluationServiceClient.cs

    r7259 r8660  
    2121
    2222using System;
     23using Google.ProtocolBuffers;
    2324using HeuristicLab.Core;
    2425
     
    2930    /// </summary>
    3031    /// <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>
    3133    /// <returns>The resulting quality message from the external process.</returns>
    32     QualityMessage Evaluate(SolutionMessage solution);
     34    QualityMessage Evaluate(SolutionMessage solution, ExtensionRegistry qualityExtensions);
    3335    /// <summary>
    3436    /// Evaluates a given solution in a non-blocking manner.
    3537    /// </summary>
    3638    /// <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>
    3740    /// <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);
    3942  }
    4043}
  • branches/GP-MoveOperators/HeuristicLab.Problems.ExternalEvaluation/3.3/Plugin.cs.frame

    r7259 r8660  
    2323
    2424namespace HeuristicLab.Problems.ExternalEvaluation {
    25   [Plugin("HeuristicLab.Problems.ExternalEvaluation", "3.3.6.$WCREV$")]
     25  [Plugin("HeuristicLab.Problems.ExternalEvaluation", "3.3.7.$WCREV$")]
    2626  [PluginFile("HeuristicLab.Problems.ExternalEvaluation-3.3.dll", PluginFileType.Assembly)]
    2727  [PluginDependency("HeuristicLab.Analysis", "3.3")]
     
    3636  [PluginDependency("HeuristicLab.Parameters", "3.3")]
    3737  [PluginDependency("HeuristicLab.Persistence", "3.3")]
    38   [PluginDependency("HeuristicLab.ProtobufCS", "0.9.1")]
     38  [PluginDependency("HeuristicLab.ProtobufCS", "2.4.1.473")]
    3939  public class HeuristicLabProblemsExternalEvaluationPlugin : PluginBase {
    4040  }
  • branches/GP-MoveOperators/HeuristicLab.Problems.ExternalEvaluation/3.3/Properties/AssemblyInfo.cs.frame

    r7259 r8660  
    3434// [assembly: AssemblyVersion("1.0.*")]
    3535[assembly: AssemblyVersion("3.3.0.0")]
    36 [assembly: AssemblyFileVersion("3.3.6.$WCREV$")]
     36[assembly: AssemblyFileVersion("3.3.7.$WCREV$")]
  • branches/GP-MoveOperators/HeuristicLab.Problems.ExternalEvaluation/3.3/Protos/ExternalEvaluationMessages.proto

    r3881 r8660  
    6767  required int32 solutionId = 1;
    6868  required double quality = 2;
     69
     70  extensions 1000 to max;
    6971}
    7072 
  • branches/GP-MoveOperators/HeuristicLab.Problems.ExternalEvaluation/3.3/Protos/ProcessProtos.cmd

    r3859 r8660  
    1 cd "%ProjectDir%"Protos
    2 
    3 for %%i in (*.proto) do (
    4   "%SolutionDir%"protoc -otmp %%i
    5   "%SolutionDir%"ProtoGen tmp
    6   del tmp)
     1for %%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.