Setting values in functions can be done in a couple of ways. It also depends on whether the variable being set is dependent or not.

Setting independent variables

var x = new Variable<Int32>();

x.SetValues(new[]{1,2,3}); // adds the values 1,2,3 to the variable x
x.Values.Add(1);           // adds 1 to variable x.

Setting values twice will add the values to the variable.

var x = new Variable<Int32>();

x.SetValues(new[]{1,2}); // adds the values 1,2 to the variable x
x.SetValues(new[]{3,4}); // now x contains {1,2,3,4}

Values added to a independent variable need to be unique because the variable might be used as an argument in a function. So the following will cause an exception

var x = new Variable<int>();
x.Values.Add(1);
x.Values.Add(1);

Setting dependent variables
Setting dependent variables is a little more complicated because the arguments of the variable have to be taken into account. I will show three methods all resulting in the following function

x

y

1

10

2

20

3

30

//setup the function
var x = new Variable<Int32>();
var y = new Variable<Int32>();
y.Arguments.Add(x)
//set dependent and independent values one by one
x.SetValues(new[]{1,2,3});        //set independent first.
y.SetValues(new[]{10,20,30});     //set dependent values

You can also set the values in a single call by using variablevalue filters

y.SetValues(new[]{10,20,30},new VariableValueFilter<int>(x,new[]{1,2,3}));

Or you can set the values one by one using the indexer of y.

y[1] = 10;
y[2] = 20;
y[3] = 30;
  • No labels