• 1 reply
  • Latest Post - ‏2013-02-28T18:44:58Z by GGR
554 Posts

Pinned topic Using the assignments from IloPack as precedence constraints

‏2013-02-26T17:57:39Z |

I'm trying to work with a bunch of interval variables Jj and Kk as follows: the jobs Jj are to be packed into batches Kk via

model.add(IloPack(env, batchloads, assignments, sj, batchesUsed));    
// batchloads is bounded by capacity = 10 


int k=1; k<nk; k++) 
{ model.add(IloEndAtStart(env, K[k-1], K[k], 0));                   
// batches are pre-sequenced 
} model.add(IloStartOf(K[0]==0));

and the packing part works just fine, but now I'd like to ensure that a job assigned to batch k starts at the same time as k; something like

model.add(IloIfThen(env,(assignments[j]==k), (IloStartOf(J[j])==IloStartOf(K[k]))));

But this runs endlessly, with the implication failing every time. I've tried a couple of other approaches, too (code is "paraphrased"):

model.add((assignments[j]==k) <= (IloStartOf(J[j])==IloStartOf(K[k])))); 
// since a job could align with multiple (empty) batches, at least one must align with the right one IloOr bbjk(env); bbjk.add((assignments[j]==k) == (IloStartOf(J[j])==IloStartOf(K[k]))); ... model.add(bbjk); 
// later (outside of the loop above)


IloIntExpr batchStart(env); 


int k=0; k<nk; k++) batchStart += ((assignments[j]==k) * IloStartOf(K[k])); model.add( IloStartOf(J[j]) == batchStart );

... but nothing works. Something like

model.add( IloStartAtStart(J[j], K[assignments[j]], 0) )

would obviously be most comfortable, but nested indexing doesn't work, and IloElement doesn't work with IntervalVars either.

What's the best way to implement this? Thanks!
Updated on 2013-02-28T18:44:58Z at 2013-02-28T18:44:58Z by GGR
  • GGR
    63 Posts

    Re: Using the assignments from IloPack as precedence constraints


    As an hint, if you start working with an interval variable based model, you will find in the language for interval variables all your needs for grouping, synchronizing and stating cumul constraint in the interval based language.

    In your case, a tasks is executed inside a batch. That is a alternative of batches. Batches spans the activities it executes. Batches and activities are start point synchronize: that is a start at start precedence. There is a maximum number of activity per batches

    Here a possible sketch for your model

    IloInt nb = ...; \\ number of batches IloInt na = ...; \\ number of activities IloInt c = ...; \\ maximum number of activity per batches IloIntervalVarArray batches(env, nb); \\ the array of batch variables (optional) of \\ min size the min size of an activity 
    for(IlcInt i = 0; i < nb-1; ++i) 
    // symmetry breaking by a logico temporal chain model.add(IloStartBeforeStart(env, batches[i], batches[i+1])) model.add(IloPresenceOf(batches[i]) >= IloPresenceOf(batches[i+1]) 
    } IloIntervalVarArray activities(env, na); \\ the array of activity variables IloIntervalVarArray operations(env, na*nb); \\ the array of activity per batches \\ variables (optional) 
    for(IlcInt i = 0; i < na; ++i) 
    { IloIntervalVarArray tmp(env, nb); 
    for(IlcInt j = 0; j < nb; ++j) 
    { tmp[j] = operations[i][j]; 
    } model.add(IloAlternative(env, activities[i], tmp); 
    for(IlcInt j = 0; j < nb; ++j) 
    { IloIntervalVarArray tmp(env, na); IloIntervalVarArray stmp(env, na); 
    for(IlcInt i = 0; i < na; ++i) 
    { model.add(IloStartAtStart(batches[j], operations[i][j])); tmp[i] = operations[i][j]; stmp[i] = IloPresenceOf(env, operations[i][j]); 
    } model.add(IloSpan(env, batches[j], tmp); model.add(IloSum(stmp) <= c); \\ the cumulative constraint 

    Hope that helps