[gecode-users] Sum of IntVarArrays with changing array positions
Mathias Dalheimer
dalheimer at itwm.fhg.de
Wed Oct 12 16:27:04 CEST 2011
-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1
Dear Guido, dear Christian, list,
wow, I'm impressed - usually not even paid support does answer so fast
and so accurate. Thank you very much!
I've implemented Guidos idea, but I still have a problem. My code looks
like this:
I have some member variables (all IntVarArrays), here's the
initialization list:
:_start_times(*this, devices.size(), 0, MINS_PER_DAY)
_movable_load(*this, MINS_PER_DAY, 0, 15000)
_dev0_load(*this, MINS_PER_DAY, 0, 15000)
_dev1_load(*this, MINS_PER_DAY, 0, 15000)
_dev0(*this, devices[0].size(), 0, 15000)
_dev1(*this, devices[1].size(), 0, 15000)
devices is of type std::vector< std::vector >, I copy the
initial device data to _dev0 (and _dev1):
for (size_t i=0; i < devices[0].size(); ++i) {
rel(*this, _dev0[i] == devices[0][i]);
}
Then, I use Guido's recommendation:
for (int j=0; j < _dev0.size(); ++j) {
rel(*this, _dev0_load[j] == element(_dev0, _start_times[0] + j));
}
Please note that I was not able to use the post function - the compiler
complains that the function is not defined, although minimodel.hh is
included. After this step (again the same code for _dev1), I can sum up
the _devX_load IntVarArrays:
for (int i=0; i<_movable_load.size(); ++i) {
rel(*this, _movable_load[i] == _dev0_load[i] + _dev1_load[i]);
}
This works in principle (The _movable_load series is calculated
correctly), but only if the device positions (_start_times) are 0. These
are also the solutions found by Gecode. If I restrict the start times to
something different, i.e.
rel(*this, _start_times[0] == 1);
Gecode will not find any solutions. I'm sure I'm only missing something
simple - any ideas? Thanks again for your time!
Cheers,
- -Mathias
Guido Tack wrote:
> Hi Mathias,
>
> you can express the constraint using element constraints. Say the
> two sequences are x and y, you create two new sequences xx and yy
> (with appropriate length) and then post the following constraints:
>
> for (int i=0; i< m || i > m+x.size())
>>> xx[i]==0)); for (int i=0; i< n || i
>> n+y.size()) >> yy[i]==0));
> I didn't test the code, but I hope you get the idea.
>
> Christian's email just arrived - I think my solution is different in
> that the time series can be variables, which means you can't use
> regular. I understand that correctly from your description?
>
> Cheers, Guido
>
> On 12 Oct 2011, at 10:57, Mathias Dalheimer wrote:
>
>> Hi,
>>
>> I'm having trouble expressing the following constraints: I have two
>> IntVarArrays which contain short timeseries (i.e. consumption
>> values for one hour, while the remaining hours of one day are
>> empty/not constrained). The *position* of the constraints of the
>> consumption can move within the day, this is governed by two
>> IntVars (m, n) (which are my optimization goal, so the cost
>> function is calculated depending on the position variables). The
>> underlying question is where to place the consumption in order to
>> optimize some cost function.
>>
>> Now I have some other constraints that depend on the position m
>> and n of the consumption. I need to sum the timeseries. So, as an
>> example, I have something like this (. denotes no constraint):
>>
>>
>> . . . 1 2 1 2 3 . . . . . . . . . // m=3 . . . . . . . 2 4 5 6 5
>> . . . . . // n=8
>>
>> Now my question: How do I encode a constraint that depends on the
>> sum of these two IntVarArrays while m and n (the position) can
>> change?
>>
>> So, in the previous example, this would be:
>>
>> . . . 1 2 1 2 3 . . . . . . . . . // m=3 . . . . . . . 2 4 5 6 5
>> . . . . . // n=8 . . . 1 2 1 2 5 4 5 6 5 . . . . . // sum
>>
>> In another example with different m and n:
>>
>> 1 2 1 2 3 . . . . . . . . . . . . // m=0 . . . . . . . 2 4 5 6 5
>> . . . . . // n=8 1 2 1 2 3 . . 2 4 5 6 5 . . . . . // sum
>>
>> Different m's and n's are being evaluated and an optimal set of m
>> and n is the result of the optimization.
>>
>> Thanks for any pointers, -Mathias
>>
>> _______________________________________________ Gecode users
>> mailing list users at gecode.org
>> https://www.gecode.org/mailman/listinfo/gecode-users
-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.4.11 (Darwin)
Comment: Using GnuPG with Mozilla - http://enigmail.mozdev.org/
iEYEARECAAYFAk6VtB8ACgkQ/Rbs3OTm+ySf6wCg0c/kkj/TI98JdoP2jpKc6bSr
a/MAnjWOkQrhcJxmgdltGcpA5v+xYS+y
=Wboo
-----END PGP SIGNATURE-----
More information about the users
mailing list