Ask Your Question

Revision history [back]

click to hide/show revision 1
initial version

Here is an example, in which we use x[0], x[1], x[2] for a, b, c, and x[-1] for the (absolute) bound for errors.

milp = MixedIntegerLinearProgram(maximization=False) # we do minimization

x = milp.new_variable(real=True)
milp.set_min(x[0],0)
milp.set_min(x[1],0)
milp.set_min(x[2],0)
milp.set_max(x[0],1)
milp.set_max(x[1],1)
milp.set_max(x[2],1)

eq1 = 0.3*x[0] + 0.1*x[1] + 0.2*x[2] - 10
milp.add_constraint( eq1 <= x[-1] )
milp.add_constraint( eq1 >= -x[-1] )

eq2 = 0.1*x[0] + 0.2*x[1] + 0.3*x[2] - 11
milp.add_constraint( eq2 <= x[-1] )
milp.add_constraint( eq2 >= -x[-1] )

milp.set_objective(x[-1])    # minimize the error bound

milp.solve()
print( milp.get_values(x) )

The code produces the following result: {0: 1.0, 1: 1.0, 2: 1.0, -1: 10.4}, that is $a=b=c=1.0$, and the maximum error of $10.4$.