Free cookie consent management tool by TermsFeed Policy Generator

Ignore:
Timestamp:
07/17/11 22:51:11 (13 years ago)
Author:
abeham
Message:

#1541

  • updated to latest trunk version
Location:
branches/QAPAlgorithms
Files:
10 edited

Legend:

Unmodified
Added
Removed
  • branches/QAPAlgorithms

  • branches/QAPAlgorithms/HeuristicLab.Problems.ExternalEvaluation/3.3/CachedExternalEvaluator.cs

    r6189 r6569  
    2020#endregion
    2121
    22 
    2322using System.Threading;
    2423using HeuristicLab.Common;
     
    2726using HeuristicLab.Parameters;
    2827using HeuristicLab.Persistence.Default.CompositeSerializers.Storable;
     28
    2929namespace HeuristicLab.Problems.ExternalEvaluation {
    3030
  • branches/QAPAlgorithms/HeuristicLab.Problems.ExternalEvaluation/3.3/Drivers/EvaluationProcessChannel.cs

    r5445 r6569  
    3333  public class EvaluationProcessChannel : EvaluationChannel {
    3434
     35    #region Fields & Properties
    3536    private Process process;
    3637    [Storable]
     
    4041      set {
    4142        if (IsInitialized) throw new InvalidOperationException(Name + ": Cannot change the executable path as the process has already been started.");
    42         string oldExecutable = executable;
     43        if (value == executable) return;
    4344        executable = value;
    44         if (!oldExecutable.Equals(executable)) OnExecutableChanged();
     45        UpdateName();
     46        OnExecutableChanged();
    4547      }
    4648    }
     
    5153      set {
    5254        if (IsInitialized) throw new InvalidOperationException(Name + ": Cannot change the arguments as the process has already been started.");
    53         string oldArguments = arguments;
     55        if (value == arguments) return;
    5456        arguments = value;
    55         if (!oldArguments.Equals(arguments)) OnArgumentsChanged();
     57        UpdateName();
     58        OnArgumentsChanged();
    5659      }
    5760    }
    5861    private EvaluationStreamChannel streamingChannel;
     62    #endregion
    5963
     64    #region Construction & Cloning
    6065    [StorableConstructor]
    6166    protected EvaluationProcessChannel(bool deserializing) : base(deserializing) { }
     
    6469      executable = original.executable;
    6570      arguments = original.arguments;
     71      UpdateName();
    6672    }
    6773    public override IDeepCloneable Clone(Cloner cloner) {
     
    7480      this.executable = executable;
    7581      this.arguments = arguments;
     82      UpdateName();
    7683    }
     84    [StorableHook(HookType.AfterDeserialization)]
     85    private void AfterDeserialization() {
     86      UpdateName();
     87    }
     88    #endregion
    7789
    7890    #region IExternalEvaluationChannel Members
    79 
    8091    public override void Open() {
    8192      if (!String.IsNullOrEmpty(executable.Trim())) {
     
    175186    }
    176187    #endregion
     188
     189    #region Auxiliary Methods
     190    private void UpdateName() {
     191      name = string.Format("ProcessChannel {0} {1}", Path.GetFileNameWithoutExtension(executable), arguments);
     192      OnNameChanged();
     193    }
     194    #endregion
    177195  }
    178196}
  • branches/QAPAlgorithms/HeuristicLab.Problems.ExternalEvaluation/3.3/Drivers/EvaluationServiceClient.cs

    r5445 r6569  
    3131  [StorableClass]
    3232  public class EvaluationServiceClient : ParameterizedNamedItem, IEvaluationServiceClient {
     33
    3334    public override bool CanChangeName { get { return false; } }
    3435    public override bool CanChangeDescription { get { return false; } }
    3536
     37    #region Parameters
    3638    public IValueParameter<IEvaluationChannel> ChannelParameter {
    3739      get { return (IValueParameter<IEvaluationChannel>)Parameters["Channel"]; }
     
    4446      get { return ChannelParameter.Value; }
    4547    }
     48    #endregion
    4649
    4750
     51    #region Construction & Cloning
    4852    [StorableConstructor]
    4953    protected EvaluationServiceClient(bool deserializing) : base(deserializing) { }
    50     protected EvaluationServiceClient(EvaluationServiceClient original, Cloner cloner) : base(original, cloner) { }
    51     public override IDeepCloneable Clone(Cloner cloner) {
    52       return new EvaluationServiceClient(this, cloner);
     54    protected EvaluationServiceClient(EvaluationServiceClient original, Cloner cloner)
     55      : base(original, cloner) {
     56      RegisterEvents();
    5357    }
    5458    public EvaluationServiceClient()
     
    5660      Parameters.Add(new ValueParameter<IEvaluationChannel>("Channel", "The channel over which to call the remote function."));
    5761      Parameters.Add(new ValueParameter<IntValue>("Retry", "How many times the client should retry obtaining a quality in case there is an exception. Note that it immediately aborts when the channel cannot be opened.", new IntValue(10)));
     62      RegisterEvents();
    5863    }
     64    public override IDeepCloneable Clone(Cloner cloner) {
     65      return new EvaluationServiceClient(this, cloner);
     66    }
     67    [StorableHook(HookType.AfterDeserialization)]
     68    private void AfterDeserialization() {
     69      ChannelParameter_ValueChanged(this, EventArgs.Empty);
     70      RegisterEvents();
     71    }
     72    #endregion
    5973
    6074    #region IEvaluationServiceClient Members
    61 
    6275    public QualityMessage Evaluate(SolutionMessage solution) {
    6376      int tries = 0, maxTries = RetryParameter.Value.Value;
     
    7184          result = (QualityMessage)Channel.Receive(QualityMessage.CreateBuilder());
    7285          success = true;
    73         }
    74         catch (InvalidOperationException) {
     86        } catch (InvalidOperationException) {
    7587          throw;
    76         }
    77         catch {
     88        } catch {
    7889          if (tries >= maxTries)
    7990            throw;
     
    92103          Channel.Send(solution);
    93104          success = true;
    94         }
    95         catch (InvalidOperationException) {
     105        } catch (InvalidOperationException) {
    96106          throw;
    97         }
    98         catch {
     107        } catch {
    99108          if (tries >= maxTries)
    100109            throw;
     
    103112      System.Threading.ThreadPool.QueueUserWorkItem(new System.Threading.WaitCallback(ReceiveAsync), callback);
    104113    }
    105 
    106114    #endregion
    107115
     116    #region Auxiliary Methods
    108117    private void CheckAndOpenChannel() {
    109118      if (Channel == null) throw new InvalidOperationException(Name + ": The channel is not defined.");
     
    111120        try {
    112121          Channel.Open();
    113         }
    114         catch (Exception e) {
     122        } catch (Exception e) {
    115123          throw new InvalidOperationException(Name + ": The channel could not be opened.", e);
    116124        }
     
    122130      try {
    123131        message = (QualityMessage)Channel.Receive(QualityMessage.CreateBuilder());
    124       }
    125       catch { }
     132      } catch { }
    126133      ((Action<QualityMessage>)callback).Invoke(message);
    127134    }
     135
     136    private void RegisterEvents() {
     137      ChannelParameter.ValueChanged += new EventHandler(ChannelParameter_ValueChanged);
     138    }
     139
     140    void ChannelParameter_ValueChanged(object sender, EventArgs e) {
     141      if (ChannelParameter.Value == null)
     142        name = "Empty EvaluationServiceClient";
     143      else
     144        name = String.Format("{0} ServiceClient", ChannelParameter.Value.Name);
     145      OnNameChanged();
     146    }
     147    #endregion
    128148  }
    129149}
  • branches/QAPAlgorithms/HeuristicLab.Problems.ExternalEvaluation/3.3/Drivers/EvaluationTCPChannel.cs

    r5445 r6569  
    3232  [StorableClass]
    3333  public class EvaluationTCPChannel : EvaluationChannel {
     34
    3435    public const int MAX_VARINT32_SIZE = 5;
    3536
     37    #region Fields & Properties
    3638    [Storable]
    3739    private string ipAddress;
     
    3941      get { return ipAddress; }
    4042      set {
    41         bool changed = !ipAddress.Equals(value);
     43        if (value == ipAddress) return;
    4244        ipAddress = value;
    43         if (changed)
    44           OnIpAddressChanged();
     45        UpdateName();
     46        OnIpAddressChanged();
    4547      }
    4648    }
     
    5052      get { return port; }
    5153      set {
    52         bool changed = port != value;
     54        if (value == port) return;
    5355        port = value;
    54         if (changed)
    55           OnPortChanged();
     56        UpdateName();
     57        OnPortChanged();
    5658      }
    5759    }
    5860    private Socket socket;
    59 
     61    #endregion
     62
     63    #region Construction & Cloning
    6064    [StorableConstructor]
    6165    protected EvaluationTCPChannel(bool deserializing) : base(deserializing) { }
     
    6468      ipAddress = original.ipAddress;
    6569      port = original.port;
    66     }
     70      UpdateName();
     71    }
     72
    6773    public override IDeepCloneable Clone(Cloner cloner) {
    6874      return new EvaluationTCPChannel(this, cloner);
     
    7480      this.ipAddress = ip;
    7581      this.port = port;
    76     }
     82      UpdateName();
     83    }
     84    [StorableHook(HookType.AfterDeserialization)]
     85    private void AfterDeserialization() {
     86      UpdateName();
     87    }
     88    #endregion
     89
     90   
    7791
    7892    #region IExternalEvaluationChannel Members
     
    183197    #endregion
    184198
     199    #region Auxiliary Methods
     200    private void UpdateName() {
     201      name = string.Format("TCPChannel {0}:{1}", ipAddress, port);
     202      OnNameChanged();
     203    }
     204    #endregion
     205
    185206    #region Events
    186207    public event EventHandler IpAddressChanged;
  • branches/QAPAlgorithms/HeuristicLab.Problems.ExternalEvaluation/3.3/EvaluationCache.cs

    r6291 r6569  
    2525using System;
    2626using System.Collections.Generic;
     27using System.Globalization;
     28using System.IO;
    2729using System.Linq;
     30using System.Text.RegularExpressions;
    2831using System.Threading;
    2932using HeuristicLab.Common;
     
    3336using HeuristicLab.Parameters;
    3437using HeuristicLab.Persistence.Default.CompositeSerializers.Storable;
    35 using HeuristicLab.Analysis;
    36 using System.IO;
    37 using System.Globalization;
    38 using System.Text.RegularExpressions;
     38
    3939namespace HeuristicLab.Problems.ExternalEvaluation {
    4040
     
    8282
    8383    private HashSet<string> activeEvaluations = new HashSet<string>();
    84     private object cacheLock = new object();   
     84    private object cacheLock = new object();
    8585    #endregion
    8686
     
    126126
    127127    #region Persistence
    128     [Storable(Name="Cache")]
     128    [Storable(Name = "Cache")]
    129129    private IEnumerable<KeyValuePair<string, double>> Cache_Persistence {
    130130      get {
     
    194194      bool lockTaken = false;
    195195      bool waited = false;
    196       try {       
     196      try {
    197197        Monitor.Enter(cacheLock, ref lockTaken);
    198198        while (true) {
  • branches/QAPAlgorithms/HeuristicLab.Problems.ExternalEvaluation/3.3/ExternalEvaluator.cs

    r6189 r6569  
    6060    protected HashSet<IEvaluationServiceClient> activeClients = new HashSet<IEvaluationServiceClient>();
    6161    protected object clientLock = new object();
    62     protected AutoResetEvent clientAvailable = new AutoResetEvent(false);
    6362    #endregion
    6463
     
    109108        client = Clients.CheckedItems.FirstOrDefault(c => !activeClients.Contains(c));
    110109        while (client == null && Clients.Count > 0) {
    111           Monitor.Exit(clientLock);
    112           clientAvailable.WaitOne();
    113           Monitor.Enter(clientLock);
     110          Monitor.Wait(clientLock);
    114111          client = Clients.CheckedItems.FirstOrDefault(c => !activeClients.Contains(c));
    115112        }
     
    122119        lock (clientLock) {
    123120          activeClients.Remove(client);
    124           clientAvailable.Set();
     121          Monitor.PulseAll(clientLock);
    125122        }
    126123      }
  • branches/QAPAlgorithms/HeuristicLab.Problems.ExternalEvaluation/3.3/HeuristicLabProblemsExternalEvaluationPlugin.cs.frame

    r6099 r6569  
    2323
    2424namespace HeuristicLab.Problems.ExternalEvaluation {
    25   [Plugin("HeuristicLab.Problems.ExternalEvaluation", "3.3.4.$WCREV$")]
     25  [Plugin("HeuristicLab.Problems.ExternalEvaluation", "3.3.5.$WCREV$")]
    2626  [PluginFile("HeuristicLab.Problems.ExternalEvaluation-3.3.dll", PluginFileType.Assembly)]
    2727  [PluginDependency("HeuristicLab.Analysis", "3.3")]
  • branches/QAPAlgorithms/HeuristicLab.Problems.ExternalEvaluation/3.3/Interfaces/IEvaluationChannel.cs

    r5445 r6569  
    2424
    2525namespace HeuristicLab.Problems.ExternalEvaluation {
    26   public interface IEvaluationChannel : IItem {
     26  public interface IEvaluationChannel : INamedItem {
    2727    /// <summary>
    2828    /// A flag that describes whether the channel has been initialized or not.
  • branches/QAPAlgorithms/HeuristicLab.Problems.ExternalEvaluation/3.3/Properties/AssemblyInfo.frame

    r6099 r6569  
    3434// [assembly: AssemblyVersion("1.0.*")]
    3535[assembly: AssemblyVersion("3.3.0.0")]
    36 [assembly: AssemblyFileVersion("3.3.4.$WCREV$")]
     36[assembly: AssemblyFileVersion("3.3.5.$WCREV$")]
Note: See TracChangeset for help on using the changeset viewer.