Example #1
0
//This function demostrate how to use SIX to compute maxmium solution.
void solve_linear_program2()
{
	/* Given system has 2 variable, x1, x2
	max = 2x1 - x2
	s.t.
		2x1 - x2 <= 2
		x1 - 5x2 <= -4

		x1,x2 >= 0
	*/
	Float v;

	//Init linear inequality.
	FloatMat leq(2,3);
	leq.sete(6,
				2.0, -1.0, 		2.0,
				1.0, -5.0, 		-4.0);

	//Init target function.
	FloatMat tgtf(1,3);
	tgtf.sete(3,
				2.0, -1.0, 0.0);

	//Init variable constrain.
	FloatMat vc(2,3);
	vc.sete(6,
				-1.0,	0.0,	0.0,
				0.0,	-1.0, 	0.0);

	FloatMat res, eq;
	SIX<FloatMat,Float> six;

	//Dump to check.
	tgtf.dumpf();
	vc.dumpf();
	leq.dumpf();

	/*
	maximum is 2
	solution is:
	   14/9(1.555556)       10/9(1.111111)        0
	*/
	if (SIX_SUCC == six.maxm(v,res,tgtf,vc,eq,leq)) {
		printf("\nmaxv is %f\n", v.f());
		printf("\nsolution is:\n"); res.dumpf();
	} else {
		printf("\nunbound");
	}
}