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

« back to all changes in this revision

Viewing changes to set/rel/nosubset.icc

  • 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
 *     Gabor Szokoli <szokoli@gecode.org>
 
6
 *
 
7
 *  Copyright:
 
8
 *     Guido Tack, 2004
 
9
 *     Christian Schulte, 2004
 
10
 *     Gabor Szokoli, 2004
 
11
 *
 
12
 *  Last modified:
 
13
 *     $Date: 2005-08-01 08:20:10 +0200 (Mon, 01 Aug 2005) $ by $Author: tack $
 
14
 *     $Revision: 2098 $
 
15
 *
 
16
 *  This file is part of Gecode, the generic constraint
 
17
 *  development environment:
 
18
 *     http://www.gecode.org
 
19
 *
 
20
 *  See the file "LICENSE" for information on usage and
 
21
 *  redistribution of this file, and for a
 
22
 *     DISCLAIMER OF ALL WARRANTIES.
 
23
 *
 
24
 */
 
25
 
 
26
namespace Gecode { namespace Set { namespace Rel {
 
27
 
 
28
  /*
 
29
   * "No Subset" propagator
 
30
   *
 
31
   */
 
32
 
 
33
  template <class View0, class View1>
 
34
  forceinline
 
35
  NoSubSet<View0,View1>::NoSubSet(Space* home, View0 y0, View1 y1)
 
36
    : InhomBinaryPropagator<View0,PC_SET_CLUB,
 
37
                            View1,PC_SET_CGLB>(home,y0,y1) {}
 
38
 
 
39
  template <class View0, class View1>
 
40
  forceinline
 
41
  NoSubSet<View0,View1>::NoSubSet(Space* home, bool share, 
 
42
                                  NoSubSet<View0,View1>& p)
 
43
    : InhomBinaryPropagator<View0,PC_SET_CLUB,
 
44
                            View1,PC_SET_CGLB>(home,share,p) {}
 
45
 
 
46
  template <class View0, class View1>
 
47
  ExecStatus
 
48
  NoSubSet<View0,View1>::post(Space* home, View0 x, View1 y) {
 
49
    if (me_failed(x.cardMin(home,1)))
 
50
      return ES_FAILED;
 
51
    (void) new (home) NoSubSet<View0,View1>(home,x,y);
 
52
    return ES_OK;
 
53
  }
 
54
 
 
55
  template <class View0, class View1>
 
56
  Actor*
 
57
  NoSubSet<View0,View1>::copy(Space* home, bool share) {
 
58
    return new (home) NoSubSet<View0,View1>(home,share,*this);
 
59
  }
 
60
 
 
61
  template <class View0, class View1>
 
62
  ExecStatus
 
63
  NoSubSet<View0,View1>::propagate(Space* home) {
 
64
    GlbRanges<View0> x0lb(x0);
 
65
    LubRanges<View1> x1ub(x1);
 
66
    if (!Iter::Ranges::subset(x0lb, x1ub))
 
67
      return ES_SUBSUMED;
 
68
    if (x0.cardMin()>x1.cardMax()) { return ES_SUBSUMED; }
 
69
    LubRanges<View0> x0ub(x0);
 
70
    GlbRanges<View1> x1lb(x1);
 
71
    Iter::Ranges::Diff<LubRanges<View0>,GlbRanges<View1> >
 
72
      breakers(x0ub,x1lb);
 
73
    if (!breakers()) { return ES_FAILED; }
 
74
    if (breakers.min() == breakers.max()) {
 
75
      int b1 = breakers.min();
 
76
      ++breakers;
 
77
      if (breakers()) { return ES_FIX; }
 
78
      //Only one subsetness-breaker element left:
 
79
      GECODE_ME_CHECK( x0.include(home,b1) );
 
80
      GECODE_ME_CHECK( x1.exclude(home,b1) );
 
81
      return ES_SUBSUMED;
 
82
    }
 
83
    return ES_FIX;
 
84
  }
 
85
 
 
86
}}}
 
87
 
 
88
// STATISTICS: set-prop