This is a very minimal core example of the ATP scheduling function. The schedule of incoming/outgoing items is a linked list, and the constraints on each item are that it's sum must be large than 0 (so at any one time, stock is not negative), and the other constraint is that the sum is equal to the sum of the previous item plus your own value (positive or negative, depending if the item is incoming or outgoing) Insert items by selecting a "time" and then enter a value and press RETURN. Try adding an outgoing item at time 1, before anything was incoming. A small error will popup in the lower left corner telling you that this insertion would violate constraints, and the sale won't happen. Try to insert it after some incoming items with enough stock, and it will just work.
ATP
X

Menu
Insert Incoming at time
Insert Outgoing at time
3: 44 (44)
5: -12 (32)
12
44
3


0


Clear
// changed at Tue Dec 03 2013 10:38:51 GMT+0100 (Central Europe Standard Time) by timfelgentr
eff
this.addScript(function constrainItem(it) {
    // sum at each item must not be negative
    bbb.always({solver: this.getCassowary(), ctx: {it: it}}, function () {
        return it.sum >= 0;
    });
    // each sum is the sum of all previous elements plus its own value
    bbb.always({solver: this.getCassowary(), ctx: {it: it, r: bbb.readonly}}, function () {
        if (it.prev) {
            return it.sum == it.prev.sum + r(it.value);
        } else {
            return it.sum == r(it.value);
        }
    });
});
XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX
<lively.morphic.List#559E4... - List>
Tag:
run
save
Tests

-- ALL --
clear
constrainItem
constructItem
getCassowary
insertItem
removeUnecessaryIncoming
spliceItemIntoListAndReturnNext
updateLinks
Scripts
-
+
-
Connections
+
-- ALL --
all
ObjectEditor -- List>>constrainItem
X

Menu