1 /* This file is part of libDAI - http://www.libdai.org/

2 *

3 * Copyright (c) 2006-2011, The libDAI authors. All rights reserved.

4 *

5 * Use of this source code is governed by a BSD-style license that can be found in the LICENSE file.

6 */

9 #include <dai/varset.h>

10 #include <dai/index.h>

11 #include <iostream>

12 #include <iomanip>

22 // Define vector V = (x1, x2, x0)

27 cout << "V = " << V << endl; // Note that the elements of X are not necessarily ordered according to their labels

29 // Define set X = {x0, x1, x2}

34 cout << "X = " << X << endl; // Note that the elements of X are ordered according to their labels

37 cout << "(ascendingly according to their labels) but the ordering in V is different." << endl << endl;

39 // N = number of variables in V (and X)

42 // Define a Permute object based on the variables in V

44 // Each Var in V corresponds with a dimension in a multi-dimensional array.

45 // The permutation sigma permutes these dimensions from the canonical ordering

46 // (sorted ascendingly on the label of the variable, i.e., the same ordering as

47 // in X) into the ordering these variables have in V.

48 cout << "The permutation between both variable orderings is sigma = " << sigma.sigma() << ", or more verbosely:" << endl;

51 cout << "This means that variable V[sigma[n]] should correspond with the n'th variable in X (for n=0,...," << (N-1) << ")...";

52 // Check whether the permutation works as advertised

58 // Iterate over the joint states of the variables, according to the ordering in V

65 cout << setw(2) << (size_t)SV << " " << SV[sigma[0]] << " " << SV[sigma[1]] << " " << SV[sigma[2]] << endl;

68 // Iterate over the joint states of the variables, according to the canonical ordering in X

69 cout << "The states of the variables x0,x1,x2 are, according to the canonical ordering in X:" << endl;

75 // The main functionality of the Permute object is to calculate the induced permutation of linear indices of joint states

76 cout << "The permutation sigma induces the following permutation of linear indices of joint states:" << endl;

82 }