Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions src/scripts/models/nets/petriNet.coffee
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,9 @@ class @PetriNet extends @Net
isFirable: (transition) ->
return false if transition.type isnt "transition"
preset = @getPreset(transition)
postset = @getPostset(transition)
return false for place in preset when parseInt(place.tokens) < @getEdgeWeight(place, transition)
return false for place in postset when parseInt(place.tokens) + @getEdgeWeight(transition, place) > parseInt(place.tokensCap)
return true

# Gets the weight of an edge between two nodes
Expand Down
11 changes: 6 additions & 5 deletions src/scripts/models/points/nodes/place.coffee
Original file line number Diff line number Diff line change
@@ -1,20 +1,21 @@
###
Petri nets places may have a label and a number of tokens
Petri nets places may have a label, a number of tokens and a token capacity
###

class @Place extends @Node
constructor: (point) ->
super(point)
{@tokens = 0} = point
{@tokens = 0, @tokensCap = 255} = point
@type = "place"
@connectableTypes = ["transition"]
@labelYoffset = 30
@labelYoffset = 50
@radius = 18

getText: ->
return @label if @label
return "p#{@id}"

getTokenLabel: ->
return "" if @tokens is 0
return @tokens
return "" if @tokens is 0 and @tokensCap is 255
return @tokens if @tokensCap is 255
return "#{@tokens}/#{@tokensCap}"
13 changes: 11 additions & 2 deletions src/scripts/models/tools/tokenTool.coffee
Original file line number Diff line number Diff line change
Expand Up @@ -17,18 +17,27 @@ class @TokenTool extends @Tool
text: "Enter a number of tokens for this place"
formElements: [
{
name: "Integer ≥ 0"
name: "Current tokens"
type: "number"
min: 0
value: parseInt(mouseDownNode.tokens)
},
{
name: "Max tokens"
type: "number"
min: 1
value: parseInt(mouseDownNode.tokensCap)
}
]
})
.then (formElements) ->
if formElements
tokens = formElements[0].value
if tokens >= 0
cap = formElements[1].value
if tokens >= 0 or cap >= 1
mouseDownNode.tokens = tokens
mouseDownNode.tokensCap = cap
mouseDownNode.radius = if cap is 255 then 18 else 25
restart()

else if mouseDownNode.type is "transition"
Expand Down