示例#1
0
文件: Tests.cpp 项目: vsaw/HJI-Approx
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;
}
示例#2
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;
}