# GAMS Support Wiki

### Site Tools

gams:model_a_step_function

# Differences

This shows you the differences between two versions of the page.

 gams:model_a_step_function [2012/10/15 12:39]support make piecewise constant easier to find gams:model_a_step_function [2012/11/12 12:28] (current)support another example for modeling piecewise constant functions (via MIP) Both sides previous revision Previous revision 2012/11/12 12:28 support another example for modeling piecewise constant functions (via MIP)2012/10/15 12:39 support make piecewise constant easier to find2007/12/15 09:02 Franz Nelissen 2007/12/15 06:47 Franz Nelissen created 2012/11/12 12:28 support another example for modeling piecewise constant functions (via MIP)2012/10/15 12:39 support make piecewise constant easier to find2007/12/15 09:02 Franz Nelissen 2007/12/15 06:47 Franz Nelissen created Line 44: Line 44: display b.r, lv.l, rhov.l; display b.r, lv.l, rhov.l; ​ + + Here another example: + <​code>​ + Set p /1*5/; + + * interception points of piecewise constant function + Parameter intercept(p) + / + 1 10 + 2 20 + 3 25 + 4 30 + 5 40 + /; + + * value(p) is value of piecewise constant function for arguments right of intercept(p) + Parameter value(p) + / + 1  10 + 2  20 + 3  10 + 4   0 + 5 -10 + / + + * we model f(x) = value(p) for x such that p <= 4 and intercept(p) <= x <= intercept(p+1) or intercept(5) <= x + * note, that f(x) is not well defined when x equals to an intercept + + Variable x, f; + x.lo = intercept('​1'​)+1;​ + x.up = 50; + + Binary Variable z(p)  '​indicate whether x > intercept(p)';​ + Equation e1(p)  'force z(p) to be 1 if x > intercept(p)';​ + Equation e2(p)  'force x(p) to be >= intercept(p) if z(p) is 1'; + Equation fdef   '​define value of f in terms of z(p)'; + Parameter M1(p) 'bigM values for e1'; + Parameter M2(p) 'bigM values for e2'; + + e1(p).. x =l= intercept(p) + M1(p) * z(p); + e2(p).. x =g= intercept(p) - M2(p) * (1-z(p)); + + M1(p) = x.up - intercept(p);​ + M2(p) = intercept(p) - x.lo; + + fdef.. f =e= sum(p, (value(p) - value(p-1)) * z(p)); + ​ +