sasoptpy.actions.switch_conditions¶
-
switch_conditions
(**args)[source]¶ Creates several if-else blocks by using the specified arguments
- Parameters
- args :
Several arguments can be passed to the function
Each case should follow a condition. You can use
sasoptpy.Constraint
objects as conditions, and Python functions for the cases.
Examples
>>> with so.Workspace('w') as w: >>> x = so.Variable(name='x') >>> p = so.Parameter(name='p') >>> x.set_value(2.5) >>> def func1(): >>> p.set_value(1) >>> def func2(): >>> p.set_value(2) >>> def func3(): >>> p.set_value(3) >>> def func4(): >>> p.set_value(0) >>> switch_conditions(x < 1, func1, x < 2, func2, x < 3, func3, func4) >>> print(to.optmodel(w)) proc optmodel; var x; num p; x = 2.5; if x < 1 then do; p = 1; end; else if x < 2 then do; p = 2; end; else if x < 3 then do; p = 3; end; else do; p = 0; end; quit;