Generated on Sat Feb 7 2015 02:01:20 for Gecode by doxygen 1.8.9.1
view-values.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, 2012
8  *
9  * Last modified:
10  * $Date: 2012-09-18 18:07:37 +0200 (Tue, 18 Sep 2012) $ by $Author: schulte $
11  * $Revision: 13101 $
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/int/branch.hh>
39 
40 namespace Gecode { namespace Int { namespace Branch {
41 
43  : PosChoice(b,x.size(),p), n(0) {
44  for (ViewRanges<IntView> r(x); r(); ++r)
45  n++;
46  pm = heap.alloc<PosMin>(n+1);
47  unsigned int w=0;
48  int i=0;
49  for (ViewRanges<IntView> r(x); r(); ++r) {
50  pm[i].min = r.min();
51  pm[i].pos = w;
52  w += r.width(); i++;
53  }
54  pm[i].pos = w;
55  }
56 
58  Archive& e)
59  : PosChoice(b,a,p) {
60  e >> n;
61  pm = heap.alloc<PosMin>(n+1);
62  for (unsigned int i=0; i<n+1; i++) {
63  e >> pm[i].pos;
64  e >> pm[i].min;
65  }
66  }
67 
68  size_t
69  PosValuesChoice::size(void) const {
70  return sizeof(PosValuesChoice)+(n+1)*sizeof(PosMin);
71  }
72 
74  heap.free<PosMin>(pm,n+1);
75  }
76 
77  forceinline void
80  e << this->alternatives() << n;
81  for (unsigned int i=0; i<n+1; i++) {
82  e << pm[i].pos;
83  e << pm[i].min;
84  }
85  }
86 
87 }}}
88 
89 // STATISTICS: int-branch
virtual ~PosValuesChoice(void)
Deallocate.
Definition: view-values.cpp:73
PosValuesChoice(const Brancher &b, const Pos &p, IntView x)
Initialize choice for brancher b, position p, and view x.
Definition: view-values.cpp:42
virtual size_t size(void) const
Report size occupied.
Definition: view-values.cpp:69
Range iterator for integer variable views
Definition: int.hpp:236
unsigned int alternatives(void) const
Return number of alternatives.
Definition: core.hpp:3173
Heap heap
The single global heap.
Definition: heap.cpp:49
int p
Number of positive literals for node type.
Definition: bool-expr.cpp:236
T * alloc(long unsigned int n)
Allocate block of n objects of type T from heap.
Definition: heap.hpp:400
Gecode::IntArgs i(4, 1, 2, 3, 4)
Base-class for branchers.
Definition: core.hpp:1071
int n
Number of negative literals for node type.
Definition: bool-expr.cpp:238
NNF * r
Right subtree.
Definition: bool-expr.cpp:246
unsigned int size(I &i)
Size of all ranges of range iterator i.
Choices storing position
Position information.
virtual void archive(Archive &e) const
Archive into e.
Integer view for integer variables.
Definition: view.hpp:129
void free(T *b, long unsigned int n)
Delete n objects starting at b.
Definition: heap.hpp:426
Node * x
Pointer to corresponding Boolean expression node.
Definition: bool-expr.cpp:253
Archive representation
Definition: archive.hpp:45
virtual void archive(Archive &e) const
Archive into e.
Definition: view-values.cpp:78
#define forceinline
Definition: config.hpp:132
struct Gecode::@518::NNF::@57::@58 b
For binary nodes (and, or, eqv)
Gecode toplevel namespace
struct Gecode::@518::NNF::@57::@59 a
For atomic nodes.