Open theladyjaye opened 10 years ago
I'm attempting to run this example without success.... within a meteor serverside method.... (works mostly the same except npm requires are slightly different.) I attempted to following along in this video
https://www.youtube.com/watch?v=72sWgwaAoyk
c = Meteor.npmRequire("cassowary");
clientSolver = new c.SimplexSolver();
spending = new c.Variable({value : 3598});
revenues = new c.Variable({value : 2328});
deficit = new c.Variable({});
balance = new c.Equation(
c.minus(spending.value,revenues.value),
deficit,
c.Strength.required,0)
;
clientSolver.addConstraint(balance);
clientSolver.addEditVar(spending,c.Strength.high)
console.log('spending ' + spending);
console.log('revenues ' + revenues);
console.log('deficit ' + deficit);
clientSolver.beginEdit();
clientSolver.suggestValue(spending,200);
clientSolver.endEdit();
// spending becomes '0'
console.log('spending ' + spending);
console.log('revenues ' + revenues);
console.log('deficit ' + deficit);
* console output *
I20150509-11:57:56.797(-8)? spending [v1:3598]
I20150509-11:57:56.800(-8)? revenues [v2:2328]
I20150509-11:57:56.801(-8)? deficit [v3:1270]
I20150509-11:57:56.801(-8)? spending [v1:0]
I20150509-11:57:56.801(-8)? revenues [v2:2328]
I20150509-11:57:56.801(-8)? deficit [v3:1270]
I feel like I'm missing a basic fundamental step to get this to work.. Apparently the 'spending' variable is never updated to the value entered into the 'suggest()' call.
Using resolve() in various appropriate places has no effect.
The
deficit
below remains at 0 after thebalance
constraint is applied. I must be doing something incorrectly. Is there something I am missing here?Even copying this test: https://github.com/slightlyoff/cassowary.js/blob/master/tests/End-To-End-test.js#L20-L31
Will fail, running the unit tests do not fail, but using c.js from bin is where this is happening
I should clarify, from the unit test above:
x.value will be
0
y.value will be0
Maybe that is indeed the correct value and I just understand it wrong?
It looks like I need to:
solver.addStay(x);
and I will get x and y to be167
. I guess that makes sense in an equal situation. One of the 2 sides of the equality needs to take precedence, I suppose the addStay() does that?If no stay is added why are the variables zero'd?