コード例 #1
0
ファイル: Tests.cpp プロジェクト: vsaw/HJI-Approx
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;
}
コード例 #2
0
ファイル: Tests.cpp プロジェクト: vsaw/HJI-Approx
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;
}
コード例 #3
0
ファイル: protoboard.cpp プロジェクト: scipr-lab/libsnark
FElem Protoboard::val(const LinearCombination& lc) const {
    return lc.eval(assignment_);
}
コード例 #4
0
ファイル: Tests.cpp プロジェクト: vsaw/HJI-Approx
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;
}