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

« back to all changes in this revision

Viewing changes to set/int.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
 *     Guido Tack <tack@gecode.org>
 
4
 *     Christian Schulte <schulte@gecode.org>
 
5
 *
 
6
 *  Copyright:
 
7
 *     Guido Tack, 2004
 
8
 *     Christian Schulte, 2004
 
9
 *
 
10
 *  Last modified:
 
11
 *     $Date: 2005-11-25 17:31:45 +0100 (Fri, 25 Nov 2005) $ by $Author: tack $
 
12
 *     $Revision: 2652 $
 
13
 *
 
14
 *  This file is part of Gecode, the generic constraint
 
15
 *  development environment:
 
16
 *     http://www.gecode.org
 
17
 *
 
18
 *  See the file "LICENSE" for information on usage and
 
19
 *  redistribution of this file, and for a
 
20
 *     DISCLAIMER OF ALL WARRANTIES.
 
21
 *
 
22
 */
 
23
 
 
24
#include "set.hh"
 
25
 
 
26
#include "set/int.hh"
 
27
#include "set/rel.hh"
 
28
 
 
29
using namespace Gecode::Int;
 
30
 
 
31
namespace Gecode {
 
32
 
 
33
  void
 
34
  rel(Space* home, SetVar s, IntRelType r, IntVar x) {
 
35
    if (home->failed()) return;
 
36
    switch(r) {
 
37
    case IRT_EQ:
 
38
      {
 
39
        Gecode::Int::IntView xv(x);
 
40
        Set::SingletonView xsingle(xv);
 
41
        GECODE_ES_FAIL(home,
 
42
                       (Set::Rel::Eq<Set::SetView,Set::SingletonView>
 
43
                        ::post(home,s,xsingle)));
 
44
 
 
45
      }
 
46
      break;
 
47
    case IRT_NQ:
 
48
      {
 
49
        Gecode::Int::IntView xv(x);
 
50
        Set::SingletonView xsingle(xv);
 
51
        GECODE_ES_FAIL(home,
 
52
                       (Set::Rel::Distinct<Set::SetView,Set::SingletonView>
 
53
                        ::post(home,s,xsingle)));
 
54
 
 
55
      }
 
56
      break;
 
57
    case IRT_LQ:
 
58
      {
 
59
        IntVar tmp(home, Limits::Int::int_min, Limits::Int::int_max);
 
60
        rel(home, tmp, IRT_LQ, x);
 
61
        GECODE_ES_FAIL(home,Set::Int::MaxElement::post(home,s,tmp));
 
62
      }
 
63
      break;
 
64
    case IRT_LE:
 
65
      {
 
66
        IntVar tmp(home, Limits::Int::int_min, Limits::Int::int_max);
 
67
        rel(home, tmp, IRT_LE, x);
 
68
        GECODE_ES_FAIL(home,Set::Int::MaxElement::post(home,s,tmp));
 
69
      }
 
70
      break;
 
71
    case IRT_GQ:
 
72
      {
 
73
        IntVar tmp(home, Limits::Int::int_min, Limits::Int::int_max);
 
74
        rel(home, tmp, IRT_GQ, x);
 
75
        GECODE_ES_FAIL(home,Set::Int::MinElement::post(home,s,tmp));
 
76
      }
 
77
      break;
 
78
    case IRT_GR:
 
79
      {
 
80
        IntVar tmp(home, Limits::Int::int_min, Limits::Int::int_max);
 
81
        rel(home, tmp, IRT_GR, x);
 
82
        GECODE_ES_FAIL(home,Set::Int::MinElement::post(home,s,tmp));
 
83
      }
 
84
      break;
 
85
    }
 
86
 
 
87
  }
 
88
 
 
89
  void
 
90
  rel(Space* home, IntVar x, IntRelType r, SetVar s) {
 
91
    IntRelType rr;
 
92
    switch (r) {
 
93
    case IRT_LE: rr=IRT_GR; break;
 
94
    case IRT_LQ: rr=IRT_GQ; break;
 
95
    case IRT_GR: rr=IRT_LE; break;
 
96
    case IRT_GQ: rr=IRT_LQ; break;
 
97
    default: rr=r;
 
98
    }
 
99
    rel(home, s, rr, x);
 
100
  }
 
101
 
 
102
  void
 
103
  minElement(Space* home, SetVar s, IntVar x){
 
104
    if (home->failed()) return;
 
105
    GECODE_ES_FAIL(home,Set::Int::MinElement::post(home,s,x));
 
106
  }
 
107
  void
 
108
  maxElement(Space* home, SetVar s, IntVar x){
 
109
    if (home->failed()) return;
 
110
    GECODE_ES_FAIL(home,Set::Int::MaxElement::post(home,s,x));
 
111
  }
 
112
 
 
113
  void
 
114
  match(Space* home, SetVar s, const IntVarArgs& x) {
 
115
    if (home->failed()) return;
 
116
    ViewArray<IntView> xa(home,x);
 
117
    GECODE_ES_FAIL(home,Set::Int::Match::post(home,s,xa));
 
118
  }
 
119
 
 
120
  void
 
121
  channelVarVal(Space* home, const IntVarArgs& x, const SetVarArgs& y) {
 
122
    if (home->failed()) return;
 
123
    ViewArray<Int::IntView> xa(home,x);
 
124
    ViewArray<Set::SetView> ya(home,y);
 
125
    GECODE_ES_FAIL(home,Set::Int::ChannelVarVal::post(home,xa,ya));
 
126
  }
 
127
 
 
128
  void weights(Space* home, const IntArgs& elements, const IntArgs& weights,
 
129
               SetVar x, IntVar y) {
 
130
    if (home->failed()) return;
 
131
    Set::SetView xv(x);
 
132
    Int::IntView yv(y);
 
133
    GECODE_ES_FAIL(home,Set::Int::Weights::post(home,elements,weights,x,y));
 
134
  }
 
135
 
 
136
}
 
137
 
 
138
// STATISTICS: set-post
 
139