Neill Clift
2018-03-10 19:36:59 UTC
Hi,
I want to restrict the values of an array to members of a multiset. This is a bit like distinct but can have repeated values.
So for example I want the values of b[0..7] to come from the multiset {5,5,5,4,3,2,1,0}. The bs are essentially a permutation of the multiset
Count seems to be the way to achieve this but I have to add a whole new set of variables (the vs below) that contain the counts of the multiplicities.
I cut out a bunch of stuff thats not relevant to the code below so I hope it still makes sense.
bp.MaxBit is the number of distinct values in the multiset. And bp.Bits[i] is the multiplicity for the multiset value i.
Is this the expected way to do what I am trying to do here?
Thanks.
Neill.
public:
IntVarArray b;
public:
PartialOrderSort(LPTYPER n, BIT_PATTERN &bp, LPTYPER TopIndex) :
b(*this, n, 0, TopIndex)
{
IntVarArgs x(n);
IntVarArgs c((LPTYPER)bp.MaxBit);
for (int i = 0; i < n; i++) {
x[i] = b[i];
}
IntVarArray v(*this, (LPTYPER)bp.MaxBit, 0, n - 1);
for (int i = 0; i < bp.MaxBit; i++) {
c[i] = v[i];
rel(*this, v[i] == (LPTYPER)bp.Bits[i]);
}
count(*this, x, c, IPL_DOM);
Sent from Mail<https://go.microsoft.com/fwlink/?LinkId=550986> for Windows 10
I want to restrict the values of an array to members of a multiset. This is a bit like distinct but can have repeated values.
So for example I want the values of b[0..7] to come from the multiset {5,5,5,4,3,2,1,0}. The bs are essentially a permutation of the multiset
Count seems to be the way to achieve this but I have to add a whole new set of variables (the vs below) that contain the counts of the multiplicities.
I cut out a bunch of stuff thats not relevant to the code below so I hope it still makes sense.
bp.MaxBit is the number of distinct values in the multiset. And bp.Bits[i] is the multiplicity for the multiset value i.
Is this the expected way to do what I am trying to do here?
Thanks.
Neill.
public:
IntVarArray b;
public:
PartialOrderSort(LPTYPER n, BIT_PATTERN &bp, LPTYPER TopIndex) :
b(*this, n, 0, TopIndex)
{
IntVarArgs x(n);
IntVarArgs c((LPTYPER)bp.MaxBit);
for (int i = 0; i < n; i++) {
x[i] = b[i];
}
IntVarArray v(*this, (LPTYPER)bp.MaxBit, 0, n - 1);
for (int i = 0; i < bp.MaxBit; i++) {
c[i] = v[i];
rel(*this, v[i] == (LPTYPER)bp.Bits[i]);
}
count(*this, x, c, IPL_DOM);
Sent from Mail<https://go.microsoft.com/fwlink/?LinkId=550986> for Windows 10