~ubuntu-branches/ubuntu/natty/gecode/natty

« back to all changes in this revision

Viewing changes to int/count.cc

  • Committer: Bazaar Package Importer
  • Author(s): Kari Pahula
  • Date: 2005-12-24 07:51:25 UTC
  • Revision ID: james.westby@ubuntu.com-20051224075125-klkiqofvbfvusfvt
Tags: upstream-1.0.0.dfsg.1
ImportĀ upstreamĀ versionĀ 1.0.0.dfsg.1

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
/*
 
2
 *  Main authors:
 
3
 *     Christian Schulte <schulte@gecode.org>
 
4
 *
 
5
 *  Copyright:
 
6
 *     Christian Schulte, 2002
 
7
 *
 
8
 *  Last modified:
 
9
 *     $Date: 2005-11-04 13:56:04 +0100 (Fri, 04 Nov 2005) $ by $Author: schulte $
 
10
 *     $Revision: 2497 $
 
11
 *
 
12
 *  This file is part of Gecode, the generic constraint
 
13
 *  development environment:
 
14
 *     http://www.gecode.org
 
15
 *
 
16
 *  See the file "LICENSE" for information on usage and
 
17
 *  redistribution of this file, and for a
 
18
 *     DISCLAIMER OF ALL WARRANTIES.
 
19
 *
 
20
 */
 
21
 
 
22
#include "int/count.hh"
 
23
 
 
24
namespace Gecode {
 
25
 
 
26
  using namespace Int;
 
27
 
 
28
#define CREATE(VY,VZ,C)                                                  \
 
29
if (icl == ICL_BND) {                                                    \
 
30
  if (C<IntView,VY,VZ,Count::RelEqBnd<IntView>,true>::post(home,x,y,z,c) \
 
31
      == ES_FAILED)                                                      \
 
32
    home->fail();                                                        \
 
33
} else {                                                                 \
 
34
  if (C<IntView,VY,VZ,Count::RelEqDom<IntView>,true>::post(home,x,y,z,c) \
 
35
      == ES_FAILED)                                                      \
 
36
    home->fail();                                                        \
 
37
}
 
38
 
 
39
  void
 
40
  count(Space* home, const IntVarArgs& xa, int yn,
 
41
        IntRelType r, int zn, IntConLevel icl) {
 
42
    if (home->failed()) return;
 
43
    ViewArray<IntView> x(home,xa);
 
44
    ConstIntView y(yn);
 
45
    ConstIntView z(zn);
 
46
    int c = 0;
 
47
    switch (r) {
 
48
    case IRT_EQ: 
 
49
      CREATE(ConstIntView,ConstIntView,Count::Eq); break;
 
50
    case IRT_NQ: 
 
51
      CREATE(ConstIntView,ConstIntView,Count::Nq); break;
 
52
    case IRT_LE: 
 
53
      c = 1; // Fall through
 
54
    case IRT_LQ: 
 
55
      CREATE(ConstIntView,ConstIntView,Count::Lq); break;
 
56
    case IRT_GR: 
 
57
      c = -1; // Fall through
 
58
    case IRT_GQ: 
 
59
      CREATE(ConstIntView,ConstIntView,Count::Gq); break;
 
60
    default: 
 
61
      throw UnknownRelation("Int::count");
 
62
    }
 
63
  }
 
64
 
 
65
  void
 
66
  count(Space* home, const IntVarArgs& xa, int yn,
 
67
        IntRelType r, IntVar z, IntConLevel icl) {
 
68
    if (home->failed()) return;
 
69
    ViewArray<IntView> x(home,xa);
 
70
    ConstIntView y(yn);
 
71
    int c = 0;
 
72
    switch (r) {
 
73
    case IRT_EQ: 
 
74
      CREATE(ConstIntView,IntView,Count::Eq); break;
 
75
    case IRT_NQ: 
 
76
      CREATE(ConstIntView,IntView,Count::Nq); break;
 
77
    case IRT_LE: 
 
78
      c = 1; // Fall through
 
79
    case IRT_LQ: 
 
80
      CREATE(ConstIntView,IntView,Count::Lq); break;
 
81
    case IRT_GR: 
 
82
      c = -1; // Fall through
 
83
    case IRT_GQ: 
 
84
      CREATE(ConstIntView,IntView,Count::Gq); break;
 
85
    default: 
 
86
      throw UnknownRelation("Int::count");
 
87
    }
 
88
  }
 
89
 
 
90
  void
 
91
  count(Space* home, const IntVarArgs& xa, IntVar y,
 
92
        IntRelType r, int zn, IntConLevel icl) {
 
93
    if (home->failed()) return;
 
94
    ViewArray<IntView> x(home,xa);
 
95
    ConstIntView z(zn);
 
96
    int c = 0;
 
97
    switch (r) {
 
98
    case IRT_EQ: 
 
99
      CREATE(IntView,ConstIntView,Count::Eq); break;
 
100
    case IRT_NQ: 
 
101
      CREATE(IntView,ConstIntView,Count::Nq); break;
 
102
    case IRT_LE: 
 
103
      c = 1; // Fall through
 
104
    case IRT_LQ: 
 
105
      CREATE(IntView,ConstIntView,Count::Lq); break;
 
106
    case IRT_GR: 
 
107
      c = -1; // Fall through
 
108
    case IRT_GQ: 
 
109
      CREATE(IntView,ConstIntView,Count::Gq); break;
 
110
    default: 
 
111
      throw UnknownRelation("Int::count");
 
112
    }
 
113
  }
 
114
 
 
115
  void
 
116
  count(Space* home, const IntVarArgs& xa, IntVar y,
 
117
        IntRelType r, IntVar z, IntConLevel icl) {
 
118
    if (home->failed()) return;
 
119
    ViewArray<IntView> x(home,xa);
 
120
    int c = 0;
 
121
    switch (r) {
 
122
    case IRT_EQ: 
 
123
      CREATE(IntView,IntView,Count::Eq); break;
 
124
    case IRT_NQ: 
 
125
      CREATE(IntView,IntView,Count::Nq); break;
 
126
    case IRT_LE: 
 
127
      c = 1; // Fall through
 
128
    case IRT_LQ: 
 
129
      CREATE(IntView,IntView,Count::Lq); break;
 
130
    case IRT_GR: 
 
131
      c = -1; // Fall through
 
132
    case IRT_GQ: 
 
133
      CREATE(IntView,IntView,Count::Gq); break;
 
134
    default: 
 
135
      throw UnknownRelation("Int::count");
 
136
    }
 
137
  }
 
138
 
 
139
}
 
140
 
 
141
// STATISTICS: int-post
 
142