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

« back to all changes in this revision

Viewing changes to search/dfs-copy.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, 2004
 
7
 *
 
8
 *  Last modified:
 
9
 *     $Date: 2005-08-09 21:44:53 +0200 (Tue, 09 Aug 2005) $ by $Author: schulte $
 
10
 *     $Revision: 2192 $
 
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
 
 
23
 
 
24
#include "search/dfs-copy.hh"
 
25
 
 
26
namespace Gecode { namespace Search {
 
27
 
 
28
  DfsCopyEngine::~DfsCopyEngine(void) {
 
29
    delete cur;
 
30
    ds.reset();
 
31
  }
 
32
 
 
33
  void
 
34
  DfsCopyEngine::reset(Space* s) {
 
35
    delete cur;
 
36
    ds.reset();
 
37
    cur = s;
 
38
    FullStatistics::reset(s);
 
39
  }
 
40
 
 
41
  size_t
 
42
  DfsCopyEngine::stacksize(void) const {
 
43
    return ds.size();
 
44
  }
 
45
 
 
46
  Space*
 
47
  DfsCopyEngine::explore(void) {
 
48
    while (true) {
 
49
      if (cur == NULL) {
 
50
        if (ds.empty())
 
51
          return NULL;
 
52
        unsigned int alt = ds.top().alt();
 
53
        if (ds.top().rightmost()) {
 
54
          cur = ds.pop().space();
 
55
          FullStatistics::pop(cur);
 
56
        } else {
 
57
          clone++;
 
58
          cur = ds.top().space()->clone(true,propagate);
 
59
          ds.top().next();
 
60
        }
 
61
        commit++;
 
62
        cur->commit(alt,NULL,propagate);
 
63
        FullStatistics::current(cur);
 
64
      }
 
65
      unsigned int alt;
 
66
      switch (cur->status(alt,propagate)) {
 
67
      case SS_FAILED: {
 
68
        fail++;
 
69
        delete cur;
 
70
        cur = NULL;
 
71
        FullStatistics::current(NULL);
 
72
        break;
 
73
      }
 
74
      case SS_SOLVED: {
 
75
        Space *s = cur;
 
76
        cur = NULL;
 
77
        FullStatistics::current(NULL);
 
78
        return s;
 
79
      }
 
80
      case SS_BRANCH: {
 
81
        if (alt > 1) {
 
82
          ds.push(cur,alt);
 
83
          FullStatistics::push(ds.top().space());
 
84
          clone++;
 
85
        }
 
86
        commit++;
 
87
        cur->commit(0,NULL,propagate);
 
88
        break;
 
89
      }
 
90
      }
 
91
    }
 
92
  }
 
93
 
 
94
}}
 
95
 
 
96
// STATISTICS: search-any