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

« back to all changes in this revision

Viewing changes to test/set/convex.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
 *
 
5
 *  Copyright:
 
6
 *     Guido Tack, 2005
 
7
 *
 
8
 *  Last modified:
 
9
 *     $Date: 2005-11-01 16:01:21 +0100 (Tue, 01 Nov 2005) $ by $Author: zayenz $
 
10
 *     $Revision: 2465 $
 
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 "test/set.hh"
 
23
 
 
24
static IntSet ds_33(-4,4);
 
25
 
 
26
class Convex : public SetTest {
 
27
public:
 
28
  Convex(const char* t) 
 
29
    : SetTest(t,1,ds_33,false) {}
 
30
  virtual bool solution(const SetAssignment& x) const {
 
31
    CountableSetRanges xr0(x.lub, x[0]);
 
32
    if (!xr0())
 
33
      return true;
 
34
    ++xr0;
 
35
    if (!xr0())
 
36
      return true;
 
37
    return false;
 
38
  }
 
39
  virtual void post(Space* home, SetVarArray& x, IntVarArray&) {
 
40
    Gecode::convex(home, x[0]);
 
41
  }
 
42
};
 
43
Convex _convex("Convex::Convex");
 
44
 
 
45
class ConvexHull : public SetTest {
 
46
public:
 
47
  ConvexHull(const char* t) 
 
48
    : SetTest(t,2,ds_33,false) {}
 
49
  virtual bool solution(const SetAssignment& x) const {
 
50
    CountableSetRanges xr0(x.lub, x[0]);
 
51
    CountableSetRanges xr1(x.lub, x[1]);
 
52
 
 
53
    if (!xr0())
 
54
      return !xr1();
 
55
 
 
56
    int x0min = xr0.min();
 
57
    int x0max = xr0.max();
 
58
    ++xr0;
 
59
    if (!xr0()) {
 
60
      if (!xr1()) return false;
 
61
      if (x0min != xr1.min()) return false;
 
62
      int x1max = Limits::Set::int_min;
 
63
      while (xr1()) { x1max = xr1.max(); ++xr1;}
 
64
      if (x0max != x1max) return false;
 
65
      return true;
 
66
    }
 
67
    return false;
 
68
  }
 
69
  virtual void post(Space* home, SetVarArray& x, IntVarArray&) {
 
70
    Gecode::convexHull(home, x[1], x[0]);
 
71
  }
 
72
};
 
73
ConvexHull _convexhull("Convex::ConvexHull");
 
74
 
 
75
class ConvexHullS : public SetTest {
 
76
public:
 
77
  ConvexHullS(const char* t) 
 
78
    : SetTest(t,1,ds_33,false) {}
 
79
  virtual bool solution(const SetAssignment& x) const {
 
80
    CountableSetRanges xr0(x.lub, x[0]);
 
81
    if (!xr0())
 
82
      return true;
 
83
    ++xr0;
 
84
    if (!xr0())
 
85
      return true;
 
86
    return false;
 
87
  }
 
88
  virtual void post(Space* home, SetVarArray& x, IntVarArray&) {
 
89
    Gecode::convexHull(home, x[0], x[0]);
 
90
  }
 
91
};
 
92
ConvexHullS _convexhulls("Convex::Sharing::ConvexHullS");
 
93
 
 
94
// STATISTICS: test-set