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