Generated on Sun Aug 9 2020 05:34:08 for Gecode by doxygen 1.8.18
eq20.cpp
Go to the documentation of this file.
1 /* -*- mode: C++; c-basic-offset: 2; indent-tabs-mode: nil -*- */
2 /*
3  * Main authors:
4  * Christian Schulte <schulte@gecode.org>
5  *
6  * Copyright:
7  * Christian Schulte, 2001
8  *
9  * This file is part of Gecode, the generic constraint
10  * development environment:
11  * http://www.gecode.org
12  *
13  * Permission is hereby granted, free of charge, to any person obtaining
14  * a copy of this software and associated documentation files (the
15  * "Software"), to deal in the Software without restriction, including
16  * without limitation the rights to use, copy, modify, merge, publish,
17  * distribute, sublicense, and/or sell copies of the Software, and to
18  * permit persons to whom the Software is furnished to do so, subject to
19  * the following conditions:
20  *
21  * The above copyright notice and this permission notice shall be
22  * included in all copies or substantial portions of the Software.
23  *
24  * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
25  * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
26  * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
27  * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
28  * LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
29  * OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
30  * WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
31  *
32  */
33 
34 #include <gecode/driver.hh>
35 #include <gecode/int.hh>
36 
37 using namespace Gecode;
38 
47 class Eq20 : public Script {
48 private:
50  static const int x_n = 7;
52  static const int e_n = 20;
54  IntVarArray x;
55 public:
57  Eq20(const Options& opt)
58  : Script(opt), x(*this,x_n,0,10) {
59  // Coefficients and constants for the equations
60  int eqs[e_n][x_n+1] = {
61  {876370, -16105, 62397, -6704, 43340, 95100, -68610, 58301},
62  {533909, 51637, 67761, 95951, 3834, -96722, 59190, 15280},
63  {915683, 1671, -34121, 10763, 80609, 42532, 93520, -33488},
64  {129768, 71202, -11119, 73017, -38875, -14413, -29234, 72370},
65  {752447, 8874, -58412, 73947, 17147, 62335, 16005, 8632},
66  {90614, 85268, 54180, -18810, -48219, 6013, 78169, -79785},
67  {1198280, -45086, 51830, -4578, 96120, 21231, 97919, 65651},
68  {18465, -64919, 80460, 90840, -59624, -75542, 25145, -47935},
69  {1503588, -43277, 43525, 92298, 58630, 92590, -9372, -60227},
70  {1244857, -16835, 47385, 97715, -12640, 69028, 76212, -81102},
71  {1410723, -60301, 31227, 93951, 73889, 81526, -72702, 68026},
72  {25334, 94016, -82071, 35961, 66597, -30705, -44404, -38304},
73  {277271, -67456, 84750, -51553, 21239, 81675, -99395, -4254},
74  {249912, -85698, 29958, 57308, 48789, -78219, 4657, 34539},
75  {373854, 85176, -95332, -1268, 57898, 15883, 50547, 83287},
76  {740061, -10343, 87758, -11782, 19346, 70072, -36991, 44529},
77  {146074, 49149, 52871, -7132, 56728, -33576, -49530, -62089},
78  {251591, -60113, 29475, 34421, -76870, 62646, 29278, -15212},
79  {22167, 87059, -29101, -5513, -21219, 22128, 7276, 57308},
80  {821228, -76706, 98205, 23445, 67921, 24111, -48614, -41906}
81  };
82  // Post equation constraints
83  for (int i = e_n; i--; ) {
84  IntArgs c(x_n, &eqs[i][1]);
85  linear(*this, c, x, IRT_EQ, eqs[i][0], opt.ipl());
86  }
87  branch(*this, x, INT_VAR_NONE(), INT_VAL_MIN());
88  }
89 
91  Eq20(Eq20& s) : Script(s) {
92  x.update(*this, s.x);
93  }
95  virtual Space*
96  copy(void) {
97  return new Eq20(*this);
98  }
100  virtual void
101  print(std::ostream& os) const {
102  os << "\tx[] = " << x << std::endl;
103  }
104 
105 };
106 
110 int
111 main(int argc, char* argv[]) {
112  Options opt("Eq20");
113  opt.solutions(0);
114  opt.iterations(1000);
115  opt.parse(argc,argv);
116  Script::run<Eq20,DFS,Options>(opt);
117  return 0;
118 }
119 
120 
121 
122 // STATISTICS: example-any
123 
Eq20(const Options &opt)
The actual problem.
Definition: eq20.cpp:57
Post propagator for SetVar x
Definition: set.hh:767
IntVarBranch INT_VAR_NONE(void)
Select first unassigned variable.
Definition: var.hpp:96
Computation spaces.
Definition: core.hpp:1742
void branch(Home home, const FloatVarArgs &x, FloatVarBranch vars, FloatValBranch vals, FloatBranchFilter bf, FloatVarValPrint vvp)
Branch over x with variable selection vars and value selection vals.
Definition: branch.cpp:39
void iterations(unsigned int i)
Set default number of iterations.
Definition: options.hpp:461
IntValBranch INT_VAL_MIN(void)
Select smallest value.
Definition: val.hpp:55
Integer variable array.
Definition: int.hh:763
int main(int argc, char *argv[])
Main-function.
Definition: eq20.cpp:111
virtual Space * copy(void)
Perform copying during cloning.
Definition: eq20.cpp:96
Gecode toplevel namespace
Options opt
The options.
Definition: test.cpp:97
Options for scripts
Definition: driver.hh:366
Parametric base-class for scripts.
Definition: driver.hh:729
void parse(int &argc, char *argv[])
Parse options from arguments argv (number is argc)
Definition: options.cpp:548
virtual void print(std::ostream &os) const
Print solution.
Definition: eq20.cpp:101
void linear(Home home, const FloatVarArgs &x, FloatRelType frt, FloatVal c)
Post propagator for .
Definition: linear.cpp:41
Eq20(Eq20 &s)
Constructor for cloning s.
Definition: eq20.cpp:91
void update(Space &home, VarImpVar< VarImp > &y)
Update this variable to be a clone of variable y.
Definition: var.hpp:116
@ IRT_EQ
Equality ( )
Definition: int.hh:926
void solutions(unsigned int n)
Set default number of solutions to search for.
Definition: options.hpp:283
Example: Solving 20 linear equations
Definition: eq20.cpp:47
Gecode::FloatVal c(-8, 8)
Passing integer arguments.
Definition: int.hh:628
Gecode::IntArgs i({1, 2, 3, 4})