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

2 *

3 * libDAI is licensed under the terms of the GNU General Public License version

4 * 2, or (at your option) any later version. libDAI is distributed without any

5 * warranty. See the file COPYING for more details.

6 *

7 * Copyright (C) 2008-2009 Joris Mooij [joris dot mooij at libdai dot org]

8 */

11 #include <dai/varset.h>

12 #include <dai/index.h>

13 #include <iostream>

14 #include <iomanip>

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

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

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

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

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

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

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

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

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

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

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

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

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

54 // Check whether the permutation works as advertised

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

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

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

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

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

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

84 }