anylogictable-functions

AnyLogic: Is it possibile to multiple/sum/subtract/...respectively link two TableFunctions in AnyLogic?


I have two TableFunctions f1: arguments1 -> values1 and f2: arguments2 -> values2 given via their arguments[] and values[] arrays. I want to link them to a new TableFunction g, so that: The arguments of g shall be: arguments1 + 0.5 * arguments2 The values of g shall be: min{values1, values2}.

Is there any way to implement it via code? I tried to do that, however, I always have the problem that when forming a cartesian product, duplicates will arise.


Solution

  • try this, assuming you have 2 table functions of the same size called t2 and t4, and your new table function is newT:

    You can do this on the startup of your simulation (note that i arbitrarily chose linear interpolation to the nearest value if out of range)

    double [] values = new double[t2.getValues().length];
    double [] arguments = new double[t2.getValues().length];
    
    for(int i = 0; i<values.length;i++){
        arguments[i]=t2.getArguments()[i]+0.5*t4.getArguments()[i];
        values[i]=min(t2.getValues()[i],t4.getValues()[i]);
    }
    newT=new TableFunction( arguments, values, 
           TableFunction.INTERPOLATION_LINEAR, 1, TableFunction.OUTOFRANGE_NEAREST,
           0.0 );