-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathpetrinet.js
58 lines (49 loc) · 1.11 KB
/
petrinet.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
function isEnabled (pre) {
return _(pre).all(function (multiplicity, place) {
return (marking[place] || 0) >= multiplicity
})
}
function updateMarking (remove, add) {
// don't do anything if it's not enabled
if (!isEnabled(remove)) {
return
}
_.each(add, function (multiplicity, place) {
if (!marking[place]) {
marking[place] = 0
}
marking[place] += multiplicity
})
_.each(remove, function (multiplicity, place) {
if (!marking[place]) {
marking[place] = 0
}
marking[place] -= multiplicity
})
redraw()
}
function arcs (transitions) {
return transitions.reduce(function (arcs, t) {
var incoming = mapLocations(t.pre).map(function (arc) {
return {
x1: arc.x,
y1: arc.y,
x2: t.x,
y2: t.y,
incoming: true,
weight: arc.weight
}
})
var outgoing = mapLocations(t.post).map(function (arc) {
return {
x1: t.x,
y1: t.y,
x2: arc.x,
y2: arc.y,
incoming: false,
weight: arc.weight
}
})
return arcs.concat(incoming).concat(outgoing)
}, [])
}