kiwi-java icon indicating copy to clipboard operation
kiwi-java copied to clipboard

Simplex tableau

Open delaneyj opened this issue 7 years ago • 0 comments

I was testing a simplex word problem as a unit test but the answer is no where near a correct answer and hope I'm doing something wrong. Add this

@Test
	public void wordProblem()
			throws DuplicateConstraintException, UnsatisfiableConstraintException, NonlinearExpressionException {
		/*
		 * Suppose a company manufactures electronic components for computers. Component
		 * A requires 2 hours of fabrication and 1 hour of assembly Component B requires
		 * 3 hours of fabrication and 1 hour of assembly Component C requires 2 hours of
		 * fabrication and 2 hour of assembly The company has up to 1000 labor hours for
		 * fabrication and 800 labor hours. If the profit on each component A,B, and C
		 * is $7,$8,$10 respectively, how many of each should be produced to maximize
		 * profit?
		 */

		Solver solver = new Solver();
		final HashMap<String, HashMap<String, Variable>> nodeHashMap = new HashMap<>();
		ConstraintParser.CassowaryVariableResolver variableResolver = createVariableResolver(solver, nodeHashMap);

		solver.addConstraint(ConstraintParser.parseConstraint("info.a >= 0", variableResolver));
		solver.addConstraint(ConstraintParser.parseConstraint("info.b >= 0", variableResolver));
		solver.addConstraint(ConstraintParser.parseConstraint("info.c >= 0", variableResolver));
		solver.addConstraint(ConstraintParser.parseConstraint("info.fabrication <= 1000", variableResolver));
		solver.addConstraint(ConstraintParser.parseConstraint("info.assembly <= 800", variableResolver));
		solver.addConstraint(ConstraintParser.parseConstraint("info.fabrication == 2*info.c + 3*info.b + 2*info.c",
				variableResolver));
		solver.addConstraint(ConstraintParser.parseConstraint("info.assembly == info.c + info.b + 2*info.c",
				variableResolver));
		solver.addConstraint(ConstraintParser.parseConstraint("info.profits == 7*info.c + 8*info.b + 10*info.c",
				variableResolver));
		solver.addConstraint(ConstraintParser.parseConstraint("info.profits == 100000000 !strong",
				variableResolver));
		solver.updateVariables();

		printNodes(nodeHashMap);
	}

To RealWorldTests.java. It prints out

node info
 a = 0.0 (address:1411892748)
 profits = 4250.0 (address:611563982)
 b = 0.0 (address:1024429571)
 c = 250.0 (address:1138193439)
 fabrication = 1000.0 (address:1601292138)
 assembly = 750.0 (address:1330754528)

which is very wrong (profits don't match equation and neither does assembly).

delaneyj avatar Dec 26 '18 23:12 delaneyj