Free cookie consent management tool by TermsFeed Policy Generator

Ignore:
Timestamp:
10/16/14 03:57:49 (10 years ago)
Author:
swagner
Message:

#2205: Worked on optimization networks

File:
1 edited

Legend:

Unmodified
Added
Removed
  • branches/OptimizationNetworks/HeuristicLab.Optimization.Networks/3.3/AlgorithmServiceNode.cs

    r11465 r11468  
    9393    }
    9494
    95     protected virtual void Execute(ServiceParameterCollection parameters) {
     95    protected virtual void Execute(ServiceParameterCollection parameters, CancellationToken token) {
    9696      if (Template == null) throw new InvalidOperationException("Template is null");
    9797
     
    120120      algorithm.Stopped += Algorithm_Stopped;
    121121      algorithm.Start();
    122       waitHandles[algorithm].WaitOne();
    123 
    124       // retrieve results
    125       foreach (var p in parameters.Where(x => x.Type == ServiceParameterType.Output)) {
    126         IResult result = null;
    127         if (algorithm.Results.TryGetValue(p.Name, out result)) {
    128           p.Value = result.Value;
    129         }
    130       }
    131 
    132       lock (locker) {
    133         waitHandles[algorithm].Dispose();
    134         waitHandles.Remove(algorithm);
    135         Runs.Add(algorithm.Runs.ToArray()[0]);
     122      if (WaitHandle.WaitAny(new WaitHandle[] { waitHandles[algorithm], token.WaitHandle }) == 1) {
     123        // retrieve results
     124        foreach (var p in parameters.Where(x => x.Type == ServiceParameterType.Output)) {
     125          IResult result = null;
     126          if (algorithm.Results.TryGetValue(p.Name, out result)) {
     127            p.Value = result.Value;
     128          }
     129        }
     130
     131        lock (locker) {
     132          waitHandles[algorithm].Dispose();
     133          waitHandles.Remove(algorithm);
     134          Runs.Add(algorithm.Runs.ToArray()[0]);
     135        }
     136      } else {  // cancellation
     137        algorithm.Stop();
     138        lock (locker) {
     139          waitHandles[algorithm].Dispose();
     140          waitHandles.Remove(algorithm);
     141        }
    136142      }
    137143    }
     
    191197      IServicePort s = port as IServicePort;
    192198      if (s != null) {
    193         s.Called += ServicePort_Called;
     199        s.ProcessParameters += ServicePort_ProcessParameters;
    194200      }
    195201    }
     
    203209      IServicePort s = port as IServicePort;
    204210      if (s != null) {
    205         s.Called -= ServicePort_Called;
     211        s.ProcessParameters -= ServicePort_ProcessParameters;
    206212      }
    207213    }
     
    212218      UpdateParameter((IInputPort)sender);
    213219    }
    214     private void ServicePort_Called(object sender, EventArgs<ServiceParameterCollection> e) {
    215       Execute(e.Value);
     220    private void ServicePort_ProcessParameters(object sender, EventArgs<ServiceParameterCollection, CancellationToken> e) {
     221      Execute(e.Value, e.Value2);
    216222    }
    217223    #endregion
Note: See TracChangeset for help on using the changeset viewer.