Skip to content

Commit

Permalink
temp: control is returned back to python
Browse files Browse the repository at this point in the history
Wrote to Steve.
  • Loading branch information
Dilawar Singh committed Nov 15, 2021
1 parent f0d54c8 commit 30bb819
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 9 deletions.
17 changes: 10 additions & 7 deletions examples/S99_more/maze/maze_solve.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
from pathlib import Path
import typing as T


def add_maze(s, mazefile) -> T.List[smoldyn.Panel]:
"""Add maze"""
panels = []
Expand All @@ -31,8 +32,8 @@ def add_maze(s, mazefile) -> T.List[smoldyn.Panel]:
A = s.addSpecies("A", difc=2, color="blue")
A.addToSolution(1000, pos=[15, 15])

B = s.addSpecies("B", difc=0, color='black', display_size=3)
B.addToSolution(10, lowpos=[105,112], highpos=[110,112])
B = s.addSpecies("B", difc=0, color="black", display_size=3)
B.addToSolution(10, lowpos=[105, 112], highpos=[110, 112])

panels = add_maze(s, Path(__file__).parent / "maze.txt")
maze = s.addSurface("maze", panels=panels)
Expand All @@ -42,12 +43,14 @@ def add_maze(s, mazefile) -> T.List[smoldyn.Panel]:

# When any A meets B, maze is solved. So we set a reaction between A and B
s.addReaction("done", [A, B], [], rate=10)
s.addCommand("ifless B 10 text ", "E")

# Stop when A + B -> ∅ happens i.e. maze is solved.
s.addCommand("ifless B 10 pause", "E")

# TODO: Show the solution.
s.addOutputData('posdata')
s.addCommand("molpos B posdata", "E")
s.addCommand("ifless B 10 stop", "E")

s.addGraphics("opengl", iter=50)
s.run(3000, dt=0.01)
s.run(3000, dt=0.01, quit_at_end=True)

print(s.getOutputData("posdata"))
print('all done')
10 changes: 9 additions & 1 deletion source/Smoldyn/smolsim.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2533,8 +2533,16 @@ int simulatetimestep(simptr sim) {
sim->time+=sim->dt; // --- end of time step ---
simsetvariable(sim,"time",sim->time);
er=simdocommands(sim);
if(er) return er;
#ifdef COMPILE_AS_PY_MODULE
if(er == 7) {
fprintf(stdout, "command stop");
sim->tmax = sim->time;
sim->tbreak = sim->time;
er = 0;
}
#endif

if(er) return er;

if(sim->time>=sim->tmax) return 1;
if(sim->time>=sim->tbreak) return 10;
Expand Down
1 change: 0 additions & 1 deletion source/python/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,6 @@ target_compile_options(_pysmoldyn PRIVATE -DENABLE_PYTHON_CALLBACK)
# especially where scanf is used for user input.
target_compile_options(_pysmoldyn PRIVATE -DCOMPILE_AS_PY_MODULE)


target_include_directories(_pysmoldyn PRIVATE ${Python3_INCLUDE_DIRS} ${PYBIND11_SOURCE_DIR}/include)

# This is suggested by pybind11: reduces binary size and disables some warnings.
Expand Down

0 comments on commit 30bb819

Please sign in to comment.