Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
26 changed files
with
951 additions
and
734 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Binary file not shown.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,26 +1,26 @@ | ||
# Demo animate 1 | ||
import salabim as sim | ||
|
||
class AnimateMovingText(sim.Animate): | ||
def __init__(self): | ||
super().__init__(text='',x0=100,x1=1000,y0=100,t1=env.now()+10) | ||
|
||
def x(self,t): | ||
return sim.interpolate(sim.interpolate(t,self.t0,self.t1,0,1)**2,0,1,self.x0,self.x1) | ||
|
||
def y(self,t): | ||
return int(t)*50 | ||
|
||
def text(self,t): | ||
return '{:0.1f}'.format(t) | ||
|
||
|
||
1env=sim.Environment() | ||
|
||
env.animation_parameters() | ||
|
||
AnimateMovingText() | ||
|
||
sim.run() | ||
|
||
# Demo animate 1 | ||
import salabim as sim | ||
|
||
class AnimateMovingText(sim.Animate): | ||
def __init__(self): | ||
super().__init__(text='',x0=100,x1=1000,y0=100,t1=env.now()+10) | ||
|
||
def x(self,t): | ||
return sim.interpolate(sim.interpolate(t,self.t0,self.t1,0,1)**2,0,1,self.x0,self.x1) | ||
|
||
def y(self,t): | ||
return int(t)*50 | ||
|
||
def text(self,t): | ||
return '{:0.1f}'.format(t) | ||
|
||
|
||
env=sim.Environment() | ||
|
||
env.animation_parameters() | ||
|
||
AnimateMovingText() | ||
|
||
env.run() | ||
|
||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,50 +1,53 @@ | ||
# Demo animate 2.py | ||
import salabim as sim | ||
|
||
class AnimateWaitSquare(sim.Animate): | ||
def __init__(self,i): | ||
self.i=i | ||
super().__init__(rectangle0=(-10,-10,10,10),x0=300-30*i,y0=100,fillcolor0='red',linewidth0=0) | ||
|
||
def visible(self,t): | ||
return q[self.i] is not None | ||
|
||
class AnimateWaitText(sim.Animate): | ||
def __init__(self,i): | ||
self.i=i | ||
super().__init__(text='',x0=300-30*i,y0=100,textcolor0='white') | ||
|
||
def text(self,t): | ||
component_i=q[self.i] | ||
|
||
if component_i is None: | ||
return '' | ||
else: | ||
return component_i.name() | ||
|
||
def do_animation(): | ||
env.animation_parameters() | ||
for i in range(10): | ||
AnimateWaitSquare(i) | ||
AnimateWaitText(i) | ||
show_length=sim.Animate(text='',x0=330,y0=100,textcolor0='black',anchor='w') | ||
show_length.text=lambda t: 'Length= '+str(len(q)) | ||
|
||
class Person(sim.Component): | ||
def process(self): | ||
self.enter(q) | ||
yield self.hold(15) | ||
self.leave(q) | ||
|
||
env=sim.Environment(trace=True) | ||
|
||
q=sim.Queue('q') | ||
for i in range(15): | ||
Person(name='{:02d}'.format(i),at=i*1) | ||
|
||
|
||
do_animation() | ||
|
||
|
||
|
||
env.run() | ||
# Demo animate 2.py | ||
import salabim as sim | ||
|
||
|
||
class AnimateWaitSquare(sim.Animate): | ||
def __init__(self, i): | ||
self.i = i | ||
super().__init__( | ||
rectangle0=(-10, -10, 10, 10), x0=300 - 30*i, y0=100, fillcolor0='red', linewidth0=0) | ||
|
||
def visible(self, t): | ||
return q[self.i] is not None | ||
|
||
|
||
class AnimateWaitText(sim.Animate): | ||
def __init__(self, i): | ||
self.i = i | ||
super().__init__(text='', x0=300-30*i, y0=100, textcolor0='white') | ||
|
||
def text(self, t): | ||
component_i = q[self.i] | ||
|
||
if component_i is None: | ||
return '' | ||
else: | ||
return component_i.name() | ||
|
||
|
||
def do_animation(): | ||
env.animation_parameters() | ||
for i in range(10): | ||
AnimateWaitSquare(i) | ||
AnimateWaitText(i) | ||
show_length=sim.Animate(text='',x0=330,y0=100,textcolor0='black',anchor='w') | ||
show_length.text = lambda t: 'Length= ' + str(len(q)) | ||
|
||
|
||
class Person(sim.Component): | ||
def process(self): | ||
self.enter(q) | ||
yield self.hold(15) | ||
self.leave(q) | ||
|
||
env = sim.Environment(trace=True) | ||
|
||
q = sim.Queue('q') | ||
for i in range(15): | ||
Person(name='{:02d}'.format(i), at=i*1) | ||
|
||
|
||
do_animation() | ||
|
||
env.run() |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,40 @@ | ||
# Example - bank, 3 clerks (state).py | ||
import salabim as sim | ||
|
||
|
||
class CustomerGenerator(sim.Component): | ||
def process(self): | ||
while True: | ||
Customer() | ||
yield self.hold(sim.Uniform(5, 15).sample()) | ||
|
||
|
||
class Customer(sim.Component): | ||
def process(self): | ||
self.enter(waitingline) | ||
worktodo.trigger(max=1) | ||
yield self.passivate() | ||
|
||
|
||
class Clerk(sim.Component): | ||
def process(self): | ||
while True: | ||
if len(waitingline) == 0: | ||
yield self.wait(worktodo) | ||
self.customer = waitingline.pop() | ||
yield self.hold(30) | ||
self.customer.activate() | ||
|
||
|
||
env = sim.Environment(trace=False) | ||
CustomerGenerator() | ||
for i in range(3): | ||
Clerk() | ||
waitingline = sim.Queue('waitingline') | ||
worktodo = sim.State('worktodo') | ||
|
||
env.run(till=50000) | ||
waitingline.length.print_histogram(30, 0, 1) | ||
print() | ||
waitingline.length_of_stay.print_histogram(30, 0, 10) | ||
worktodo.print_statistics() |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -7,7 +7,6 @@ def process(self): | |
while True: | ||
yield self.hold(1) | ||
|
||
|
||
env = sim.Environment(trace=True) | ||
Car() | ||
env.run(till=5) |
Oops, something went wrong.