[AMPL 24889] Allocation and scheduling model using binary decision variable

Good afternoon,

I need your help to solve the following error please:
I am going to explain a part of the problem first :

  • M : set of contracts to be allocated to each project
  • P : set of n projects
  • T : set of l time periods
  • RType : set of resources type (engineer, architect, manager)
  • S : set of project sizes (SP, MP, LP, XLP) small, medium, large and major.
  • set PS within {P,S}; # Set of project-size combinations

We would like to allocate the best fit of contract to a project to minimize both the cost and duration.

  • X(i,j) is binary variable = 1 if contract i is allocated to project j and 0 otherwise.
  • Act(j,t) is a binary variable = 1 if the project j is executing during the period t and 0 otherwise
    Data :
  • Av(r, t) is a parameter that indicates the number of resource type r available during the period t
  • RDemand : demand of resource type r according to the project size s and the contract i (The demand depends on the size of the project and the contract that will be selected)

The second part of the model is a scheduling part to make sure that the human resources are available to work on the project using the selected contract else the model should select another contract.

The requirement constraint

My problem is how to express that the contract is the index i when X(i,j)=1

subject to ReqConstraint {r in RType, t in T}:

sum {(j,s) in PS, j in P, i in M : X[i,j]=1} RDemand[s,i,r]*Act[j,t]<=Av[r,t];

This statement does not work!

Thank’s in advance!!!

Writing “sum {(j,s) in PS, j in P, . . .” will give you an error, because “(j,s) in PS” defines j, and then “j in P” defines j again. Perhaps you want them in the opposite order:

sum {j in P, (j,s) in PS, ...

Here “(j,s) in PS” is a “slice” through PS for a fixed j, as explained in Section 6.2 Subsets and slices of ordered pairs in the AMPL book.

Also you cannot put a condition like “X[i,j]=1” inside an indexing expression. The members of the indexing set need to be known before the problem is sent to the solver; but the optimal value of X is only known after the solver is called. Instead, will the following work for you?

subject to ReqConstraint {r in RType, t in T}:
   sum {j in P, (j,s) in PS, i in M} RDemand[s,i,r] * X[i,j] * Act[j,t] <= Av[r,t];

The presence of X[i,j] * Act[j,t] makes this a quadratic constraint, but any of the popular solvers will reformulate the constraint expression so that the product of binary variables is linearized. Alternatively you can formulate the linearization yourself as described in How to linearize the product of two binary variables.

Hi Robert,

Thank you so much!
This one works perfectly : subject to ReqConstraint {r in RType, t in T}: sum {j in P, (j,s) in PS, i in M} RDemand[s,i,r] * X[i,j] * Act[j,t] <= Av[r,t];

Now I understand better the problem.
I am new to AMPL but I am trying to learn it step by step.

Thank’s again!