-
Notifications
You must be signed in to change notification settings - Fork 76
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #183 from cyderize/feature/cumulatives
Add support for the cumulatives constraint for MiniZinc
- Loading branch information
Showing
13 changed files
with
737 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
include "fzn_cumulatives_decomp.mzn"; | ||
|
||
predicate fzn_cumulatives(array[int] of var int: s, | ||
array[int] of var int: d, | ||
array[int] of var int: r, | ||
array[int] of var int: m, | ||
array[int] of var int: b, | ||
bool: upper, | ||
int: min_m) = | ||
if is_fixed(b) then | ||
% Propagator only supports fixed bounds | ||
gecode_cumulatives(s, d, r, [m_i - min_m | m_i in m], fix(b), upper) | ||
else | ||
fzn_cumulatives_decomp(s, d, r, m, b, upper) | ||
endif; | ||
|
||
predicate gecode_cumulatives(array[int] of var int: s, | ||
array[int] of var int: d, | ||
array[int] of var int: r, | ||
array[int] of var int: m, | ||
array[int] of int: b, | ||
bool: upper); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,84 @@ | ||
/* -*- mode: C++; c-basic-offset: 2; indent-tabs-mode: nil -*- */ | ||
/* | ||
* Main authors: | ||
* Jason Nguyen <[email protected]> | ||
* | ||
* Copyright: | ||
* Jason nguyen, 2023 | ||
* | ||
* This file is part of Gecode, the generic constraint | ||
* development environment: | ||
* http://www.gecode.org | ||
* | ||
* Permission is hereby granted, free of charge, to any person obtaining | ||
* a copy of this software and associated documentation files (the | ||
* "Software"), to deal in the Software without restriction, including | ||
* without limitation the rights to use, copy, modify, merge, publish, | ||
* distribute, sublicense, and/or sell copies of the Software, and to | ||
* permit persons to whom the Software is furnished to do so, subject to | ||
* the following conditions: | ||
* | ||
* The above copyright notice and this permission notice shall be | ||
* included in all copies or substantial portions of the Software. | ||
* | ||
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, | ||
* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF | ||
* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND | ||
* NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE | ||
* LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION | ||
* OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION | ||
* WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. | ||
* | ||
*/ | ||
|
||
#include "test/flatzinc.hh" | ||
|
||
namespace Test { namespace FlatZinc { | ||
|
||
namespace { | ||
/// Helper class to create and register tests | ||
class Create { | ||
public: | ||
|
||
/// Perform creation and registration | ||
Create(void) { | ||
(void) new FlatZincTest("cumulatives_full::1", | ||
R"FZN( | ||
var 1..10: s1 :: output_var; | ||
var 1..10: s2 :: output_var; | ||
var 0..1: m1 :: output_var; | ||
var 0..2: m2 :: output_var; | ||
var 3..4: d1; | ||
var 1..5: d2; | ||
var 2..3: r1; | ||
var 2..5: r2; | ||
var 4..14: e1; | ||
var 2..15: e2; | ||
var 4..15: ms :: output_var; | ||
constraint gecode_int_element(m1, 0, [3, 4], d1); | ||
constraint gecode_int_element(m2, 0, [1, 5], d2); | ||
constraint gecode_int_element(m1, 0, [3, 2], r1); | ||
constraint gecode_int_element(m2, 0, [5, 2], r2); | ||
constraint gecode_cumulatives([s1, s2], [d1, d2], [r1, r2], [m1, m2], [4, 6], true); | ||
constraint int_lin_eq([1, 1, -1], [s1, d1, e1], 0); | ||
constraint int_lin_eq([1, 1, -1], [s2, d2, e2], 0); | ||
constraint array_int_maximum(ms, [e1, e2]); | ||
solve minimize ms; | ||
)FZN", | ||
R"OUT(m1 = 0; | ||
m2 = 1; | ||
ms = 6; | ||
s1 = 1; | ||
s2 = 1; | ||
---------- | ||
========== | ||
)OUT"); | ||
} | ||
}; | ||
|
||
Create c; | ||
} | ||
|
||
}} | ||
|
||
// STATISTICS: test-flatzinc |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,80 @@ | ||
/* -*- mode: C++; c-basic-offset: 2; indent-tabs-mode: nil -*- */ | ||
/* | ||
* Main authors: | ||
* Jason Nguyen <[email protected]> | ||
* | ||
* Copyright: | ||
* Jason nguyen, 2023 | ||
* | ||
* This file is part of Gecode, the generic constraint | ||
* development environment: | ||
* http://www.gecode.org | ||
* | ||
* Permission is hereby granted, free of charge, to any person obtaining | ||
* a copy of this software and associated documentation files (the | ||
* "Software"), to deal in the Software without restriction, including | ||
* without limitation the rights to use, copy, modify, merge, publish, | ||
* distribute, sublicense, and/or sell copies of the Software, and to | ||
* permit persons to whom the Software is furnished to do so, subject to | ||
* the following conditions: | ||
* | ||
* The above copyright notice and this permission notice shall be | ||
* included in all copies or substantial portions of the Software. | ||
* | ||
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, | ||
* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF | ||
* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND | ||
* NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE | ||
* LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION | ||
* OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION | ||
* WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. | ||
* | ||
*/ | ||
|
||
#include "test/flatzinc.hh" | ||
|
||
namespace Test { namespace FlatZinc { | ||
|
||
namespace { | ||
/// Helper class to create and register tests | ||
class Create { | ||
public: | ||
|
||
/// Perform creation and registration | ||
Create(void) { | ||
(void) new FlatZincTest("cumulatives_full::2", | ||
R"FZN( | ||
var 1..10: s1 :: output_var; | ||
var 1..10: s2 :: output_var; | ||
var 3..4: d1; | ||
var 1..5: d2; | ||
var 2..3: r1; | ||
var 2..5: r2; | ||
var 4..14: e1; | ||
var 2..15: e2; | ||
var 4..15: ms :: output_var; | ||
constraint gecode_int_element(s1, -1, [3, 4, 3, 4, 3, 4, 3, 4, 3, 4], d1); | ||
constraint gecode_int_element(s2, -1, [1, 5, 4, 2, 1, 5, 4, 2, 1, 5], d2); | ||
constraint gecode_int_element(s1, -1, [3, 2, 3, 2, 3, 2, 3, 2, 3, 2], r1); | ||
constraint gecode_int_element(s2, -1, [5, 2, 4, 3, 5, 2, 4, 3, 5, 2], r2); | ||
constraint gecode_cumulatives([s1, s2], [d1, d2], [r1, r2], [0, 1], [4, 6], true); | ||
constraint int_lin_eq([1, 1, -1], [s1, d1, e1], 0); | ||
constraint int_lin_eq([1, 1, -1], [s2, d2, e2], 0); | ||
constraint array_int_maximum(ms, [e1, e2]); | ||
solve minimize ms; | ||
)FZN", | ||
R"OUT(ms = 4; | ||
s1 = 1; | ||
s2 = 2; | ||
---------- | ||
========== | ||
)OUT"); | ||
} | ||
}; | ||
|
||
Create c; | ||
} | ||
|
||
}} | ||
|
||
// STATISTICS: test-flatzinc |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,80 @@ | ||
/* -*- mode: C++; c-basic-offset: 2; indent-tabs-mode: nil -*- */ | ||
/* | ||
* Main authors: | ||
* Jason Nguyen <[email protected]> | ||
* | ||
* Copyright: | ||
* Jason nguyen, 2023 | ||
* | ||
* This file is part of Gecode, the generic constraint | ||
* development environment: | ||
* http://www.gecode.org | ||
* | ||
* Permission is hereby granted, free of charge, to any person obtaining | ||
* a copy of this software and associated documentation files (the | ||
* "Software"), to deal in the Software without restriction, including | ||
* without limitation the rights to use, copy, modify, merge, publish, | ||
* distribute, sublicense, and/or sell copies of the Software, and to | ||
* permit persons to whom the Software is furnished to do so, subject to | ||
* the following conditions: | ||
* | ||
* The above copyright notice and this permission notice shall be | ||
* included in all copies or substantial portions of the Software. | ||
* | ||
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, | ||
* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF | ||
* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND | ||
* NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE | ||
* LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION | ||
* OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION | ||
* WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. | ||
* | ||
*/ | ||
|
||
#include "test/flatzinc.hh" | ||
|
||
namespace Test { namespace FlatZinc { | ||
|
||
namespace { | ||
/// Helper class to create and register tests | ||
class Create { | ||
public: | ||
|
||
/// Perform creation and registration | ||
Create(void) { | ||
(void) new FlatZincTest("cumulatives_full::3", | ||
R"FZN( | ||
var 1..10: s1 :: output_var; | ||
var 1..10: s2 :: output_var; | ||
var 0..1: m1 :: output_var; | ||
var 0..2: m2 :: output_var; | ||
var 2..3: r1; | ||
var 2..5: r2; | ||
var 4..14: e1; | ||
var 2..15: e2; | ||
var 4..15: ms :: output_var; | ||
constraint gecode_int_element(m1, 0, [3, 2], r1); | ||
constraint gecode_int_element(m2, 0, [5, 2], r2); | ||
constraint gecode_cumulatives([s1, s2], [3, 5], [r1, r2], [m1, m2], [4, 6], true); | ||
constraint int_lin_eq([1, -1], [s1, e1], -3); | ||
constraint int_lin_eq([1, -1], [s2, e2], -5); | ||
constraint array_int_maximum(ms, [e1, e2]); | ||
solve minimize ms; | ||
)FZN", | ||
R"OUT(m1 = 0; | ||
m2 = 1; | ||
ms = 6; | ||
s1 = 1; | ||
s2 = 1; | ||
---------- | ||
========== | ||
)OUT"); | ||
} | ||
}; | ||
|
||
Create c; | ||
} | ||
|
||
}} | ||
|
||
// STATISTICS: test-flatzinc |
Oops, something went wrong.