0

I am trying to solve a facility location problem, where I have a set of customers and a set of potential facility locations. Although, the traditional problem is linear, I transformed some constraints and now I have a non-linear problem.

I know there are non-linear optimization packages for python, such as SciPy, but I do not understand how I should iterate over large sets. Can I just use a for-loop to account for the summations? And how do I account for the 'for all i in I' and 'for all j in J' in the constraint as put in the following example?

Objective: Max: Z=∑_i ∑_j (d_i * p_ij * a_ij * y_j)

Subject to: p_ij=(u_ij * a_ij * y_j)/(∑_j (u_ij * a_ij * y_j)) ∀ i ∈ I, j ∈ J

y_j ∈ {0,1} ∀ j ∈ J

where I is the set of customers, and J is the set of potential facility locations. d, a, and u are given. p and y are defined by the model.

Can someone explain me how to use sets in SciPy? Or please send me an example code with this kind of optimization problem so I can see how it is done.

Thank you!

  • have you seen [Google's OR tools](https://developers.google.com/optimization/)? sounds like a problem that's better suited to that. the stated problem looks like a linear/combinatorial problem to me – Sam Mason Jan 21 '19 at 17:46
  • Most or all SciPy solvers are for small problems only. Large scale, sparse solvers can handle much larger problems. Modeling tools can help with things likes sets, summations etc. – Erwin Kalvelagen Jan 22 '19 at 12:49
  • Thanks for your replies. Sam Mason, I never worked with the Google OR tools before. I will have a look at it. @ErwinKalvelagen do you recommend any modeling tools for this problem? – user10945671 Jan 23 '19 at 15:02
  • AMPL and GAMS come to mind. Btw, your math is confusing (j is used in two different ways), but I believe this model can be linearized. – Erwin Kalvelagen Jan 24 '19 at 10:28

1 Answers1

0

I don't think scipy is the way to go here. Instead, I would suggest you use PuLP (link), which provides an interface to essentially translate your algebraic model into the matrices and vectors that the solver can understand. PuLP works with several different solvers. Alternately, you could use Gurobi's or CPLEX's dedicated packages (gurobipy and docplex). In any case, these packages provide functions to do the looping of the type you are asking about.

Also, as @Erwin Kalvelagen pointed out, your model can and should be linearized: Just multiply both sides of your constraint by the denominator.

LarrySnyder610
  • 2,277
  • 12
  • 24
  • Multiplying both sides of the constraint with the denominator will give a term `p_ij * y_j`. Since both are variables, this is non-linear. However, tools like CPLEX have ways to handle this. Given that `y_j` is a binary/boolean variable, you can use logical (aka indicator constraints) to model the constraint without creating products of variables. You can use CPLEX through PuLP. You can use it directly as well. It has a Python interface. – Daniel Junglas May 05 '19 at 06:19
  • Oh, I missed the fact that `p` is a decision variable. – LarrySnyder610 May 05 '19 at 12:21