Loading [MathJax]/jax/output/CommonHTML/jax.js

Tuesday, June 27, 2017

Who needs Cplex or Gurobi: solving LPs using LU

The strange notion that linear programming problems can be solved simply by applying an LU decomposition (not as part of the Simplex method but just LU) seems to take hold. The original idea is from (1) but now we also can use LU as a solver for “Fuzzy Linear Fractional Programming Problems” (2).


image 

I agree with the abstract: the proposed approach is simple.

References
  1. S.M.Chincole, A.P.Bhadane, LU Factorization Method To Solve Linear Programming Problem, International Journal of Emerging Technology and Advanced Engineering ,Volume 4, Issue 4, 176-180, http://www.ijetae.com/files/Volume4Issue4/IJETAE_0414_31.pdf. Warning: this method does not work except in some very special cases (e.g. all constraints binding in the optimal solution).
  2. S. Muruganandam and P. Ambika,  Solving Fuzzy Linear Fractional Programming Problem using LU Decomposition Method, Annals of Pure and Applied Mathematics, Vol. 13, No 1., 2017, pp 89-97.
  3. Solving LP by LU??, http://yetanothermathprogrammingconsultant.blogspot.com/2017/01/solving-lp-by-lu.html

Wednesday, June 21, 2017

Minimizing the k-th largest x

Minimizing the largest xi is an easy exercise in LP modeling:
minzzxi
This is sometimes called MINIMAX.

What about minimizing the kth largest value? Here is one possible MIP formulation:

minzzxiδiMiδi=k1δi{0,1}

I.e., we have k1 exceptions on the constraint zxi. The objective will make sure the exceptions are the largest xi.  We should think long and hard about making the big-M’s as small as possible. If you have no clue about proper bounds on xi one could use indicator constraints.

Interestingly, minimizing the sum of the k largest can be modeled as a pure LP (1) :

minivi+kqvixiqvi0q free 

You almost would think there is an LP formulation for minimizing the kth largest value. I don't see it however.
References
  1. Comment by Michael Grant in http://orinanobworld.blogspot.se/2015/08/optimizingpartoftheobjectivefunction-ii.html.

Wednesday, June 14, 2017

Modeling production runs with length exactly three

In (1) the question was posed how to model production runs that have an exact length. Although the question was asked in terms of integer variables, this is much easier to deal with when we have binary variables. Let’s introduce a binary variable:

xt={1when the unit x is turned on in period t0otherwise

The question was formulated as an implication:

xt=1xt+1=xt+2=1

This implication is not 100% correct: it would turn on x forever. But we understand what the poster meant, if a unit is turned on, it should stay on for exactly three periods.

image

This condition can be more correctly stated as the implication:

xt1=0 and xt=1xt+1=xt+2=1 and xt+3=0

We can make linear inequalities out of this as follows:

xt+1xtxt1xt+2xtxt11xt+3xtxt1

If we want to model the condition “a unit should stay on for at least three periods”, we can drop the last constraint and just keep:

xt+1xtxt1xt+2xtxt1


References
  1. https://stackoverflow.com/questions/44496473/block-of-consecutive-variables-to-have-same-value-in-mixed-integer-linear-progra

Friday, June 9, 2017

A Staffing Problem

In (1) a "simple problem" is stated (problems are rarely as simple as they seem):

For the next 18 weeks there is some data about demand for staffing resources:

image

Actually we don’t need the data for the individual projects: just the totals. It is noted that the maximum number of “bodies” we need is 52 (in week 3).

We start with 48 temps available in the first period. We can let a temp staffer go and we can hire new ones. However when hiring a staffer it will cost 10 days (2 weeks) to train this person. During training a staffer is not productive.  We can also keep a staffer idling for a few periods.

To make a difference between idling and training, as shown here:

image

I will assume that hiring + training is slightly more expensive than keeping someone idle. I think it makes sense to assign some cost to the hiring and training process. This property was not in the original post but I think I have convinced myself that this is actually a reasonable assumption.

To model this I introduce two sets of binary variables:

ri,t={1if a staffer i is available for training or work during period t0otherwisehi,t={1if a staffer i is hired at the beginning of period t0otherwise

We can link hi,t and ri,t as follows:

hi,tri,tri,t1

This implements the implication:

ri,t1=0 and ri,t=1hi,t=1

that is: if we change r from 0 to 1, we have a new hire. We will add a (small) cost to a hire to the objective so we don’t need to add constraint to enforce the other way around:

ri,t1=1 or ri,t=0hi,t=0

There is one wrinkle here: we need to make sure that the 48 staffers already hired before can work in the first period without being considered to be hired. We can explicitly model this:

hi,t{ri,tri,t1if t>1ri,tif t=1 and i>48

Actually in the GAMS model below I approached this slightly differently, but with the same net result.

The main equation in the model is to make sure we have enough staffing in each period t. This can be modeled as:

i(ri,thi,thi,t1)demandt

The complete model can look like:

image

Notes:

  • riniti,t is used to indicate initial staffing when we start period 1. It is sparse: it assumes the value 1 only if i=1 and t48.
  • This allows us to write equation EHire as one single, clean equation.
  • Note that GAMS will assume a variable is zero outside its domain:  ri,t1 is zero when t=1.
  • I used the maximum demand (52 in week 3) to dimension the the problem: set i has 52 members.
  • The model does not decide which workers are idle. We can see in each period how many workers we have and how many are in training. The remaining ones are working or sitting idle.
  • We reuse resource numbers i. In the results below worker i=21 is likely to be two different persons.

The results look like:

image

 image

Here a green cell with code=2 means hired and working (or idle, but not in training). A red cell with code=1 means in training.  The row “total” is the number of staffers (either working, idling or training). The row “Work” indicates the number of workers available (not in training). We are overshooting demand a bit: some workers are idling.

A picture is always a good idea, so here we see demand vs. staffing available for work.

image

We see two place where we increase the workforce: we hire in week 1 to handle demand in week 3, and we hire again in week 7 to deal with demand in week 9.

References

Wednesday, June 7, 2017

Minimum down- and up-time

In machine scheduling models we sometimes want to impose minimum up-time and minimum down-time restrictions. E.g., from (1):

My question is how do I add in additional constraints that if the factory switches off then its needs to stay off for 3 months, and if it switches back on then it needs to stay on for 4 months?

One possible solution is the following. Let us define our binary decision variable by

xi,t={1if factory i is operating in month t0otherwise
Method 1

We really want to forbid short run patterns such as 010 (i.e. off-on-off), 0110, 01110 and 101, 1001. Forbidding patterns 010, 0110, 01110 will ensure a factory is up at least 4 consecutive periods. By not allowing 101,1001 we really make sure that a down time period is at least three months. We can model these restrictions in a linear fashion as follows (2):

Forbid 010 xi,t+xi,t+1xi,t+20
Forbid 0110 xi,t+xi,t+1+xi,t+2xi,t+31
Forbid 01110 xi,t+xi,t+1+xi,t+2+xi,t+3xi,t+42
Forbid 101 xi,txi,t+1+xi,t+21
Forbid 1001 xi,txi,t+1xi,t+2+xi,t+31
Method 2

A different approach is as follows. First define binary variables:

δoni,t={1if factory i is turned on in month t0otherwiseδoffi,t={1if factory i is turned off in month t0otherwise

Mathematically we write this as:

δoni,t=(1xi,t1)xi,tδoffi,t=xi,t1(1xi,t)

We can linearize these non-linear equations by:

δoni,t1xi,t1δoni,txi,tδoni,txi,txi,t1δoffi,txi,t1δoffi,t1xi,tδoffi,txi,t1xi,t

With these variables we can implement the implications:

δoni,t=1xi,t+xi,t+1+xi,t+2+xi,t+3=4δoffi,t=1xi,t+xi,t+1+xi,t+2=0

This can be linearized as:

xi,t+1+xi,t+2+xi,t+33δoni,txi,t+1+xi,t+22(1δoffi,t)

Note that I dropped xi,t in both inequalities. These are already known from the definition of δoni,t and δoffi,t.

In the comments it is mentioned by Rob Pratt that we can strengthen this a bit (the math does not look very good in a comment, so I repeat it here):

xi,t+1δoni,txi,t+2δoni,txi,t+3δoni,txi,t+11δoffi,txi,t+21δoffi,t

References
  1. How do I add a constraint to keep a factory switched on or off for a certain period of time in PuLP? https://stackoverflow.com/questions/44281389/how-do-i-add-a-constraint-to-keep-a-factory-switched-on-or-off-for-a-certain-per/44293592
  2. Integer cuts, http://yetanothermathprogrammingconsultant.blogspot.com/2011/10/integer-cuts.html