18 using namespace gtsam;
27 using IJ = std::pair<size_t, size_t>;
33 return dkeys_.at(
IJ(i, j));
37 Key key(
size_t i,
size_t j)
const {
return dkey(i, j).first; }
44 for (
size_t i = 0;
i <
n; ++
i) {
45 for (
size_t j = 0;
j <
n; ++
j) {
51 int value = va_arg(ap,
int);
52 if (value != 0) addSingleValue(dkeys_[ij], value - 1);
59 for (
size_t i = 0;
i <
n;
i++) {
61 for (
size_t j = 0;
j <
n;
j++) dkeys.push_back(dkey(
i,
j));
66 for (
size_t j = 0;
j <
n;
j++) {
68 for (
size_t i = 0;
i <
n;
i++) dkeys.push_back(dkey(
i,
j));
74 for (
size_t I = 0;
I <
N;
I++) {
76 for (
size_t J = 0;
J <
N;
J++) {
79 for (
size_t i = i0;
i < i0 +
N;
i++)
80 for (
size_t j = j0;
j < j0 +
N;
j++) dkeys.push_back(dkey(
i,
j));
90 for (
size_t i = 0;
i < n_;
i++) {
91 for (
size_t j = 0;
j < n_;
j++) {
93 cout << 1 + assignment.at(k) <<
" ";
102 printAssignment(MPE);
107 for (
size_t i = 0;
i < n_;
i++) {
108 for (
size_t j = 0;
j < n_;
j++) {
110 cout << domains.at(k).base1Str();
129 expected = {{csp.
key(0, 0), 0}, {csp.
key(0, 1), 1},
130 {csp.
key(0, 2), 2}, {csp.
key(0, 3), 3},
131 {csp.
key(1, 0), 2}, {csp.
key(1, 1), 3},
132 {csp.
key(1, 2), 0}, {csp.
key(1, 3), 1},
133 {csp.
key(2, 0), 3}, {csp.
key(2, 1), 2},
134 {csp.
key(2, 2), 1}, {csp.
key(2, 3), 0},
135 {csp.
key(3, 0), 1}, {csp.
key(3, 1), 0},
136 {csp.
key(3, 2), 3}, {csp.
key(3, 3), 2}};
152 auto new_solution = new_csp.optimize();
160 0, 0, 5, 0, 9, 0, 0, 0, 1,
161 0, 0, 0, 0, 0, 2, 0, 7, 3,
162 7, 6, 0, 0, 0, 8, 2, 0, 0,
164 0, 1, 2, 0, 0, 9, 0, 0, 4,
165 0, 0, 0, 2, 0, 3, 0, 0, 0,
166 3, 0, 0, 1, 0, 0, 9, 6, 0,
168 0, 0, 1, 9, 0, 0, 0, 5, 8,
169 9, 7, 0, 5, 0, 0, 0, 0, 0,
170 5, 0, 0, 0, 3, 0, 7, 0, 0);
178 Domain domain99 = domains.at(key99);
192 0, 0, 9, 7, 4, 8, 0, 0, 0, 7,
193 0, 0, 0, 0, 0, 0, 0, 0, 0, 2,
194 0, 1, 0, 9, 0, 0, 0, 0, 0, 7,
195 0, 0, 0, 2, 4, 0, 0, 6, 4, 0,
196 1, 0, 5, 9, 0, 0, 9, 8, 0, 0,
197 0, 3, 0, 0, 0, 0, 0, 8, 0, 3,
198 0, 2, 0, 0, 0, 0, 0, 0, 0, 0,
199 0, 6, 0, 0, 0, 2, 7, 5, 9, 0, 0);
205 VariableIndexOrdered index(csp);
206 index.print(
"index");
207 ofstream
os(
"/Users/dellaert/src/hmetis-1.5-osx-i686/extreme-dual.txt");
208 index.outputMetisFormat(os);
215 Domain domain99 = domains.at(key99);
229 9, 5, 0, 0, 0, 6, 0, 0, 0,
230 0, 8, 4, 0, 7, 0, 0, 0, 0,
231 6, 2, 0, 5, 0, 0, 4, 0, 0,
233 0, 0, 0, 2, 9, 0, 6, 0, 0,
234 0, 9, 0, 0, 0, 0, 0, 2, 0,
235 0, 0, 2, 0, 6, 3, 0, 0, 0,
237 0, 0, 9, 0, 0, 7, 0, 6, 8,
238 0, 0, 0, 0, 3, 0, 2, 9, 0,
239 0, 0, 0, 1, 0, 0, 0, 3, 7);
245 Domain domain99 = domains.at(key99);
254 auto solution = new_csp.optimize();
const gtsam::Symbol key('X', 0)
static int runAllTests(TestResult &result)
bool assert_equal(const Matrix &expected, const Matrix &actual, double tol)
Sudoku(size_t n,...)
Constructor.
void printSolution() const
solve and print solution
Key key(size_t i, size_t j) const
return Key for cell(i,j)
DiscreteValues optimize(OptionalOrderingType orderingType={}) const
Find the maximum probable explanation (MPE) by doing max-product.
const DiscreteKey & dkey(size_t i, size_t j) const
return DiscreteKey for cell(i,j)
CSP partiallyApply(const Domains &domains) const
std::pair< size_t, size_t > IJ
Mapping from base i,j coordinates to discrete keys:
std::map< Key, Domain > Domains
#define EXPECT(condition)
A class that encodes Sudoku's as a CSP problem.
JacobiRotation< float > J
Domains runArcConsistency(size_t cardinality, size_t maxIterations=10) const
std::map< IJ, DiscreteKey > dkeys_
size_t n_
Side of Sudoku, e.g. 4 or 9.
#define EXPECT_LONGS_EQUAL(expected, actual)
ofstream os("timeSchurFactors.csv")
int optimize(const SfmData &db, const NonlinearFactorGraph &graph, const Values &initial, bool separateCalibration=false)
std::pair< Key, size_t > DiscreteKey
void printAssignment(const DiscreteValues &assignment) const
Print readable form of assignment.
Jet< T, N > sqrt(const Jet< T, N > &f)
std::uint64_t Key
Integer nonlinear key type.
void printDomains(const Domains &domains)
DiscreteKeys is a set of keys that can be assembled using the & operator.