Free cookie consent management tool by TermsFeed Policy Generator

source: branches/3.1/sources/HeuristicLab.SimOpt/SimOptParameterPacker.cs @ 583

Last change on this file since 583 was 583, checked in by abeham, 16 years ago

Adding communication framework to branch 3.1 (ticket #278)

File size: 1.2 KB
Line 
1using System;
2using System.Collections.Generic;
3using System.Linq;
4using System.Text;
5using System.Xml;
6using HeuristicLab.Core;
7using HeuristicLab.Data;
8
9namespace HeuristicLab.SimOpt {
10  public class SimOptParameterPacker : OperatorBase {
11    public override string Description {
12      get { return @"Updates a ConstrainedItemList with the variables in the scope and removes them afterwards."; }
13    }
14
15    public SimOptParameterPacker()
16      : base() {
17      AddVariableInfo(new VariableInfo("Items", "The ConstrainedItemList to be updated", typeof(ConstrainedItemList), VariableKind.In | VariableKind.Out));
18    }
19
20    public override IOperation Apply(IScope scope) {
21      ConstrainedItemList cil = GetVariableValue<ConstrainedItemList>("Items", scope, false);
22      for (int i = 0; i < cil.Count; i++) {
23        IVariable var = scope.GetVariable(((Variable)cil[i]).Name);
24        if (var == null) throw new InvalidOperationException("ERROR in SimOptParameterPacker: Cannot find variable " + ((Variable)cil[i]).Name + " in scope");
25        else {
26          ((Variable)cil[i]).Value = (IItem)var.Value.Clone();
27          scope.RemoveVariable(var.Name);
28        }
29      }
30      return null;
31    }
32  }
33}
Note: See TracBrowser for help on using the repository browser.