Exemplo n.º 1
0
void test_GameStateDomain_eval() {
	printf("==== test_GameStateDomain_eval()\n");

	LinearCombination *lc = new LinearCombination();

	// Build Linear Combination.
	for (int i = 0; i < LINEAR_COMBINATON_LENGTH; i++) {
		lc->setFactor(i, pow(2, -LINEAR_COMBINATON_LENGTH));

		State *dp = new State[STATE_SPACE_DIMENSION];
		int p = i / 2;
		for (int j = 0; j < STATE_SPACE_DIMENSION; j++) {
			if (j == p)
				dp[j] = pow(-1, i);
			else
				dp[j] = 0;
		}
		lc->setPoint(i, dp);
	}

	// Build Expected result
	State expected[] = { 0.0, 0.0, 0.0, 0.0 };

	State *actual = lc->eval();
	ASSERT(GameStateDomain::equals(expected, actual, 1e-9), "Not Zero\n");

	delete[] actual;
	delete lc;
}
Exemplo n.º 2
0
void test_LinearCombination_creation() {
	cout << "==== test_LinearCombination_creation()" << endl;

	LinearCombination *lc = new LinearCombination();

	for (int i = 0; i < LINEAR_COMBINATON_LENGTH; i++) {
		ASSERT(lc->getPoint(i) == 0, "Point %d\n", i);
		ASSERT_EQUALS(1, lc->getFactor(i), 1e-9, "Factor %d\n", i);
	}
}
Exemplo n.º 3
0
void test_SquareDomain_convexCombination() {
	cout << "==== test_SquareDomain_convexCombination()" << endl;

	SquareDomain *sq = new SquareDomain(-1, 1, 2);

	State p0[] = { 0.0, 0.0, 0.0, 0.0 };
	LinearCombination *lc = sq->convexDecomposition(p0);
	State *actual = lc->eval();
	ASSERT(SquareDomain::equals(p0, actual, 1e-9), "p0\n");
	delete[] actual;
	delete lc;

	State p1[] = { 0.1, 0.9, -0.5, -1.0 };
	lc = sq->convexDecomposition(p1);
	actual = lc->eval();
	//	cout << "LinComb of P1: ";
	//	util_print_LinearCombination(lc);
	//	cout << "Actual of P1: ";
	//	util_print_State(actual);
	ASSERT(SquareDomain::equals(p1, actual, 1e-9), "p1\n");
	delete[] actual;
	delete lc;

	State p2[] = { 1.0, 1.0, 1.0, 1.0 };
	lc = sq->convexDecomposition(p2);
	actual = lc->eval();
	//	cout << "LinComb of P2: ";
	//	util_print_LinearCombination(lc);
	//	cout << "Actual of P2: ";
	//	util_print_State(actual);
	ASSERT(SquareDomain::equals(p2, actual, 1e-9), "p2\n");
	delete[] actual;
	delete lc;

	State p3[] = { -1.0, -1.0, -1.0, -1.0 };
	lc = sq->convexDecomposition(p3);
	actual = lc->eval();
	//	cout << "LinComb of P3: ";
	//	util_print_LinearCombination(lc);
	//	cout << "Actual of P3: ";
	//	util_print_State(actual);
	ASSERT(SquareDomain::equals(p3, actual, 1e-9), "p3\n");
	delete[] actual;
	delete lc;

	State p4[] = { 0.5, 0.5, 0.5, 0.5 };
	lc = sq->convexDecomposition(p4);
	actual = lc->eval();
	//	cout << "LinComb of P4: ";
	//	util_print_LinearCombination(lc);
	//	cout << "Actual of P4: ";
	//	util_print_State(actual);
	ASSERT(SquareDomain::equals(p4, actual, 1e-9), "p4\n");
	delete[] actual;
	delete lc;

	delete sq;
}
Exemplo n.º 4
0
void test_SquareDomain_convexCombination_index() {
	printf("==== test_SquareDomain_convexCombination_index() in %s:%d\n",
			__FILE__, __LINE__);

	SquareDomain *sq = new SquareDomain(-2, 2, 10);
	State s[] = { 0.1, 0.9, -0.5, -1.0 };

	LinearCombination *lc = sq->convexDecomposition(s);
	for (int i = 0; i < LINEAR_COMBINATON_LENGTH; i++) {
		State *corner = lc->getPoint(i);
		if (corner != NULL) {
			GridPointIndex *cornerIndex = sq->getGridIndex(corner);
			for (int j = 0; j < STATE_SPACE_DIMENSION; j++) {
				ASSERT_EQUALS(cornerIndex[j], lc->getIndex(i)[j], 1e-3,
						"%d %d: %d %d\n",
						i, j, cornerIndex[j], lc->getIndex(i)[j]);
			}
		}
	}

	delete lc;
	delete sq;
}
Exemplo n.º 5
0
FElem Protoboard::val(const LinearCombination& lc) const {
    return lc.eval(assignment_);
}
Exemplo n.º 6
0
void test_SquareDomainSquareHole_convexCombination() {
	cout << "==== test_SquareDomainSquareHole_convexCombination()" << endl;

	SquareDomainSquareHole *sq = new SquareDomainSquareHole(-1, 1, -0.5, 0.5,
			4);

	State p0[] = { 0.6, 0.0, 0.5, 0.0 };
	LinearCombination *lc = sq->convexDecomposition(p0);
	State *actual = lc->eval();
	ASSERT(SquareDomain::equals(p0, actual, 1e-9), "p0\n");
//	cout << "LinComb of P0: ";
//	util_print_LinearCombination(lc);
//	cout << "Actual of P0: ";
//	util_print_State(actual);
	delete[] actual;
	delete lc;

	State p1[] = { 0.1, 0.9, -0.5, -1.0 };
	lc = sq->convexDecomposition(p1);
	actual = lc->eval();
//	cout << "LinComb of P1: ";
//	util_print_LinearCombination(lc);
//	cout << "Actual of P1: ";
//	util_print_State(actual);
	ASSERT(SquareDomain::equals(p1, actual, 1e-9), "p1\n");
	delete[] actual;
	delete lc;

	State p2[] = { 1.0, 1.0, 1.0, 1.0 };
	lc = sq->convexDecomposition(p2);
	actual = lc->eval();

	//	cout << "LinComb of P2: ";
	//	util_print_LinearCombination(lc);
	//	cout << "Actual of P2: ";
	//	util_print_State(actual);

	ASSERT(SquareDomain::equals(p2, actual, 1e-9), "p2\n");
	delete[] actual;
	delete lc;

	State p3[] = { -1.0, -1.0, -1.0, -1.0 };
	lc = sq->convexDecomposition(p3);
	actual = lc->eval();
	//	cout << "LinComb of P3: ";
	//	util_print_LinearCombination(lc);
	//	cout << "Actual of P3: ";
	//	util_print_State(actual);
	ASSERT(SquareDomain::equals(p3, actual, 1e-9), "p3\n");
	delete[] actual;
	delete lc;

	State p4[] = { 0.5, 0.5, 0.5, 0.5 };
	lc = sq->convexDecomposition(p4);
	actual = lc->eval();
	//	cout << "LinComb of P4: ";
	//	util_print_LinearCombination(lc);
	//	cout << "Actual of P4: ";
	//	util_print_State(actual);
	ASSERT(SquareDomainSquareHole::equals(p4, actual, 1e-9), "p4\n");
	delete[] actual;
	delete lc;

	delete sq;

	sq = new SquareDomainSquareHole(-2, 2, -0.5, 0.5, 16);
	State p5[] = { -1.78, -1.84, -2, -1.46 };
	lc = sq->convexDecomposition(p5);
	actual = lc->eval();
//	cout << "LinComb of P5: ";
//	util_print_LinearCombination(lc);
//	cout << "Actual of P5: ";
//	util_print_State(actual);
	for (int i = 0; i < lc->getSize(); i++) {
		if (lc->getPoint(i) == NULL) {
			ASSERT_NULL(lc->getIndex(i), "Index not null %d", i);
		} else {
			GridPointIndex *index = sq->getGridIndex(lc->getPoint(i));
			for (int d = 0; d < STATE_SPACE_DIMENSION; d++) {
				ASSERT_EQUALS(index[d], lc->getIndex(i)[d], 1e-9,
						"Index number %d Component %d: %d <> %d",
						i, d, index[d], lc->getIndex(i)[d]);
			}
			delete[] index;
		}
	}
	ASSERT(SquareDomainSquareHole::equals(p5, actual, 1e-9), "p5\n");
	delete[] actual;
	delete lc;
	delete sq;
}