Free cookie consent management tool by TermsFeed Policy Generator

Changeset 6460


Ignore:
Timestamp:
06/21/11 11:11:38 (13 years ago)
Author:
epitzer
Message:

Correct locking construct for external evaluation on multiple clients and simplify string formatting (#1526)

Location:
trunk/sources
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • trunk/sources/HeuristicLab.Problems.ExternalEvaluation.GP/3.4/ExternalEvaluationSymbolicExpressionTreeStringFormatter.cs

    r5809 r6460  
    2828using HeuristicLab.Problems.DataAnalysis.Symbolic;
    2929using System;
     30using System.Globalization;
    3031
    3132namespace HeuristicLab.Problems.ExternalEvaluation.GP {
     
    5758      StringBuilder strBuilder = new StringBuilder();
    5859      if (Indent) strBuilder.Append(' ', indentLength);
    59       strBuilder.Append("(");
    60       // internal nodes or leaf nodes?
    61       if (node.Subtrees.Count() > 0) {
    62         // symbol on same line as '('
     60      if (node.Subtrees.Count() > 0) { // internal node
     61        strBuilder.Append("(");
    6362        if (node.Symbol is Addition) {
    6463          strBuilder.AppendLine("+");
     
    9897        // each subtree expression on a new line
    9998        // and closing ')' also on new line
    100 
    10199        foreach (var subtree in node.Subtrees) {
    102100          strBuilder.AppendLine(FormatRecursively(subtree, indentLength + 2));
     
    107105        if (node is VariableTreeNode) {
    108106          var varNode = node as VariableTreeNode;
    109           // symbol in the same line with as '(' and ')'
    110           strBuilder.Append(";" + varNode.VariableName + ";" + varNode.Weight.ToString("E4"));
    111           strBuilder.Append(")");
     107          strBuilder.AppendFormat("(* {0} {1})", varNode.VariableName, varNode.Weight.ToString("g17", CultureInfo.InvariantCulture));
    112108        } else if (node is ConstantTreeNode) {
    113109          var constNode = node as ConstantTreeNode;
    114           // symbol in the same line with as '(' and ')'
    115           strBuilder.Append(";" + constNode.Value.ToString("E4"));
    116           strBuilder.Append(")");
     110          strBuilder.Append(constNode.Value.ToString("g17", CultureInfo.InvariantCulture));
    117111        } else {
    118112          throw new NotSupportedException("Formatting of symbol: " + node.Symbol + " not supported for external evaluation.");
  • trunk/sources/HeuristicLab.Problems.ExternalEvaluation/3.3/ExternalEvaluator.cs

    r6189 r6460  
    5959    #region Fields
    6060    protected HashSet<IEvaluationServiceClient> activeClients = new HashSet<IEvaluationServiceClient>();
    61     protected object clientLock = new object();
    62     protected AutoResetEvent clientAvailable = new AutoResetEvent(false);
     61    protected object clientLock = new object();   
    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      }
Note: See TracChangeset for help on using the changeset viewer.