Free cookie consent management tool by TermsFeed Policy Generator

Changeset 420 for trunk


Ignore:
Timestamp:
08/01/08 21:35:35 (16 years ago)
Author:
gkronber
Message:

worked on #211.

  • Implemented downloading of linked operators from the database in AgentList (to allow view/edit of the whole operator graph)
  • Implemented downloading and patching of linked operators in RunScheduler to prepare the operator-graph for execution (OperatorLink operator can't be executed)

(there is some code duplication because the patching is very similar in AgentList DatabaseOperatorLibrary and RunScheduler. This needs some more work)

Location:
trunk/sources
Files:
3 edited

Legend:

Unmodified
Added
Removed
  • trunk/sources/HeuristicLab.CEDMA.Core/AgentList.cs

    r403 r420  
    3030using System.Runtime.Serialization;
    3131using System.IO;
     32using HeuristicLab.Operators;
    3233
    3334namespace HeuristicLab.CEDMA.Core {
     
    5051        newAgent.Status = a.Status;
    5152        IOperatorGraph opGraph = (IOperatorGraph)PersistenceManager.RestoreFromGZip(a.RawData);
    52         foreach(IOperator op in opGraph.Operators) newAgent.OperatorGraph.AddOperator(op);
     53
     54        DownloadOperators(opGraph, new Dictionary<long, IOperator>());
     55
     56        foreach(IOperator op in opGraph.Operators) {
     57          newAgent.OperatorGraph.AddOperator(op);
     58        }
    5359        newAgent.OperatorGraph.InitialOperator = opGraph.InitialOperator;
    5460        agentList.Add(newAgent);
     
    8086    }
    8187
     88    private void DownloadOperators(IOperatorGraph opGraph, Dictionary<long, IOperator> downloaded) {
     89      foreach(IOperator op in opGraph.Operators) {
     90        DownloadOperators(op, downloaded);
     91      }
     92    }
     93
     94    private void DownloadOperators(IOperator op, Dictionary<long, IOperator> downloaded) {
     95      if(op is OperatorLink) {
     96        OperatorLink link = op as OperatorLink;
     97        if(downloaded.ContainsKey(link.Id)) {
     98          link.Operator = downloaded[link.Id];
     99        } else {
     100          OperatorEntry targetEntry = database.GetOperator(link.Id);
     101          IOperator target = (IOperator)PersistenceManager.RestoreFromGZip(targetEntry.RawData);
     102          downloaded.Add(link.Id, target);
     103          DownloadOperators(target, downloaded);
     104          link.Operator = target;
     105        }
     106      } else if(op is CombinedOperator) {
     107        DownloadOperators(((CombinedOperator)op).OperatorGraph, downloaded);
     108      }
     109    }
     110
    82111    public override IView CreateView() {
    83112      return new AgentListView(this);
  • trunk/sources/HeuristicLab.CEDMA.DB.Interfaces/IDatabase.cs

    r417 r420  
    7373    ICollection<OperatorEntry> GetOperators();
    7474
     75    [OperationContract]
     76    OperatorEntry GetOperator(long agentId);
     77
    7578  }
    7679}
  • trunk/sources/HeuristicLab.CEDMA.Server/RunScheduler.cs

    r419 r420  
    7676        IOperatorGraph opGraph = (IOperatorGraph)PersistenceManager.RestoreFromGZip(entry.RawData);
    7777
    78         foreach(IOperator op in opGraph.Operators) {
    79           PatchLinks(op);
    80         }
     78        PatchLinks(opGraph, new Dictionary<long, IOperator>());
    8179
    8280        AtomicOperation operation = new AtomicOperation(opGraph.InitialOperator, scope);
     
    9997    }
    10098
    101     private void PatchLinks(IOperator op) {
    102       if(op is OperatorLink) {
    103         OperatorLink link = op as OperatorLink;
    104         OperatorEntry targetEntry = database.GetOperator(link.Id);
    105         IOperator target = (IOperator)PersistenceManager.RestoreFromGZip(targetEntry.RawData);
    106         ReplaceOperatorInGraph(link, target);
    107       } else if(op is CombinedOperator) {
    108         CombinedOperator combinedOp = op as CombinedOperator;
    109         foreach(IOperator internalOp in combinedOp.OperatorGraph.Operators) {
    110           PatchLinks(internalOp);
     99    private void PatchLinks(IOperatorGraph opGraph, Dictionary<long, IOperator> patchedOperators) {
     100      Dictionary<IOperator, IOperator> patchDictionary = new Dictionary<IOperator, IOperator>();
     101      foreach(IOperator op in opGraph.Operators) {
     102        IOperator patched = PatchLinks(op, patchedOperators);
     103        patchDictionary.Add(op, patched);
     104      }
     105      foreach(KeyValuePair<IOperator, IOperator> p in patchDictionary) {
     106        IOperator original = p.Key;
     107        IOperator patch = p.Value;
     108        if(original != patch) {
     109          foreach(IOperator subOperator in original.SubOperators) {
     110            patch.AddSubOperator(subOperator);
     111          }
     112          if(opGraph.InitialOperator == original)
     113            opGraph.InitialOperator = patch;
     114          opGraph.RemoveOperator(original.Guid);
     115          opGraph.AddOperator(patch);
    111116        }
    112117      }
    113118    }
    114119
    115     private void ReplaceOperatorInGraph(OperatorLink link, IOperator target) {
    116       throw new NotImplementedException();
     120    private IOperator PatchLinks(IOperator op, Dictionary<long, IOperator> patchedOperators) {
     121      if(op is OperatorLink) {
     122        OperatorLink link = op as OperatorLink;
     123        if(patchedOperators.ContainsKey(link.Id)) {
     124          return patchedOperators[link.Id];
     125        } else {
     126          OperatorEntry targetEntry = database.GetOperator(link.Id);
     127          IOperator target = (IOperator)PersistenceManager.RestoreFromGZip(targetEntry.RawData);
     128          patchedOperators.Add(link.Id, target);
     129          PatchLinks(target, patchedOperators);
     130          return target;
     131        }
     132      } else if(op is CombinedOperator) {
     133        PatchLinks(((CombinedOperator)op).OperatorGraph, patchedOperators);
     134        return op;
     135      }
     136      return op;
    117137    }
    118138
Note: See TracChangeset for help on using the changeset viewer.