Discussion:
[gecode-users] dynamic cost calculation
a***@orange.fr
2018-04-09 16:53:10 UTC
Permalink
Hello,

I've a problem solved with gecode where jobs must be assigned to person.
Each (job, person) has it own cost statically given. The implementation
looks like :
// --------------------------------------------------------------
_j(*this, _nb_jobs, 0, _nb_persons - 1)

int _cost[] =
{
9, 2, 7, 8,
6, 4, 3, 7,
5, 8, 1, 8,
7, 6, 9, 4,
};

IntArgs cost(_nb_persons*_nb_jobs, _cost);
distinct(*this, _j);

for (int i = 0 ; i < _nb_jobs ; ++i)
{
C << expr(*this, element(cost_m.col(i), _j[i]));
}
_total_cost = expr(*this, sum(C));
JobBrancher::post(*this, _j);
// --------------------------------------------------------------

The problem is that the _cost must be precomputed. To enable a dynamic
cost computation (and to prepare futher improvement),
i've modified the code this way :

// --------------------------------------------------------------
_cost(*this, _nb_persons, 0, 10) // a IntVarArray
JobBrancher::post(*this, _j, _cost, _nb_jobs, _nb_persons);
// --------------------------------------------------------------

And :
1) compute dynamically the cost in JobBrancher::choice
2) call me_failed(_costs_views[choice._person].eq(home, choice._cost))
In JobBrancher::commit (for job/person affectation)
3) call me_failed(_jobs_views[choice._job].eq(home, choice._person))
In JobBrancher::commit (to compute the _total_cost)

The problem is that solution can be found without having an
assigned cost. This produce a Int::ValOfUnassignedVar as stated
in MPG.

I've tried to set all unassigned cost in JobBrancher::commit
(not only the one corresponding to the choice person/job)
just to make a try but it doesn't work :

// --------------------------------------------------------------
for(int i = 0 ; i < choice._costs.size() ; ++i)
{
const JobChoice::Info & elem = choice._costs[i];
const int p = elem.person;
const int c = elem.cost;

if (! _costs_views[p].assigned())
{
has_failed = me_failed(_costs_views[p].eq(home, c));
if (has_failed)
{
return Gecode::ES_FAILED;
}
}
}

return Gecode::ES_OK;
// --------------------------------------------------------------

The first affectation seems to works. After that, i see under gist
that the first branch is infinitely explored without any change.
Can someone explain me what i'm doing wrong and how to correct it ?

Thanks
Philippe.
aqwzsxaqwzsx
2018-04-17 21:56:08 UTC
Permalink
Hi,

The mistakes was easy to solve since I have simply forgotten to

retrieve the return value of a me_failed call.

Bye.

Loading...