experiments.sumofproducts

Module summary

Performs the sum-of-products linearize/solve exercise.

(In the implementation details below, click on class/function names for additional documentation and links to the source code.)

❖❖❖

Implements functions (outside the classes above):

gen_instance(n[, M, jmax, Cmax])

Generates an instance.

make_MIP(I, c)

Makes a MIP model for the problem, with Gurobi.

❖❖❖

Implementation details

❖❖❖

Functions

experiments.sumofproducts.gen_instance(n, M=3, jmax=3, Cmax=10.0)[source]

Generates an instance.

Parameters
  • n (int) – number of variables

  • M (int) – number of terms in the sum

  • jmax (int) – number of vars in a term, at most

  • Cmax (float) – cost coefficient will be -Cmax..Cmax

Returns

list of lists of indices c (list): list of costs (per sum term)

Return type

I (list)

experiments.sumofproducts.make_MIP(I, c)[source]

Makes a MIP model for the problem, with Gurobi.

Parameters
  • I (list) – list of indices per sum term.

  • c (list) – corresponding cost coefficients.

Returns

the resulting model and variables.

Return type

m, x, y