Darwin  1.10(beta)
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Groups Pages
drwnVarAssignment.h
Go to the documentation of this file.
1 /******************************************************************************
2 ** DARWIN: A FRAMEWORK FOR MACHINE LEARNING RESEARCH AND DEVELOPMENT
3 ** Distributed under the terms of the BSD license (see the LICENSE file)
4 ** Copyright (c) 2007-2015, Stephen Gould
5 ** All rights reserved.
6 **
7 ******************************************************************************
8 ** FILENAME: drwnVarAssignment.h
9 ** AUTHOR(S): Stephen Gould <stephen.gould@anu.edu.au>
10 ** DESCRIPTION:
11 ** Data structures for encoding assignments to variables.
12 **
13 *****************************************************************************/
14 
21 #pragma once
22 
23 #include <cstdlib>
24 #include <cassert>
25 #include <vector>
26 #include <map>
27 
28 #include "drwnGraphUtils.h"
29 #include "drwnVarUniverse.h"
30 
31 using namespace std;
32 
33 // drwnFullAssignment ------------------------------------------------------
35 
36 typedef std::vector<int> drwnFullAssignment;
37 
38 // drwnPartialAssignment ---------------------------------------------------
40 
41 class drwnPartialAssignment : public std::map<int, int> {
42  public:
44  drwnPartialAssignment() { /* do nothing */ }
48  for (int i = 0; i < (int)a.size(); i++) {
49  if (a[i] >= 0) {
50  this->insert(make_pair(i, a[i]));
51  }
52  }
53  }
54 
58  for (drwnClique::const_iterator it = c.begin(); it != c.end(); ++it) {
59  if (a[*it] >= 0) {
60  this->insert(make_pair(*it, a[*it]));
61  }
62  }
63  }
64 
68  drwnClique c;
69  for (const_iterator it = begin(); it != end(); ++it) {
70  c.insert(it->first);
71  }
72  return c;
73  }
74 
77  operator drwnFullAssignment() const {
78  drwnFullAssignment a(this->rbegin()->first + 1, -1);
79  for (const_iterator it = begin(); it != end(); ++it) {
80  a[it->first] = it->second;
81  }
82  return a;
83  }
84 };
85 
86 // utility functions -------------------------------------------------------
87 
89 void successor(drwnFullAssignment& assignment, const drwnVarUniverse& universe);
91 void predecessor(drwnFullAssignment& assignment, const drwnVarUniverse& universe);
93 void successor(drwnPartialAssignment& assignment, const drwnVarUniverse& universe);
95 void predecessor(drwnPartialAssignment& assignment, const drwnVarUniverse& universe);
void successor(drwnFullAssignment &assignment, const drwnVarUniverse &universe)
next full assignment
Definition: drwnVarAssignment.cpp:24
drwnPartialAssignment(const drwnFullAssignment &a)
construct a partial assignment from a full assignment (values of -1 in the full assignment are ignore...
Definition: drwnVarAssignment.h:47
drwnPartialAssignment(const drwnFullAssignment &a, const drwnClique &c)
construct a partial assignment from a full assignment over a subset of the variables ...
Definition: drwnVarAssignment.h:57
void predecessor(drwnFullAssignment &assignment, const drwnVarUniverse &universe)
previous full assignment
Definition: drwnVarAssignment.cpp:36
Data structure for definining the random variables (name and cardinality) for a given problem instanc...
Definition: drwnVarUniverse.h:29
std::set< int > drwnClique
variable clique
Definition: drwnGraphUtils.h:37
std::vector< int > drwnFullAssignment
defines a complete assignment to all variables in the universe
Definition: drwnVarAssignment.h:36
defines an assignment to a subset of the variables
Definition: drwnVarAssignment.h:41
Generic graph utilities.
drwnClique getClique() const
return the clique of variables over which the partial assignment is defined
Definition: drwnVarAssignment.h:67
drwnPartialAssignment()
construct an empty partial assignment
Definition: drwnVarAssignment.h:44