diff --git a/Makefile b/Makefile new file mode 100644 index 0000000000000000000000000000000000000000..4668d7ced383773e1bed8a22bf1689c6b90c72e1 --- /dev/null +++ b/Makefile @@ -0,0 +1,261 @@ +#------------------------------------------------------------------------------# +# This makefile was generated by 'cbp2make' tool rev.147 # +#------------------------------------------------------------------------------# + + +WORKDIR = `pwd` + +CC = gcc +CXX = g++ +AR = ar +LD = g++ +WINDRES = windres + +INC = -Isrc +CFLAGS = -Wall -std=c++11 -fexceptions -fpermissive +RESINC = +LIBDIR = +LIB = -lglpk -ldl +LDFLAGS = + +INC_DEBUG = $(INC) -Isrc -Isrc/bpn -Isrc/interf -Isrc/simul +CFLAGS_DEBUG = $(CFLAGS) -w -pg -g -Wunused-result -O0 -D_SIMULEAU_DEBUG_ +RESINC_DEBUG = $(RESINC) +RCFLAGS_DEBUG = $(RCFLAGS) +LIBDIR_DEBUG = $(LIBDIR) -L/usr/local/lib -L/usr/local/include -L/usr/include -L/usr/lib/x86_64-linux-gnu/ +LIB_DEBUG = $(LIB) +LDFLAGS_DEBUG = $(LDFLAGS) -pg -static-libstdc++ -static-libgcc +OBJDIR_DEBUG = obj/Debug +DEP_DEBUG = +OUT_DEBUG = bin/Debug/simuleau + +INC_RELEASE = $(INC) -Isrc/bpn -Isrc/simul -Isrc -Isrc/interf +CFLAGS_RELEASE = $(CFLAGS) -O2 +RESINC_RELEASE = $(RESINC) +RCFLAGS_RELEASE = $(RCFLAGS) +LIBDIR_RELEASE = $(LIBDIR) +LIB_RELEASE = $(LIB) +LDFLAGS_RELEASE = $(LDFLAGS) -s +OBJDIR_RELEASE = obj/Release +DEP_RELEASE = +OUT_RELEASE = bin/Release/simuleau + +OBJ_DEBUG = $(OBJDIR_DEBUG)/src/simul/breakpoint.o $(OBJDIR_DEBUG)/src/interf/interf.o $(OBJDIR_DEBUG)/src/interf/lex.yy.o $(OBJDIR_DEBUG)/src/interf/prf.o $(OBJDIR_DEBUG)/src/interf/timer.o $(OBJDIR_DEBUG)/src/interf/y.tab.o $(OBJDIR_DEBUG)/src/simul/event.o $(OBJDIR_DEBUG)/src/simul/schedule.o $(OBJDIR_DEBUG)/src/simul/simtime.o $(OBJDIR_DEBUG)/src/simul/simulate.o $(OBJDIR_DEBUG)/src/simuleau.o $(OBJDIR_DEBUG)/src/bpn/discretetransition.o $(OBJDIR_DEBUG)/src/bpn/batch.o $(OBJDIR_DEBUG)/src/bpn/batchplace.o $(OBJDIR_DEBUG)/src/bpn/batchtransition.o $(OBJDIR_DEBUG)/src/bpn/bpn.o $(OBJDIR_DEBUG)/src/bpn/continuousplace.o $(OBJDIR_DEBUG)/src/bpn/continuoustransition.o $(OBJDIR_DEBUG)/src/bpn/controllablebatch.o $(OBJDIR_DEBUG)/src/bpn/discreteplace.o $(OBJDIR_DEBUG)/src/bpn/arc.o $(OBJDIR_DEBUG)/src/bpn/firingquantity.o $(OBJDIR_DEBUG)/src/bpn/flow.o $(OBJDIR_DEBUG)/src/bpn/node.o $(OBJDIR_DEBUG)/src/bpn/place.o $(OBJDIR_DEBUG)/src/bpn/transition.o $(OBJDIR_DEBUG)/src/bpn/triangularbatchplace.o + +OBJ_RELEASE = $(OBJDIR_RELEASE)/src/simul/breakpoint.o $(OBJDIR_RELEASE)/src/interf/interf.o $(OBJDIR_RELEASE)/src/interf/lex.yy.o $(OBJDIR_RELEASE)/src/interf/prf.o $(OBJDIR_RELEASE)/src/interf/timer.o $(OBJDIR_RELEASE)/src/interf/y.tab.o $(OBJDIR_RELEASE)/src/simul/event.o $(OBJDIR_RELEASE)/src/simul/schedule.o $(OBJDIR_RELEASE)/src/simul/simtime.o $(OBJDIR_RELEASE)/src/simul/simulate.o $(OBJDIR_RELEASE)/src/simuleau.o $(OBJDIR_RELEASE)/src/bpn/discretetransition.o $(OBJDIR_RELEASE)/src/bpn/batch.o $(OBJDIR_RELEASE)/src/bpn/batchplace.o $(OBJDIR_RELEASE)/src/bpn/batchtransition.o $(OBJDIR_RELEASE)/src/bpn/bpn.o $(OBJDIR_RELEASE)/src/bpn/continuousplace.o $(OBJDIR_RELEASE)/src/bpn/continuoustransition.o $(OBJDIR_RELEASE)/src/bpn/controllablebatch.o $(OBJDIR_RELEASE)/src/bpn/discreteplace.o $(OBJDIR_RELEASE)/src/bpn/arc.o $(OBJDIR_RELEASE)/src/bpn/firingquantity.o $(OBJDIR_RELEASE)/src/bpn/flow.o $(OBJDIR_RELEASE)/src/bpn/node.o $(OBJDIR_RELEASE)/src/bpn/place.o $(OBJDIR_RELEASE)/src/bpn/transition.o $(OBJDIR_RELEASE)/src/bpn/triangularbatchplace.o + +all: debug release + +clean: clean_debug clean_release + +before_debug: + lex -o src/interf/y.tab.cpp src/interf/tokens.l + yacc -tdv -o src/interf/y.tab.cpp src/interf/glc.y + test -d bin/Debug || mkdir -p bin/Debug + test -d $(OBJDIR_DEBUG)/src/simul || mkdir -p $(OBJDIR_DEBUG)/src/simul + test -d $(OBJDIR_DEBUG)/src/interf || mkdir -p $(OBJDIR_DEBUG)/src/interf + test -d $(OBJDIR_DEBUG)/src || mkdir -p $(OBJDIR_DEBUG)/src + test -d $(OBJDIR_DEBUG)/src/bpn || mkdir -p $(OBJDIR_DEBUG)/src/bpn + +after_debug: + +debug: before_debug out_debug after_debug + +out_debug: before_debug $(OBJ_DEBUG) $(DEP_DEBUG) + $(LD) $(LIBDIR_DEBUG) -o $(OUT_DEBUG) $(OBJ_DEBUG) $(LDFLAGS_DEBUG) $(LIB_DEBUG) + +$(OBJDIR_DEBUG)/src/simul/breakpoint.o: src/simul/breakpoint.cpp + $(CXX) $(CFLAGS_DEBUG) $(INC_DEBUG) -c src/simul/breakpoint.cpp -o $(OBJDIR_DEBUG)/src/simul/breakpoint.o + +$(OBJDIR_DEBUG)/src/interf/interf.o: src/interf/interf.cpp + $(CXX) $(CFLAGS_DEBUG) $(INC_DEBUG) -c src/interf/interf.cpp -o $(OBJDIR_DEBUG)/src/interf/interf.o + +$(OBJDIR_DEBUG)/src/interf/lex.yy.o: src/interf/lex.yy.cpp + $(CC) $(CFLAGS_DEBUG) $(INC_DEBUG) -c src/interf/lex.yy.cpp -o $(OBJDIR_DEBUG)/src/interf/lex.yy.o + +$(OBJDIR_DEBUG)/src/interf/prf.o: src/interf/prf.cpp + $(CXX) $(CFLAGS_DEBUG) $(INC_DEBUG) -c src/interf/prf.cpp -o $(OBJDIR_DEBUG)/src/interf/prf.o + +$(OBJDIR_DEBUG)/src/interf/timer.o: src/interf/timer.cpp + $(CXX) $(CFLAGS_DEBUG) $(INC_DEBUG) -c src/interf/timer.cpp -o $(OBJDIR_DEBUG)/src/interf/timer.o + +$(OBJDIR_DEBUG)/src/interf/y.tab.o: src/interf/y.tab.cpp + $(CC) $(CFLAGS_DEBUG) $(INC_DEBUG) -c src/interf/y.tab.cpp -o $(OBJDIR_DEBUG)/src/interf/y.tab.o + +$(OBJDIR_DEBUG)/src/simul/event.o: src/simul/event.cpp + $(CXX) $(CFLAGS_DEBUG) $(INC_DEBUG) -c src/simul/event.cpp -o $(OBJDIR_DEBUG)/src/simul/event.o + +$(OBJDIR_DEBUG)/src/simul/schedule.o: src/simul/schedule.cpp + $(CXX) $(CFLAGS_DEBUG) $(INC_DEBUG) -c src/simul/schedule.cpp -o $(OBJDIR_DEBUG)/src/simul/schedule.o + +$(OBJDIR_DEBUG)/src/simul/simtime.o: src/simul/simtime.cpp + $(CXX) $(CFLAGS_DEBUG) $(INC_DEBUG) -c src/simul/simtime.cpp -o $(OBJDIR_DEBUG)/src/simul/simtime.o + +$(OBJDIR_DEBUG)/src/simul/simulate.o: src/simul/simulate.cpp + $(CXX) $(CFLAGS_DEBUG) $(INC_DEBUG) -c src/simul/simulate.cpp -o $(OBJDIR_DEBUG)/src/simul/simulate.o + +$(OBJDIR_DEBUG)/src/simuleau.o: src/simuleau.cpp + $(CXX) $(CFLAGS_DEBUG) $(INC_DEBUG) -c src/simuleau.cpp -o $(OBJDIR_DEBUG)/src/simuleau.o + +$(OBJDIR_DEBUG)/src/bpn/discretetransition.o: src/bpn/discretetransition.cpp + $(CXX) $(CFLAGS_DEBUG) $(INC_DEBUG) -c src/bpn/discretetransition.cpp -o $(OBJDIR_DEBUG)/src/bpn/discretetransition.o + +$(OBJDIR_DEBUG)/src/bpn/batch.o: src/bpn/batch.cpp + $(CXX) $(CFLAGS_DEBUG) $(INC_DEBUG) -c src/bpn/batch.cpp -o $(OBJDIR_DEBUG)/src/bpn/batch.o + +$(OBJDIR_DEBUG)/src/bpn/batchplace.o: src/bpn/batchplace.cpp + $(CXX) $(CFLAGS_DEBUG) $(INC_DEBUG) -c src/bpn/batchplace.cpp -o $(OBJDIR_DEBUG)/src/bpn/batchplace.o + +$(OBJDIR_DEBUG)/src/bpn/batchtransition.o: src/bpn/batchtransition.cpp + $(CXX) $(CFLAGS_DEBUG) $(INC_DEBUG) -c src/bpn/batchtransition.cpp -o $(OBJDIR_DEBUG)/src/bpn/batchtransition.o + +$(OBJDIR_DEBUG)/src/bpn/bpn.o: src/bpn/bpn.cpp + $(CXX) $(CFLAGS_DEBUG) $(INC_DEBUG) -c src/bpn/bpn.cpp -o $(OBJDIR_DEBUG)/src/bpn/bpn.o + +$(OBJDIR_DEBUG)/src/bpn/continuousplace.o: src/bpn/continuousplace.cpp + $(CXX) $(CFLAGS_DEBUG) $(INC_DEBUG) -c src/bpn/continuousplace.cpp -o $(OBJDIR_DEBUG)/src/bpn/continuousplace.o + +$(OBJDIR_DEBUG)/src/bpn/continuoustransition.o: src/bpn/continuoustransition.cpp + $(CXX) $(CFLAGS_DEBUG) $(INC_DEBUG) -c src/bpn/continuoustransition.cpp -o $(OBJDIR_DEBUG)/src/bpn/continuoustransition.o + +$(OBJDIR_DEBUG)/src/bpn/controllablebatch.o: src/bpn/controllablebatch.cpp + $(CXX) $(CFLAGS_DEBUG) $(INC_DEBUG) -c src/bpn/controllablebatch.cpp -o $(OBJDIR_DEBUG)/src/bpn/controllablebatch.o + +$(OBJDIR_DEBUG)/src/bpn/discreteplace.o: src/bpn/discreteplace.cpp + $(CXX) $(CFLAGS_DEBUG) $(INC_DEBUG) -c src/bpn/discreteplace.cpp -o $(OBJDIR_DEBUG)/src/bpn/discreteplace.o + +$(OBJDIR_DEBUG)/src/bpn/arc.o: src/bpn/arc.cpp + $(CXX) $(CFLAGS_DEBUG) $(INC_DEBUG) -c src/bpn/arc.cpp -o $(OBJDIR_DEBUG)/src/bpn/arc.o + +$(OBJDIR_DEBUG)/src/bpn/firingquantity.o: src/bpn/firingquantity.cpp + $(CXX) $(CFLAGS_DEBUG) $(INC_DEBUG) -c src/bpn/firingquantity.cpp -o $(OBJDIR_DEBUG)/src/bpn/firingquantity.o + +$(OBJDIR_DEBUG)/src/bpn/flow.o: src/bpn/flow.cpp + $(CXX) $(CFLAGS_DEBUG) $(INC_DEBUG) -c src/bpn/flow.cpp -o $(OBJDIR_DEBUG)/src/bpn/flow.o + +$(OBJDIR_DEBUG)/src/bpn/node.o: src/bpn/node.cpp + $(CXX) $(CFLAGS_DEBUG) $(INC_DEBUG) -c src/bpn/node.cpp -o $(OBJDIR_DEBUG)/src/bpn/node.o + +$(OBJDIR_DEBUG)/src/bpn/place.o: src/bpn/place.cpp + $(CXX) $(CFLAGS_DEBUG) $(INC_DEBUG) -c src/bpn/place.cpp -o $(OBJDIR_DEBUG)/src/bpn/place.o + +$(OBJDIR_DEBUG)/src/bpn/transition.o: src/bpn/transition.cpp + $(CXX) $(CFLAGS_DEBUG) $(INC_DEBUG) -c src/bpn/transition.cpp -o $(OBJDIR_DEBUG)/src/bpn/transition.o + +$(OBJDIR_DEBUG)/src/bpn/triangularbatchplace.o: src/bpn/triangularbatchplace.cpp + $(CXX) $(CFLAGS_DEBUG) $(INC_DEBUG) -c src/bpn/triangularbatchplace.cpp -o $(OBJDIR_DEBUG)/src/bpn/triangularbatchplace.o + +clean_debug: + rm -f $(OBJ_DEBUG) $(OUT_DEBUG) + rm -rf bin/Debug + rm -rf $(OBJDIR_DEBUG)/src/simul + rm -rf $(OBJDIR_DEBUG)/src/interf + rm -rf $(OBJDIR_DEBUG)/src + rm -rf $(OBJDIR_DEBUG)/src/bpn + +before_release: + yacc -tdv -o src/interf/y.tab.cpp src/interf/glc.y + test -d bin/Release || mkdir -p bin/Release + test -d $(OBJDIR_RELEASE)/src/simul || mkdir -p $(OBJDIR_RELEASE)/src/simul + test -d $(OBJDIR_RELEASE)/src/interf || mkdir -p $(OBJDIR_RELEASE)/src/interf + test -d $(OBJDIR_RELEASE)/src || mkdir -p $(OBJDIR_RELEASE)/src + test -d $(OBJDIR_RELEASE)/src/bpn || mkdir -p $(OBJDIR_RELEASE)/src/bpn + +after_release: + +release: before_release out_release after_release + +out_release: before_release $(OBJ_RELEASE) $(DEP_RELEASE) + $(LD) $(LIBDIR_RELEASE) -o $(OUT_RELEASE) $(OBJ_RELEASE) $(LDFLAGS_RELEASE) $(LIB_RELEASE) + +$(OBJDIR_RELEASE)/src/simul/breakpoint.o: src/simul/breakpoint.cpp + $(CXX) $(CFLAGS_RELEASE) $(INC_RELEASE) -c src/simul/breakpoint.cpp -o $(OBJDIR_RELEASE)/src/simul/breakpoint.o + +$(OBJDIR_RELEASE)/src/interf/interf.o: src/interf/interf.cpp + $(CXX) $(CFLAGS_RELEASE) $(INC_RELEASE) -c src/interf/interf.cpp -o $(OBJDIR_RELEASE)/src/interf/interf.o + +$(OBJDIR_RELEASE)/src/interf/lex.yy.o: src/interf/lex.yy.cpp + $(CC) $(CFLAGS_RELEASE) $(INC_RELEASE) -c src/interf/lex.yy.cpp -o $(OBJDIR_RELEASE)/src/interf/lex.yy.o + +$(OBJDIR_RELEASE)/src/interf/prf.o: src/interf/prf.cpp + $(CXX) $(CFLAGS_RELEASE) $(INC_RELEASE) -c src/interf/prf.cpp -o $(OBJDIR_RELEASE)/src/interf/prf.o + +$(OBJDIR_RELEASE)/src/interf/timer.o: src/interf/timer.cpp + $(CXX) $(CFLAGS_RELEASE) $(INC_RELEASE) -c src/interf/timer.cpp -o $(OBJDIR_RELEASE)/src/interf/timer.o + +$(OBJDIR_RELEASE)/src/interf/y.tab.o: src/interf/y.tab.cpp + $(CC) $(CFLAGS_RELEASE) $(INC_RELEASE) -c src/interf/y.tab.cpp -o $(OBJDIR_RELEASE)/src/interf/y.tab.o + +$(OBJDIR_RELEASE)/src/simul/event.o: src/simul/event.cpp + $(CXX) $(CFLAGS_RELEASE) $(INC_RELEASE) -c src/simul/event.cpp -o $(OBJDIR_RELEASE)/src/simul/event.o + +$(OBJDIR_RELEASE)/src/simul/schedule.o: src/simul/schedule.cpp + $(CXX) $(CFLAGS_RELEASE) $(INC_RELEASE) -c src/simul/schedule.cpp -o $(OBJDIR_RELEASE)/src/simul/schedule.o + +$(OBJDIR_RELEASE)/src/simul/simtime.o: src/simul/simtime.cpp + $(CXX) $(CFLAGS_RELEASE) $(INC_RELEASE) -c src/simul/simtime.cpp -o $(OBJDIR_RELEASE)/src/simul/simtime.o + +$(OBJDIR_RELEASE)/src/simul/simulate.o: src/simul/simulate.cpp + $(CXX) $(CFLAGS_RELEASE) $(INC_RELEASE) -c src/simul/simulate.cpp -o $(OBJDIR_RELEASE)/src/simul/simulate.o + +$(OBJDIR_RELEASE)/src/simuleau.o: src/simuleau.cpp + $(CXX) $(CFLAGS_RELEASE) $(INC_RELEASE) -c src/simuleau.cpp -o $(OBJDIR_RELEASE)/src/simuleau.o + +$(OBJDIR_RELEASE)/src/bpn/discretetransition.o: src/bpn/discretetransition.cpp + $(CXX) $(CFLAGS_RELEASE) $(INC_RELEASE) -c src/bpn/discretetransition.cpp -o $(OBJDIR_RELEASE)/src/bpn/discretetransition.o + +$(OBJDIR_RELEASE)/src/bpn/batch.o: src/bpn/batch.cpp + $(CXX) $(CFLAGS_RELEASE) $(INC_RELEASE) -c src/bpn/batch.cpp -o $(OBJDIR_RELEASE)/src/bpn/batch.o + +$(OBJDIR_RELEASE)/src/bpn/batchplace.o: src/bpn/batchplace.cpp + $(CXX) $(CFLAGS_RELEASE) $(INC_RELEASE) -c src/bpn/batchplace.cpp -o $(OBJDIR_RELEASE)/src/bpn/batchplace.o + +$(OBJDIR_RELEASE)/src/bpn/batchtransition.o: src/bpn/batchtransition.cpp + $(CXX) $(CFLAGS_RELEASE) $(INC_RELEASE) -c src/bpn/batchtransition.cpp -o $(OBJDIR_RELEASE)/src/bpn/batchtransition.o + +$(OBJDIR_RELEASE)/src/bpn/bpn.o: src/bpn/bpn.cpp + $(CXX) $(CFLAGS_RELEASE) $(INC_RELEASE) -c src/bpn/bpn.cpp -o $(OBJDIR_RELEASE)/src/bpn/bpn.o + +$(OBJDIR_RELEASE)/src/bpn/continuousplace.o: src/bpn/continuousplace.cpp + $(CXX) $(CFLAGS_RELEASE) $(INC_RELEASE) -c src/bpn/continuousplace.cpp -o $(OBJDIR_RELEASE)/src/bpn/continuousplace.o + +$(OBJDIR_RELEASE)/src/bpn/continuoustransition.o: src/bpn/continuoustransition.cpp + $(CXX) $(CFLAGS_RELEASE) $(INC_RELEASE) -c src/bpn/continuoustransition.cpp -o $(OBJDIR_RELEASE)/src/bpn/continuoustransition.o + +$(OBJDIR_RELEASE)/src/bpn/controllablebatch.o: src/bpn/controllablebatch.cpp + $(CXX) $(CFLAGS_RELEASE) $(INC_RELEASE) -c src/bpn/controllablebatch.cpp -o $(OBJDIR_RELEASE)/src/bpn/controllablebatch.o + +$(OBJDIR_RELEASE)/src/bpn/discreteplace.o: src/bpn/discreteplace.cpp + $(CXX) $(CFLAGS_RELEASE) $(INC_RELEASE) -c src/bpn/discreteplace.cpp -o $(OBJDIR_RELEASE)/src/bpn/discreteplace.o + +$(OBJDIR_RELEASE)/src/bpn/arc.o: src/bpn/arc.cpp + $(CXX) $(CFLAGS_RELEASE) $(INC_RELEASE) -c src/bpn/arc.cpp -o $(OBJDIR_RELEASE)/src/bpn/arc.o + +$(OBJDIR_RELEASE)/src/bpn/firingquantity.o: src/bpn/firingquantity.cpp + $(CXX) $(CFLAGS_RELEASE) $(INC_RELEASE) -c src/bpn/firingquantity.cpp -o $(OBJDIR_RELEASE)/src/bpn/firingquantity.o + +$(OBJDIR_RELEASE)/src/bpn/flow.o: src/bpn/flow.cpp + $(CXX) $(CFLAGS_RELEASE) $(INC_RELEASE) -c src/bpn/flow.cpp -o $(OBJDIR_RELEASE)/src/bpn/flow.o + +$(OBJDIR_RELEASE)/src/bpn/node.o: src/bpn/node.cpp + $(CXX) $(CFLAGS_RELEASE) $(INC_RELEASE) -c src/bpn/node.cpp -o $(OBJDIR_RELEASE)/src/bpn/node.o + +$(OBJDIR_RELEASE)/src/bpn/place.o: src/bpn/place.cpp + $(CXX) $(CFLAGS_RELEASE) $(INC_RELEASE) -c src/bpn/place.cpp -o $(OBJDIR_RELEASE)/src/bpn/place.o + +$(OBJDIR_RELEASE)/src/bpn/transition.o: src/bpn/transition.cpp + $(CXX) $(CFLAGS_RELEASE) $(INC_RELEASE) -c src/bpn/transition.cpp -o $(OBJDIR_RELEASE)/src/bpn/transition.o + +$(OBJDIR_RELEASE)/src/bpn/triangularbatchplace.o: src/bpn/triangularbatchplace.cpp + $(CXX) $(CFLAGS_RELEASE) $(INC_RELEASE) -c src/bpn/triangularbatchplace.cpp -o $(OBJDIR_RELEASE)/src/bpn/triangularbatchplace.o + +clean_release: + rm -f $(OBJ_RELEASE) $(OUT_RELEASE) + rm -rf bin/Release + rm -rf $(OBJDIR_RELEASE)/src/simul + rm -rf $(OBJDIR_RELEASE)/src/interf + rm -rf $(OBJDIR_RELEASE)/src + rm -rf $(OBJDIR_RELEASE)/src/bpn + +.PHONY: before_debug after_debug clean_debug before_release after_release clean_release + diff --git a/bin/.DS_Store b/bin/.DS_Store new file mode 100644 index 0000000000000000000000000000000000000000..9f49df576945f7892a40e0707fb79bb3aff92ebd Binary files /dev/null and b/bin/.DS_Store differ diff --git a/bin/Release/simuleau b/bin/Release/simuleau new file mode 100755 index 0000000000000000000000000000000000000000..d60f74df50c333b2e52f788fdd5a0e9cf9dcf8c7 Binary files /dev/null and b/bin/Release/simuleau differ diff --git a/examples/batch1.bpn b/examples/batch1.bpn new file mode 100644 index 0000000000000000000000000000000000000000..74da0251486a53716388fe6659e8d1c13877a20b --- /dev/null +++ b/examples/batch1.bpn @@ -0,0 +1,47 @@ +// pure continuous petri net with constant speed. + + +model test; +length unity= m ; +time unity = m; + +network description +places + + place CP1 (continuous) + initial marking {8} + steady marking {8} + output arc T1 + output arc T2 (3) + + place CP2 (continuous) + initial marking {2} + steady marking {3} + output arc T2 + + place BP3 (batch) + function (2,4,5) + initial marking {(3,2,5)} + steady marking {(5,1,5)} + output arc T3 + +transitions + + transition T1 (batch) + flow (1) + steady flow (1) + output arc CP2 + + transition T2 (batch) + flow (1) + steady flow (1) + output arc CP1 (2) + output arc BP3 (2) + + transition T3 (batch) + flow (2) + steady flow (2) + output arc CP1 + + + diff --git a/examples/batch11.bpn b/examples/batch11.bpn new file mode 100644 index 0000000000000000000000000000000000000000..ba81805e153f20872d696839bfa27ff6a6f11d92 --- /dev/null +++ b/examples/batch11.bpn @@ -0,0 +1,44 @@ +model test; +length unity= m ; +time unity = m; + +network description +places + + place CP1 (continuous) + initial marking {8} + steady marking {8} + output arc T1 + output arc T2 (3) + + place CP2 (continuous) + initial marking {2} + steady marking {3} + output arc T2 + + place BP3 (batch) + function (2,4,5) + initial marking {(1.5,4,4)} + steady marking {(5,1,5)} + output arc T3 + +transitions + + transition T1 (batch) + flow (1) + steady flow (1) + output arc CP2 + + transition T2 (batch) + flow (1) + steady flow (1) + output arc CP1 (2) + output arc BP3 (2) + + transition T3 (batch) + flow (2) + steady flow (2) + output arc CP1 + + + diff --git a/examples/batch111.bpn b/examples/batch111.bpn new file mode 100644 index 0000000000000000000000000000000000000000..9af0b1df4c3be046a7dd708a1f2c9192e6adad35 --- /dev/null +++ b/examples/batch111.bpn @@ -0,0 +1,47 @@ +// pure continuous petri net with constant speed. + + +model test; +length unity= m ; +time unity = m; + +network description +places + + place CP1 (continuous) + initial marking {8} + steady marking {8} + output arc T1 + output arc T2 (3) + + place CP2 (continuous) + initial marking {2} + steady marking {3} + output arc T2 + + place BP3 (batch) + function (2,2,5) + initial marking {(3,2,5)} + steady marking {(5,1,5)} + output arc T3 + +transitions + + transition T1 (batch) + flow (1) + steady flow (1) + output arc CP2 + + transition T2 (batch) + flow (1) + steady flow (1) + output arc CP1 (2) + output arc BP3 (2) + + transition T3 (batch) + flow (2) + steady flow (2) + output arc CP1 + + + diff --git a/examples/batch2.bpn b/examples/batch2.bpn new file mode 100644 index 0000000000000000000000000000000000000000..78f3c99489630612548db12fba5c8243519b4b9d --- /dev/null +++ b/examples/batch2.bpn @@ -0,0 +1,47 @@ +// batch petri net without discrete nodes. + +model test; +length unity= m ; +time unity = m; + +network description +places + + place BP2 (batch) + function (2, 4, 2) // speed, density, length + initial marking {(0.5,0.2,2),(0.3,2,1.5),(1.2,4,1.2)} //length, density, poistion + steady marking {(1,4,2),(1,1,1)} + output arc T2 + + place BP3 (batch) + function (2, 4, 2) // speed, density, length + initial marking {(1,4,1)} //length, density, poistion + steady marking {(1,4,2),(1,1,1)} + output arc T3 + + + place CP1 (continuous) + initial marking {5.5} + steady marking {5} + output arc T1 + +transitions + + transition T1 (batch) + flow (4) + steady flow (2) + output arc BP2 + + transition T2 (batch) + flow (2) + steady flow (2) + output arc BP3 + + transition T3 (batch) + flow (2) + steady flow (2) + output arc CP1 + + + + diff --git a/examples/batch21.bpn b/examples/batch21.bpn new file mode 100644 index 0000000000000000000000000000000000000000..cbbbd3132505abdc28d91c128aac3917c88391df --- /dev/null +++ b/examples/batch21.bpn @@ -0,0 +1,47 @@ +// batch petri net + +model test; +length unity= m ; +time unity = m; + +network description +places + + place BP2 (batch) + function (2, 4, 2) // speed, density, length + initial marking {(0.2,0.5,2),(0.3,2,1.5),(1.2,4,1.2)} //length, density, poistion + steady marking {(1,4,2),(1,1,1)} + output arc T2 + + place BP3 (batch) + function (2, 4, 2) // speed, density, length + initial marking {(1,4,1)} //length, density, poistion + steady marking {(1,4,2),(1,1,1)} + output arc T3 + + + place CP1 (continuous) + initial marking {5.5} + steady marking {5} + output arc T1 + +transitions + + transition T1 (batch) + flow (4) + steady flow (2) + output arc BP2 + + transition T2 (batch) + flow (2) + steady flow (2) + output arc BP3 + + transition T3 (batch) + flow (2) + steady flow (2) + output arc CP1 + + + + diff --git a/examples/batch22.bpn b/examples/batch22.bpn new file mode 100644 index 0000000000000000000000000000000000000000..7cbc0b56c8c4fdd6240458aaf04a284cd5cd7d8a --- /dev/null +++ b/examples/batch22.bpn @@ -0,0 +1,48 @@ +// batch petri net +// + +model test; +length unity= m ; +time unity = m; + +network description +places + + place BP2 (batch) + function (2, 4, 2) // speed, density, length + initial marking {(0.2,0.5,2),(0.2,2.5,1.5),(1.2,4,1.2)} //length, density, poistion + steady marking {(1,4,2),(1,1,1)} + output arc T2 + + place BP3 (batch) + function (2, 8, 1) // speed, density, length + initial marking {(0.5,8,0.5)} //length, density, poistion + steady marking {(0.5,8,1),(0.5,1,0.5)} + output arc T3 + + + place CP1 (continuous) + initial marking {5.1} + steady marking {5} + output arc T1 + +transitions + + transition T1 (batch) + flow (4) + steady flow (2) + output arc BP2 + + transition T2 (batch) + flow (2) + steady flow (2) + output arc BP3 + + transition T3 (batch) + flow (2) + steady flow (2) + output arc CP1 + + + + diff --git a/examples/batch23.bpn b/examples/batch23.bpn new file mode 100644 index 0000000000000000000000000000000000000000..9af3624a3842a510d2a021aed96823168e9e97f9 --- /dev/null +++ b/examples/batch23.bpn @@ -0,0 +1,47 @@ +// batch petri net + +model test; +length unity= m ; +time unity = m; + +network description +places + + place BP2 (batch) + function (2, 8, 1) // speed, density, length + initial marking {(0.2,0.5,1),(0.15,4,0.75),(0.55,8,0.55)} //length, density, poistion + steady marking {(0.5,8,1),(0.5,1,0.5)} + output arc T2 + + place BP3 (batch) + function (2, 4, 2) // speed, density, length + initial marking {(1,4,1)} //length, density, poistion + steady marking {(1,4,2),(1,1,1)} + output arc T3 + + + place CP1 (continuous) + initial marking {5.4} + steady marking {5} + output arc T1 + +transitions + + transition T1 (batch) + flow (4) + steady flow (2) + output arc BP2 + + transition T2 (batch) + flow (2) + steady flow (2) + output arc BP3 + + transition T3 (batch) + flow (2) + steady flow (2) + output arc CP1 + + + + diff --git a/examples/batch24.bpn b/examples/batch24.bpn new file mode 100644 index 0000000000000000000000000000000000000000..68b1fd4290b4f545ef3d89b440e81a95c4399977 --- /dev/null +++ b/examples/batch24.bpn @@ -0,0 +1,47 @@ +// batch petri net + +model test; +length unity= m ; +time unity = m; + +network description +places + + place BP2 (batch) + function (2, 8, 1) // speed, density, length + initial marking {(0.2,0.5,1),(0.1,5,0.8),(0.5,8,0.5)} //length, density, poistion + steady marking {(0.5,8,1),(0.5,1,0.5)} + output arc T2 + + place BP3 (batch) + function (2, 8, 1) // speed, density, length + initial marking {(0.5,8,1)} //length, density, poistion + steady marking {(0.5,8,1),(0.5,1,0.5)} + output arc T3 + + + place CP1 (continuous) + initial marking {5.4} + steady marking {5} + output arc T1 + +transitions + + transition T1 (batch) + flow (4) + steady flow (2) + output arc BP2 + + transition T2 (batch) + flow (2) + steady flow (2) + output arc BP3 + + transition T3 (batch) + flow (2) + steady flow (2) + output arc CP1 + + + + diff --git a/examples/batch25.bpn b/examples/batch25.bpn new file mode 100644 index 0000000000000000000000000000000000000000..24a8c90b32a9950e66d8d3d1e17bb4cafec8adfe --- /dev/null +++ b/examples/batch25.bpn @@ -0,0 +1,47 @@ +// batch petri net + +model test; +length unity= m ; +time unity = m; + +network description +places + + place BP2 (batch) + function (20, 80, 10) // speed, density, length + initial marking {(2,5,10),(1,50,8),(5,80,5)} //length, density, poistion + steady marking {(5,80,10),(5,10,5)} + output arc T2 + + place BP3 (batch) + function (20, 80, 10) // speed, density, length + initial marking {(5,80,10)} //length, density, poistion + steady marking {(5,80,10),(5,10,5)} + output arc T3 + + + place CP1 (continuous) + initial marking {90} + steady marking {50} + output arc T1 + +transitions + + transition T1 (batch) + flow (400) + steady flow (200) + output arc BP2 + + transition T2 (batch) + flow (200) + steady flow (200) + output arc BP3 + + transition T3 (batch) + flow (200) + steady flow (200) + output arc CP1 + + + + diff --git a/examples/batch26.bpn b/examples/batch26.bpn new file mode 100644 index 0000000000000000000000000000000000000000..65162cfa0d124bb4fed8e92a9fdb63e8fb247856 --- /dev/null +++ b/examples/batch26.bpn @@ -0,0 +1,47 @@ +// batch petri net + +model test; +length unity= m ; +time unity = m; + +network description +places + + place BP2 (batch) + function (2, 8, 1) // speed, density, length + initial marking {(0.2,0.5,1),(0.1,5,0.8),(0.2,0.5,0.7),(0.1,7,0.5),(0.4,8,0.4)} //length, density, poistion + steady marking {(0.5,8,1),(0.5,1,0.5)} + output arc T2 + + place BP3 (batch) + function (2, 8, 1) // speed, density, length + initial marking {(0.5,8,1)} //length, density, poistion + steady marking {(0.5,8,1),(0.5,1,0.5)} + output arc T3 + + + place CP1 (continuous) + initial marking {5.4} + steady marking {5} + output arc T1 + +transitions + + transition T1 (batch) + flow (4) + steady flow (2) + output arc BP2 + + transition T2 (batch) + flow (2) + steady flow (2) + output arc BP3 + + transition T3 (batch) + flow (2) + steady flow (2) + output arc CP1 + + + + diff --git a/examples/batch27.bpn b/examples/batch27.bpn new file mode 100644 index 0000000000000000000000000000000000000000..d57f233fdcc6dfa398eba0247ed2689bc95733ea --- /dev/null +++ b/examples/batch27.bpn @@ -0,0 +1,47 @@ +// batch petri net +// bp2 > 0.5 +model test; +length unity= m ; +time unity = m; + +network description +places + + place BP2 (batch) + function (2, 2, 0.4) // speed, density, length + initial marking {(0.1,0.5,0.4),(0.05,1.5,0.25),(0.2,2,0.2)} //length, density, poistion + steady marking {(0.1,2,0.4),(0.3,1,0.3)} + output arc T2 + + place BP3 (batch) + function (2, 8, 1) // speed, density, length + initial marking {(0.5,8,0.5)} //length, density, poistion + steady marking {(0.5,8,1),(0.5,1,0.5)} + output arc T3 + + + place CP1 (continuous) + initial marking {5.25} + steady marking {5} + output arc T1 + +transitions + + transition T1 (batch) + flow (4) + steady flow (2) + output arc BP2 + + transition T2 (batch) + flow (2) + steady flow (2) + output arc BP3 + + transition T3 (batch) + flow (2) + steady flow (2) + output arc CP1 + + + + diff --git a/examples/bp.bpn b/examples/bp.bpn new file mode 100644 index 0000000000000000000000000000000000000000..8bd37f0d305f1ccba56062ba9f3d69c20f99b41d --- /dev/null +++ b/examples/bp.bpn @@ -0,0 +1,27 @@ +// test batch transitions + +model batch_transitions; +length unity= m ; +time unity = s; + +network description +places + place PB1 (batch) + initial marking {1} + output arc TC1 + + place PC2 (continuous) + initial marking {1} + output arc TC2 + + +transitions + transition TC1 (continuous) + flow (2) + output arc PC2 + + transition TC2 (continuous) + flow (3) + output arc PC1 + + diff --git a/examples/bpn1.bpn b/examples/bpn1.bpn new file mode 100644 index 0000000000000000000000000000000000000000..82e91979e12ba7171175aaa42908158196af99a3 --- /dev/null +++ b/examples/bpn1.bpn @@ -0,0 +1,17 @@ +// batch petri net + +model test; +length unity= m ; +time unity = s; + +network description +places + place PB (batch) + function (120, 200, 10) // speed, density, length + initial marking { (2, 150, 4), (1, 100, 1)} //length, density, position + output arc T1 + +transitions + transition T1 (batch) + flow (4000) + diff --git a/examples/bpn2.bpn b/examples/bpn2.bpn new file mode 100644 index 0000000000000000000000000000000000000000..8bd0f70986dd7c38265ea5f8e113f194e7e1100d --- /dev/null +++ b/examples/bpn2.bpn @@ -0,0 +1,21 @@ +// batch petri net + +model test; +length unity= m ; +time unity = s; + +network description +places + place BP (batch) + function (100, 200, 10) // speed, density, length + initial marking {} //length, density, poistion + output arc TOut + +transitions + transition TIn (batch) + flow (100000) + output arc BP + + transition TOut (batch) + flow (10000) + diff --git a/examples/bpn3.bpn b/examples/bpn3.bpn new file mode 100644 index 0000000000000000000000000000000000000000..e146190cb52c9c8002cbc7498cf03f2eddb84319 --- /dev/null +++ b/examples/bpn3.bpn @@ -0,0 +1,26 @@ +// batch petri net + +model test; +length unity= m ; +time unity = s; + +network description +places + place BP (batch) + function (100, 200, 10) // speed, density, length + initial marking {} //length, density, poistion + output arc TOut + + place CP (continuous) + initial marking {2000} + output arc TIn + +transitions + transition TIn (batch) + flow (100000) + output arc BP + + transition TOut (batch) + flow (10000) + output arc CP + diff --git a/examples/bpn4.bpn b/examples/bpn4.bpn new file mode 100644 index 0000000000000000000000000000000000000000..bfb14c981f4f353a190dd1beec64da448886e9f8 --- /dev/null +++ b/examples/bpn4.bpn @@ -0,0 +1,39 @@ +// batch petri net + +model test; +length unity= m ; +time unity = s; + +network description +places + place BP (batch) + function (5, 15, 15) // speed, density, length + initial marking {} //length, density, poistion + output arc CTOut + + place CPCap (continuous) + initial marking {225} + output arc CTIn + + place CPIn (continuous) + initial marking {175} + output arc CTIn + + place CPOut (continuous) + initial marking {0} + + +transitions + transition DTIn (discrete) + timing (4) + output arc CPIn (40) + + transition CTIn (batch) + flow (70) + output arc BP + + transition CTOut (batch) + flow (30) + output arc CPCap + output arc CPOut + diff --git a/examples/bpn5.bpn b/examples/bpn5.bpn new file mode 100644 index 0000000000000000000000000000000000000000..7a8077a454f6029c5f7a1f46d81bc32a4f8067b5 --- /dev/null +++ b/examples/bpn5.bpn @@ -0,0 +1,53 @@ +// batch petri net + +model test; +length unity= m ; +time unity = m; + +network description +places + place CPIn (continuous) + initial marking {150} + output arc BTIn + + place BP1 (batch) + function (4, 15, 12) // speed, density, length + initial marking {} //length, density, poistion + output arc BTMid + + place CPCap1 (continuous) + initial marking {180} + output arc BTIn + + place BP2 (batch) + function (5, 15, 20) // speed, density, length + initial marking {} //length, density, poistion + output arc BTOut + + place CPCap2 (continuous) + initial marking {300} + output arc BTMid + + place CPOut (continuous) + initial marking {} + + +transitions + transition DTIn (discrete) + timing (2) + output arc CPIn (80) + + transition BTIn (batch) + flow (55) + output arc BP1 + + transition BTMid (batch) + flow (80) + output arc BP2 + output arc CPCap1 + + transition BTOut (batch) + flow (30) + output arc CPCap2 + output arc CPOut + diff --git a/examples/bpn6.bpn b/examples/bpn6.bpn new file mode 100644 index 0000000000000000000000000000000000000000..96b87a3058b0fdbd1625caa295aa45109b947c5b --- /dev/null +++ b/examples/bpn6.bpn @@ -0,0 +1,21 @@ +// batch petri net + +model test; +length unity= m ; +time unity = s; + +network description +places + place BP (batch) + function (100, 200, 10) // speed, density, length + initial marking {} //length, density, poistion + output arc TOut + +transitions + transition TIn (batch) + flow (15000) + output arc BP + + transition TOut (batch) + flow (10000) + diff --git a/examples/control.bpn b/examples/control.bpn new file mode 100644 index 0000000000000000000000000000000000000000..950e04620c798d992dc9660324d591232c7a1e9a --- /dev/null +++ b/examples/control.bpn @@ -0,0 +1,51 @@ +// batch petri net + +model test; +length unity= m ; +time unity = m; + +network description +places + + place BP3 (batch) + function (1, 2, 4) // speed, density, length + initial marking {} //length, density, poistion + steady marking {(4,1,4)} + output arc T2 + + place BP4 (batch) + function (1, 2, 5) // speed, density, length + initial marking {} //length, density, poistion + steady marking {(3,2,5),(2,1,2)} + output arc T3 + + + place CP1 (continuous) + initial marking {8} + steady marking {4} + output arc T1 + + place CP2 (continuous) + initial marking {8} + steady marking {0} + output arc T2 + +transitions + + transition T1 (batch) + flow (2) + steady flow (1) + output arc BP3 + + transition T2 (batch) + flow (2) + steady flow (1) + output arc BP4 + output arc CP1 + + transition T3 (batch) + flow (1) + steady flow (1) + output arc CP2 + + diff --git a/examples/cpn2p.bpn b/examples/cpn2p.bpn new file mode 100644 index 0000000000000000000000000000000000000000..e75af7dec859c7845c8c17b07bc08bb9f864c38a --- /dev/null +++ b/examples/cpn2p.bpn @@ -0,0 +1,30 @@ +// test continuous petri net + +model continuous_places_transitions; +length unity= m ; +time unity = s; + +network description +places + place PC1 (continuous) + initial marking {0} + output arc TC1 (3) + output arc TC2 (2) + + place PC2 (continuous) + initial marking {100} + output arc TC3 + +transitions + transition TC1 (continuous) + flow (2) + output arc PC2 + + transition TC2 (continuous) + flow (3) + output arc PC2 + + transition TC3 (continuous) + flow (1) + output arc PC1 + diff --git a/examples/cpn5p.bpn b/examples/cpn5p.bpn new file mode 100644 index 0000000000000000000000000000000000000000..83757e7acb206e960cca8e7286ca6bea96248f78 --- /dev/null +++ b/examples/cpn5p.bpn @@ -0,0 +1,47 @@ +// test continuous petri net + +model continuous_places_transitions; +length unity= m ; +time unity = s; + +network description +places + place PC1 (continuous) + initial marking {5} + output arc TC1 + + place PC2 (continuous) + initial marking {10} + output arc TC1 + output arc TC2 + + place PC3 (continuous) + initial marking {5} + output arc TC2 + + place PC4 (continuous) + initial marking {0} + output arc TC3 + + place PC5 (continuous) + initial marking {0} + output arc TC4 + +transitions + transition TC1 (continuous) + flow (3) + output arc PC4 + + transition TC2 (continuous) + flow (1) + output arc PC5 + + transition TC3 (continuous) + flow (2) + output arc PC1 + output arc PC2 + + transition TC4 (continuous) + flow (5) + output arc PC2 + output arc PC3 diff --git a/examples/ct.bpn b/examples/ct.bpn new file mode 100644 index 0000000000000000000000000000000000000000..068e617a68cfacb81c38774c1c03c17d23fc3c74 --- /dev/null +++ b/examples/ct.bpn @@ -0,0 +1,27 @@ +// test continuous transitions + +model continuous_transitions; +length unity= m ; +time unity = s; + +network description +places + place PC1 (continuous) + initial marking {1} + output arc TC1 + + place PC2 (continuous) + initial marking {1} + output arc TC2 + + +transitions + transition TC1 (continuous) + flow (2) + output arc PC2 + + transition TC2 (continuous) + flow (3) + output arc PC1 + + diff --git a/examples/discretetransition.bpn b/examples/discretetransition.bpn new file mode 100644 index 0000000000000000000000000000000000000000..4e0627765237d99fde7816a546a85b253a23fb65 --- /dev/null +++ b/examples/discretetransition.bpn @@ -0,0 +1,27 @@ +// test discrete transitions + +model discrete_transitions; +length unity= m ; +time unity = s; + +network description +places + place PD1 (discrete) + initial marking {1} + output arc TD1 + + place PD2 (discrete) + initial marking {1} + output arc TD2 + + +transitions + transition TD1 (discrete) + timing (2) + output arc PD2 + + transition TD2 (discrete) + timing (3) + output arc PD1 + + diff --git a/examples/discretetransition.in b/examples/discretetransition.in new file mode 100644 index 0000000000000000000000000000000000000000..0315137a6f301285f7ba8d99b12101f07dd0e0e6 --- /dev/null +++ b/examples/discretetransition.in @@ -0,0 +1,12 @@ +1 +1 +discretetransition +2 +1 +x +y +10 +0 + + + diff --git a/examples/dpn_1p.bpn b/examples/dpn_1p.bpn new file mode 100644 index 0000000000000000000000000000000000000000..472023be8ddf3bfefdd9c1fde6ec3d93e86daa10 --- /dev/null +++ b/examples/dpn_1p.bpn @@ -0,0 +1,24 @@ +// test discrete petri net + +model discrete_places_transitions; +length unity= m ; +time unity = s; + +network description +places + place PD1 (discrete) + initial marking {6} + output arc TD1 (3) + output arc TD2 (2) + + +transitions + transition TD1 (discrete) + timing (3) + output arc PD1 + + transition TD2 (discrete) + timing (2) + output arc PD1 + + diff --git a/examples/dpn_3p.bpn b/examples/dpn_3p.bpn new file mode 100644 index 0000000000000000000000000000000000000000..92d335e2d03f4739cca80083a0e3ab8a50c9ac79 --- /dev/null +++ b/examples/dpn_3p.bpn @@ -0,0 +1,35 @@ +// test discrete petri net + +model discrete_places_transitions; +length unity= m ; +time unity = s; + +network description +places + place PD1 (discrete) + initial marking {1} + output arc TD1 + + place PD2 (discrete) + initial marking {0} + output arc TD2 + + place PD3 (discrete) + initial marking {0} + output arc TD3 + + +transitions + transition TD1 (discrete) + timing (0) + output arc PD2 + + transition TD2 (discrete) + timing (0) + output arc PD3 + + transition TD3 (discrete) + timing (3) + output arc PD1 + + diff --git a/examples/dpn_4p.bpn b/examples/dpn_4p.bpn new file mode 100644 index 0000000000000000000000000000000000000000..927b284d041fe4e39324ceecdd37bd2c93c42a5e --- /dev/null +++ b/examples/dpn_4p.bpn @@ -0,0 +1,37 @@ +// test discrete petri net + +model discrete_places_transitions; +length unity= m ; +time unity = s; + +network description +places + place PD1 (discrete) + initial marking {2} + output arc TD1 + + place PD2 (discrete) + initial marking {0} + output arc TD2 + + place PD3 (discrete) + initial marking {1} + output arc TD1 + + place PD4 (discrete) + initial marking {1} + output arc TD2 + + +transitions + transition TD1 (discrete) + timing (2) + output arc PD2 + output arc PD3 + + transition TD2 (discrete) + timing (3) + output arc PD1 + output arc PD4 + + diff --git a/examples/fig12.bpn b/examples/fig12.bpn new file mode 100644 index 0000000000000000000000000000000000000000..4db0df751045fc03094fa50b9be80cf7e4ed484f --- /dev/null +++ b/examples/fig12.bpn @@ -0,0 +1,82 @@ +// pure continuous petri net with constant speed. + + +model test; +length unity= m ; +time unity = m; + +network description +places + + place CP1 (continuous) + initial marking {1} + steady marking {0} + output arc T1 + output arc T2 + + place CP2 (continuous) + initial marking {1} + steady marking {2} + output arc T1 + output arc T3 + + place CP3 (continuous) + initial marking {0} + steady marking {0} + output arc T2 + output arc T3 + + place CP4 (continuous) + initial marking {0} + steady marking {0} + output arc T4 + + + place CP5 (continuous) + initial marking {0} + steady marking {0} + output arc T5 + + place CP6 (continuous) + initial marking {0} + steady marking {0} + output arc T6 + +transitions + + transition T1 (continuous) + flow (1) + steady flow (1) + output arc CP4 + + transition T2 (continuous) + flow (1) + steady flow (1) + output arc CP5 + + transition T3 (continuous) + flow (2) + steady flow (1) + output arc CP6 + + transition T4 (continuous) + flow (1) + steady flow (1) + output arc CP1 + output arc CP3 + + + transition T5 (continuous) + flow (1) + steady flow (1) + output arc CP2 + output arc CP3 + + + transition T6 (continuous) + flow (1) + steady flow (1) + output arc CP1 + output arc CP2 + + diff --git a/examples/gbpn1.bpn b/examples/gbpn1.bpn new file mode 100644 index 0000000000000000000000000000000000000000..a7191fce999151a8e266171332545370339cd277 --- /dev/null +++ b/examples/gbpn1.bpn @@ -0,0 +1,77 @@ +//generalised batch petri net with controllable transfer speed + +model test; +length unity= m ; +time unity = s; + +network description +places + place BP1 (batch) + function (10, 3, 3) // speed, density, length + initial marking {} //length, density, poistion + output arc BT2 + output arc BT3 + + place BP2 (batch) + function (1, 3, 1) // speed, density, length + initial marking {} //length, density, poistion + output arc BT4 + + place BP3 (batch) + function (5, 3, 2) + initial marking {} + output arc BT5 + + place CP4 (continuous) + initial marking {3} + output arc BT1 + + place CP5 (continuous) + initial marking {1} + output arc BT2 + + place CP6 (continuous) + initial marking {3} + output arc BT3 + + + +transitions + transition BT1 (batch) + flow (4) + output arc BP1 + + transition BT2 (batch) + flow (2) + output arc BP2 + output arc CP4 + + transition BT3 (batch) + flow (2) + output arc BP3 + output arc CP4 + + transition BT4 (batch) + flow (4) + output arc CP5 + + transition BT5 (batch) + flow (4) + output arc CP6 + + + + + + + + + + + + + + + + + diff --git a/examples/hpn3p.bpn b/examples/hpn3p.bpn new file mode 100644 index 0000000000000000000000000000000000000000..e813ec898bee9d62e7a506e75e24ebac73d138f3 --- /dev/null +++ b/examples/hpn3p.bpn @@ -0,0 +1,33 @@ +// test hybrid petri net + +model hybrid_places_transitions; +length unity= m ; +time unity = s; + +network description +places + place PD1 (discrete) + initial marking {2} + output arc TD1 (2) + + place PC2 (continuous) + initial marking {0} + output arc TC2 + + place PC3 (continuous) + initial marking {0} + output arc TD3 (5) + +transitions + transition TD1 (discrete) + timing (3) + output arc PC2 (10) + + transition TC2 (continuous) + flow (1) + output arc PC3 + + transition TD3 (discrete) + timing (2) + output arc PD1 + diff --git a/examples/hpn5p.bpn b/examples/hpn5p.bpn new file mode 100644 index 0000000000000000000000000000000000000000..9c8e25dc4f4457b439f1579a4387384e4cd33cff --- /dev/null +++ b/examples/hpn5p.bpn @@ -0,0 +1,40 @@ +// test hybrid petri net + +model continuous_places_hybrid_transitions; +length unity= m ; +time unity = s; + +network description +places + place PC1 (continuous) + initial marking {40} + output arc TC1 + + place PC2 (continuous) + initial marking {0} + output arc TD2 (0.00000000001) + + place PC3 (continuous) + initial marking {0} + output arc TC3 + + place PC4 (continuous) + initial marking {0} + + place PC5 (continuous) + initial marking {100} + output arc TC1 + +transitions + transition TC1 (continuous) + flow (50) + output arc PC2 + + transition TD2 (discrete) + timing (2) + output arc PC3 (0.00000000001) + + transition TC3 (continuous) + flow (50) + output arc PC4 + output arc PC5 diff --git a/examples/lego.bpn b/examples/lego.bpn new file mode 100644 index 0000000000000000000000000000000000000000..9b1c3bd9abe9313e1a9211598349acf0306a3ab9 --- /dev/null +++ b/examples/lego.bpn @@ -0,0 +1,70 @@ +// BPN file generated by FreewayLEGO +model lego; +length unity = km; +time unity = h; + +network description +places + place PL_1(triangular) + function (0, 1000, 70, 0) + initial marking {} + output arc TL_1_3 + + place PL_2(triangular) + function (0, 1000, 70, 0) + initial marking {} + output arc TL_2_3 + + place PL0_3(triangular) + function (0, 1000, 130, 0) + initial marking {} + output arc TL_3_I1 + + place PL1_3(triangular) + function (0, 1000, 130, 0) + initial marking {} + output arc TL_3_I2 + + place PL2_3(triangular) + function (0, 1000, 130, 0) + initial marking {} + output arc TL_3_4 + + place PL_4(triangular) + function (0, 1000, 70, 0) + initial marking {} + output arc TL_4_S + + +transitions + transition TL_1_E(batch) + flow (0) + output arc PL_1 + + transition TL_1_3(batch) + flow (0) + output arc PL0_3 + + transition TL_2_E(batch) + flow (0) + output arc PL_2 + + transition TL_2_3(batch) + flow (0) + output arc PL1_3 + + transition TL_3_4(batch) + flow (0) + output arc PL_4 + + transition TL_3_I1(batch) + flow (0) + output arc PL2_3 + + transition TL_3_I2(batch) + flow (0) + output arc PL2_3 + + transition TL_4_S(batch) + flow (0) + diff --git a/examples/optimal.bpn b/examples/optimal.bpn new file mode 100644 index 0000000000000000000000000000000000000000..8e937ef65070db33ea3c8281aa6a18b378260542 --- /dev/null +++ b/examples/optimal.bpn @@ -0,0 +1,53 @@ +// batch petri net +// bp2 > 0.5 +model test; +length unity= m ; +time unity = m; + +network description +places + + place BP3 (batch) + function (2, 2, 4) // speed, density, length + initial marking {(4,1,4)} //length, density, poistion + steady marking {(4,1,4)} + output arc T2 + + place BP4 (batch) + function (2, 2, 4) // speed, density, length + initial marking {(3,2,4)} //length, density, poistion + steady marking {(1,2,4),(3,1,3)} + output arc T3 + + + place CP1 (continuous) + initial marking {4} + steady marking {4} + output arc T1 + + place CP2 (continuous) + initial marking {4} + steady marking {5} + output arc T2 + +transitions + + transition T1 (batch) + flow (4) + steady flow (2) + output arc BP3 + + transition T2 (batch) + flow (2) + steady flow (2) + output arc BP4 + output arc CP1 + + transition T3 (batch) + flow (2) + steady flow (2) + output arc CP2 + + + + diff --git a/examples/periodic1.bpn b/examples/periodic1.bpn new file mode 100644 index 0000000000000000000000000000000000000000..b85f1499da2dd688b279a29ad45f3f274706013d --- /dev/null +++ b/examples/periodic1.bpn @@ -0,0 +1,51 @@ +// batch petri net + +model test; +length unity= m ; +time unity = m; + +network description +places + + place BP3 (batch) + function (1, 2, 4) // speed, density, length + initial marking {} //length, density, poistion + steady marking {(4,1,4)} + output arc T2 + + place BP4 (batch) + function (1, 2, 5) // speed, density, length + initial marking {} //length, density, poistion + steady marking {(3,2,5),(2,1,2)} + output arc T3 + + + place CP1 (continuous) + initial marking {3} + steady marking {4} + output arc T1 + + place CP2 (continuous) + initial marking {3} + steady marking {0} + output arc T2 + +transitions + + transition T1 (batch) + flow (2) + steady flow (1) + output arc BP3 + + transition T2 (batch) + flow (2) + steady flow (1) + output arc BP4 + output arc CP1 + + transition T3 (batch) + flow (1) + steady flow (1) + output arc CP2 + + diff --git a/examples/petrinets.bpn b/examples/petrinets.bpn new file mode 100644 index 0000000000000000000000000000000000000000..b779b59585708c4105d7cb36d710373aab61abef --- /dev/null +++ b/examples/petrinets.bpn @@ -0,0 +1,52 @@ +// double "/" for comments +model example; +length unity=km; +time unity=h; + + +network description + places + place DPlace (discrete) + initial marking {2} // integer value + output arc DTransition // 2 is the weight of the arc + + place CPlace (continuous) + initial marking {2.3} // real value + output arc CTransition // if no specified weight is 1 + + place BPlace (batch) + function (110, 200, 10) // speed, max density, and length + initial marking {(1.2, 150, 2)} + // list of initial batches {(length, density, position), ..} + output arc BTransition + + transitions + transition DTransition (discrete) + timing (4) // real value + output arc CPlace + + transition CTransition (continuous) + flow (2.0) // real value + output arc BPlace + + transition BTransition (batch) + flow (200.0) // real value + + + + + + + + + + + + + + + + + + + diff --git a/examples/pn_discrets.bpn b/examples/pn_discrets.bpn new file mode 100644 index 0000000000000000000000000000000000000000..6920813cf5b0b5aca408039b0fcc01ceda1c6805 --- /dev/null +++ b/examples/pn_discrets.bpn @@ -0,0 +1,27 @@ +// test discrete petri net + +model discrete_places_transitions; +length unity= m ; +time unity = s; + +network description +places + place PD1 (discrete) + initial marking {1} + output arc TD1 + + place PD2 (discrete) + initial marking {1} + output arc TD2 + + +transitions + transition TD1 (discrete) + timing (2) + output arc PD2 + + transition TD2 (discrete) + timing (3) + output arc PD1 + + diff --git a/examples/pureCPN.bpn b/examples/pureCPN.bpn new file mode 100644 index 0000000000000000000000000000000000000000..b8116ddd1e537d1be426d770c7e430b098e4d2cd --- /dev/null +++ b/examples/pureCPN.bpn @@ -0,0 +1,47 @@ +// pure continuous petri net with constant speed. + + +model test; +length unity= m ; +time unity = m; + +network description +places + + place CP1 (continuous) + initial marking {0.5} + steady marking {1} + output arc T1 + + place CP2 (continuous) + initial marking {0} + steady marking {0.1} + output arc T2 + output arc T3 + + place CP3 (continuous) + initial marking {10} + steady marking {9.4} + output arc T3 + +transitions + + transition T1 (continuous) + flow (1) + steady flow (1) + output arc CP2 + + transition T2 (continuous) + flow (1) + steady flow (1) + output arc CP3 + + transition T3 (continuous) + flow (1) + steady flow (1) + output arc CP1 + output arc CP2 + + + + diff --git a/examples/pureCPN2.bpn b/examples/pureCPN2.bpn new file mode 100644 index 0000000000000000000000000000000000000000..bb2c7af139658a8bc69e29f642354b929ccc2f96 --- /dev/null +++ b/examples/pureCPN2.bpn @@ -0,0 +1,47 @@ +// pure continuous petri net with constant speed. + + +model test; +length unity= m ; +time unity = m; + +network description +places + + place CP1 (continuous) + initial marking {1} + steady marking {0.5} + output arc T1 + + place CP2 (continuous) + initial marking {0.3} + steady marking {0.5} + output arc T2 + output arc T3 + + place CP3 (continuous) + initial marking {10} + steady marking {10.3} + output arc T2 + +transitions + + transition T1 (continuous) + flow (1) + steady flow (1) + output arc CP2 + + transition T2 (continuous) + flow (1) + steady flow (1) + output arc CP1 + output arc CP2 + + transition T3 (continuous) + flow (1) + steady flow (1) + output arc CP3 + + + + diff --git a/examples/pureCPN21.bpn b/examples/pureCPN21.bpn new file mode 100644 index 0000000000000000000000000000000000000000..c25607e97a703bca09cb64e31256d7a5f79134d7 --- /dev/null +++ b/examples/pureCPN21.bpn @@ -0,0 +1,52 @@ +// pure continuous petri net with constant speed. + + +model test; +length unity= m ; +time unity = m; + +network description +places + + place CP1 (continuous) + initial marking {3} + steady marking {5.5} + output arc T1 (2) + + place CP2 (continuous) + initial marking {1} + steady marking {0.75} + output arc T2 + + place CP3 (continuous) + initial marking {3} + steady marking {0.75} + output arc T3 + + place CP4 (continuous) + initial marking {3} + steady marking {1.5} + output arc T1 (2) + output arc T2 + + +transitions + + transition T1 (continuous) + flow (1) + steady flow (1) + output arc CP2 + output arc CP3 + + transition T2 (continuous) + flow (1) + steady flow (1) + output arc CP1 + + transition T3 (continuous) + flow (1) + steady flow (1) + output arc CP1 + output arc CP4 (3) + + diff --git a/examples/pureCPN3.bpn b/examples/pureCPN3.bpn new file mode 100644 index 0000000000000000000000000000000000000000..7e5f7cf0e5abe3ad9528ac668db51f3f40e5f317 --- /dev/null +++ b/examples/pureCPN3.bpn @@ -0,0 +1,45 @@ +// pure continuous petri net with constant speed. + + +model test; +length unity= m ; +time unity = m; + +network description +places + + place CP1 (continuous) + initial marking {0.5} + steady marking {1} + output arc T1 + + place CP2 (continuous) + initial marking {0.3} + steady marking {0.5} + output arc T2 + output arc T3 (2) + + place CP3 (continuous) + initial marking {10} + steady marking {9.3} + output arc T3 (2) + +transitions + + transition T1 (continuous) + flow (1) + steady flow (1) + output arc CP2 + + transition T2 (continuous) + flow (2) + steady flow (2) + output arc CP3 + + transition T3 (continuous) + flow (1) + steady flow (1) + output arc CP1 + output arc CP2 (3) + + diff --git a/examples/pureCPN31.bpn b/examples/pureCPN31.bpn new file mode 100644 index 0000000000000000000000000000000000000000..2c29822227354831856784d02f3c25ed3290833b --- /dev/null +++ b/examples/pureCPN31.bpn @@ -0,0 +1,41 @@ +// pure continuous petri net with constant speed. + + +model test; +length unity= m ; +time unity = m; + +network description +places + + place CP1 (continuous) + initial marking {4} + steady marking {2.5} + output arc T1 + + place CP2 (continuous) + initial marking {0} + steady marking {1.5} + output arc T2 + + place CP3 (continuous) + initial marking {1} + steady marking {2.5} + output arc T1 + output arc T2 (2) + +transitions + + transition T1 (continuous) + flow (2.5) + steady flow (2.5) + output arc CP2 + output arc CP3 (2) + + transition T2 (continuous) + flow (2.5) + steady flow (2.5) + output arc CP1 + output arc CP3 + + diff --git a/examples/pureCPN4.bpn b/examples/pureCPN4.bpn new file mode 100644 index 0000000000000000000000000000000000000000..8c3f4421e1a3733e375eea904dcaf80d3e84bf18 --- /dev/null +++ b/examples/pureCPN4.bpn @@ -0,0 +1,45 @@ +// pure continuous petri net with constant speed. + + +model test; +length unity= m ; +time unity = m; + +network description +places + + place CP1 (continuous) + initial marking {0.5} + steady marking {1} + output arc T1 + + place CP2 (continuous) + initial marking {0.3} + steady marking {0.5} + output arc T2 + output arc T3 (2) + + place CP3 (continuous) + initial marking {10} + steady marking {9.3} + output arc T3 + +transitions + + transition T1 (continuous) + flow (1) + steady flow (1) + output arc CP2 + + transition T2 (continuous) + flow (2) + steady flow (2) + output arc CP3 + + transition T3 (continuous) + flow (1) + steady flow (1) + output arc CP1 + output arc CP2 (3) + + diff --git a/examples/pureCPN5.bpn b/examples/pureCPN5.bpn new file mode 100644 index 0000000000000000000000000000000000000000..7e5f7cf0e5abe3ad9528ac668db51f3f40e5f317 --- /dev/null +++ b/examples/pureCPN5.bpn @@ -0,0 +1,45 @@ +// pure continuous petri net with constant speed. + + +model test; +length unity= m ; +time unity = m; + +network description +places + + place CP1 (continuous) + initial marking {0.5} + steady marking {1} + output arc T1 + + place CP2 (continuous) + initial marking {0.3} + steady marking {0.5} + output arc T2 + output arc T3 (2) + + place CP3 (continuous) + initial marking {10} + steady marking {9.3} + output arc T3 (2) + +transitions + + transition T1 (continuous) + flow (1) + steady flow (1) + output arc CP2 + + transition T2 (continuous) + flow (2) + steady flow (2) + output arc CP3 + + transition T3 (continuous) + flow (1) + steady flow (1) + output arc CP1 + output arc CP2 (3) + + diff --git a/examples/pureCPN6.bpn b/examples/pureCPN6.bpn new file mode 100644 index 0000000000000000000000000000000000000000..a00ca0800a2d521f5e01f901855e1421777fc393 --- /dev/null +++ b/examples/pureCPN6.bpn @@ -0,0 +1,45 @@ +// pure continuous petri net with constant speed. + + +model test; +length unity= m ; +time unity = m; + +network description +places + + place CP1 (continuous) + initial marking {0.5} + steady marking {1} + output arc T1 + + place CP2 (continuous) + initial marking {0.3} + steady marking {0.5} + output arc T2 + output arc T3 (2) + + place CP3 (continuous) + initial marking {10} + steady marking {9.3} + output arc T3 + +transitions + + transition T1 (continuous) + flow (3) + steady flow (1) + output arc CP2 + + transition T2 (continuous) + flow (1) + steady flow (1) + output arc CP3 + + transition T3 (continuous) + flow (1) + steady flow (1) + output arc CP1 (3) + output arc CP2 + + diff --git a/examples/pureCPN7.bpn b/examples/pureCPN7.bpn new file mode 100644 index 0000000000000000000000000000000000000000..b8ecc80ee8f8658d0e0b1b08e299eb20e73457f4 --- /dev/null +++ b/examples/pureCPN7.bpn @@ -0,0 +1,45 @@ +// pure continuous petri net with constant speed. + + +model test; +length unity= m ; +time unity = m; + +network description +places + + place CP1 (continuous) + initial marking {0.1} + steady marking {0.3} + output arc T1 + + place CP2 (continuous) + initial marking {0.5} + steady marking {1} + output arc T2 + output arc T3 (3) + + place CP3 (continuous) + initial marking {10} + steady marking {9.3} + output arc T3 + +transitions + + transition T1 (continuous) + flow (2) + steady flow (2) + output arc CP2 + + transition T2 (continuous) + flow (1) + steady flow (1) + output arc CP3 + + transition T3 (continuous) + flow (1) + steady flow (1) + output arc CP1 (2) + output arc CP2 (2) + + diff --git a/examples/tbpn.bpn b/examples/tbpn.bpn new file mode 100644 index 0000000000000000000000000000000000000000..6db13af6166fdff15042abb1dc0733641ef1054a --- /dev/null +++ b/examples/tbpn.bpn @@ -0,0 +1,22 @@ +// Trinagular batch petri net + +model test_tbpn; +length unity= km ; +time unity = h; + +network description +places + place BP1 (triangular) + function (100, 200, 10, 5000) // speed, density, length + initial marking {} //length, density, poistion + output arc BTOut + + +transitions + transition BTIn (batch) + flow (1000) + output arc BP1 + + transition BTOut (batch) + flow (100) + diff --git a/examples/tbpn2.bpn b/examples/tbpn2.bpn new file mode 100644 index 0000000000000000000000000000000000000000..b8c88646ab8ded35987733a486c705e90e87ff2d --- /dev/null +++ b/examples/tbpn2.bpn @@ -0,0 +1,41 @@ +// Trinagular batch petri net + +model test_tbpn; +length unity= km ; +time unity = h; + +network description +places + place DP1 (discrete) + initial marking {2} + output arc DTIn + + place CP2 (continuous) + initial marking {0} + output arc CTMid + + place BP3 (triangular) + function (50, 200, 100, 2000) // speed, density, length + initial marking {} //length, density, poistion + output arc BTOut + + +transitions + transition DTIn (discrete) + timing (1) + output arc CP2 (400) + + transition CTMid (continuous) + flow (1000) + output arc BP3 + + transition BTOut (batch) + flow (100) + +controlled events // les evenements controlles pourrons aussi etre lu a partir d un fichier externe + ev1 = (flow, BTOut, 1000, 3.5); +// ev2 = (speed, PT, 120, 0.002); + +time inspection // affiche l information d une place(caracteristiques+lots)/transition(flux) a l instant <time> + res1 = @ 1.5 ? BP3; + res2 = # 1.0 * places diff --git a/examples/tbpn3.bpn b/examples/tbpn3.bpn new file mode 100644 index 0000000000000000000000000000000000000000..7b81d52143544ee83b371bab79f716a220a60ab1 --- /dev/null +++ b/examples/tbpn3.bpn @@ -0,0 +1,35 @@ +// Trinagular batch petri net + +model test_tbpn; +length unity= km ; +time unity = h; + +network description +places + place CP1 (continuous) + initial marking {10000} + output arc CTIn + + place BP2 (triangular) + function (50, 200, 100, 2000) // speed, density, length + initial marking {} //length, density, poistion + output arc BTOut + + +transitions + transition CTIn (batch) + flow (1000) + output arc BP2 + + transition BTOut (batch) + flow (1000) + +controlled events // les evenements controlles pourrons aussi etre lu a partir d un fichier externe + ev1 = (flow, BTOut, 100, 5); + ev2 = (flow, BTOut, 100, 4); + +// ev2 = (speed, PT, 120, 0.002); + +time inspection // affiche l information d une place(caracteristiques+lots)/transition(flux) a l instant <time> + res1 = @ 1.5 ? BP2; + res2 = # 1.0 * places diff --git a/examples/tbpn4.bpn b/examples/tbpn4.bpn new file mode 100644 index 0000000000000000000000000000000000000000..3c0b69ecf7cee5caad1de5763d4ba82f6bf68067 --- /dev/null +++ b/examples/tbpn4.bpn @@ -0,0 +1,25 @@ +// Trinagular batch petri net + +model test_tbpn; +length unity= km ; +time unity = h; + +network description +places + place BP2 (triangular) + function (50, 200, 100, 2000) // speed, density, length + initial marking {(5.20833333333, 192, 100, 0.5208333333333334)} //length, density, poistion, speed + output arc BTOut + + +transitions + transition BTOut (batch) + flow (1000) + +controlled events // les evenements controlles pourrons aussi etre lu a partir d un fichier externe + ev1 = (flow, BTOut, 1000, 0.003); + ev2 = (speed, BP2, 30, 0.002); + +time inspection // affiche l information d une place(caracteristiques+lots)/transition(flux) a l instant <time> + res1 = @ 1.5 ? BP2; + res2 = # 1.0 * places diff --git a/examples/test.bpn b/examples/test.bpn new file mode 100644 index 0000000000000000000000000000000000000000..46a0401d359208ef54f139f3ec97a45392d8af5f --- /dev/null +++ b/examples/test.bpn @@ -0,0 +1,67 @@ +// comments + +model test; +length unity= m ; +time unity = s; + +network description +places + place PD (discrete) + initial marking {1} + steady marking {1} + output arc T1 + output arc T2 (2) + + place PC (continuous) + initial marking {2.5} + steady marking {2.5} + + output arc t3 (1) + output arc t4 + + place PC2 (continuous) + initial marking {2.5} + output arc t3 (1) + output arc t4 + + place PB (batch) + function (10,120, 200 ) + initial marking { (1, 1.2, 100) } + output arc t3 +// output arc t6 (3) + + place PT (triangular) + function ( 120, 250, 10.4, 4000) + initial marking { (2.3, 1.0,50, 200) , + (3, 10, 120, 300) } + output arc t4 (3.2) + +transitions + transition T1 (discrete) + timing (5.1) + output arc PD + output arc PC (2) + + transition T2 (continuous) + flow (300.5) + output arc PC2 + output arc PB + + transition t3 (batch) + flow (4000) + output arc PT + + transition t4 (batch) + flow (4000) + output arc PT + + +controlled events // les evenements controlles pourrons aussi etre lu a partir d un fichier externe + ev1 = (flow, T1, 4000, 0.001); + ev2 = (speed, PT, 120, 0.002); + +time inspection // affiche l information d une place(caracteristiques+lots)/transition(flux) a l instant <time> + res1 = @ 1.001 ? pt; + res2 = # 1.02 * places + + diff --git a/examples/test1.bpn b/examples/test1.bpn new file mode 100644 index 0000000000000000000000000000000000000000..f84c82445f7145865c1401e327df9bc7af57eddc --- /dev/null +++ b/examples/test1.bpn @@ -0,0 +1,32 @@ +// batch petri net + +model test; +length unity= m ; +time unity = m; + +network description +places + + place BP2 (batch) + function (10, 3, 3) // speed, density, length + initial marking {} //length, density, poistion + steady marking {(3,0.4,3)} + output arc T2 + + place CP1 (continuous) + initial marking {3} + steady marking {1.8} + output arc T1 + +transitions + + transition T1 (batch) + flow (4) + steady flow (4) + output arc BP2 + + transition T2 (batch) + flow (4) + steady flow (4) + output arc CP1 + diff --git a/examples/test2.bpn b/examples/test2.bpn new file mode 100644 index 0000000000000000000000000000000000000000..213c049805984c382460825f80a8fb4374e05122 --- /dev/null +++ b/examples/test2.bpn @@ -0,0 +1,38 @@ +// batch petri net + +model test; +length unity= m ; +time unity = m; + +network description +places + + + + place BP2 (batch) + function (1, 2, 5) // speed, density, length + initial marking {} //length, density, poistion + steady marking {(3,2,5),(2,1,2)} + output arc T2 (0.5) + + + place CP1 (continuous) + initial marking {9} + steady marking {1} + output arc T1 (2) + + + +transitions + + transition T1 (batch) + flow (1) + steady flow (1) + output arc BP2 + + transition T2 (batch) + flow (1) + steady flow (1) + output arc CP1 + + diff --git a/examples/test_steady.bpn b/examples/test_steady.bpn new file mode 100644 index 0000000000000000000000000000000000000000..b8dbd7d5423796a5d8a8d83f169c561f5e30e719 --- /dev/null +++ b/examples/test_steady.bpn @@ -0,0 +1,76 @@ +// comments + +model test; +length unity= m ; +time unity = s; + +network description +places + place PD (discrete) + initial marking {1} + steady marking {1} + output arc T1 + output arc T2 (2) + + place PC (continuous) + initial marking {2.5} + steady marking {2.5} + output arc t3 (1) + output arc t4 + + place PC2 (continuous) + initial marking {2.5} + output arc t3 (1) + output arc t4 + + place PB (batch) + function (10,120, 200 ) + initial marking { (1, 1.2, 100) } + steady marking { (1, 1, 100), (9, 2, 200) } + + output arc t3 +// output arc t6 (3) + + place PT (triangular) + function ( 120, 250, 10.4, 4000) + initial marking { (2.3, 1.0,50, 200) , + (3, 10, 120, 300) } + steady marking { (2.3, 1.0,50, 200) , + (4, 10, 120, 300) } + output arc t4 (3.2) + +transitions + transition T1 (discrete) + timing (5.1) + steady timing (4.0) + output arc PD + output arc PC (2) + + transition T2 (continuous) + flow (300.5) + steady flow (300.5) + + output arc PC2 + output arc PB + + transition t3 (batch) + flow (4000) + steady flow (300.5) + + output arc PT + + transition t4 (batch) + flow (4000) + steady flow (3000) + output arc PT + + +controlled events // les evenements controlles pourrons aussi etre lu a partir d un fichier externe + ev1 = (flow, T2, 4000, 0.001); + ev2 = (speed, PT, 120, 0.002); + +time inspection // affiche l information d une place(caracteristiques+lots)/transition(flux) a l instant <time> + res1 = @ 1.001 ? PT; + res2 = # 1.02 * places + + diff --git a/simuleau.cbp b/simuleau.cbp new file mode 100644 index 0000000000000000000000000000000000000000..d6b04ce25f9bc02be9c13b88ff74ee67b3264e61 --- /dev/null +++ b/simuleau.cbp @@ -0,0 +1,130 @@ +<?xml version="1.0" encoding="UTF-8" standalone="yes" ?> +<CodeBlocks_project_file> + <FileVersion major="1" minor="6" /> + <Project> + <Option title="simuleau" /> + <Option pch_mode="2" /> + <Option compiler="gcc" /> + <Build> + <Target title="Debug"> + <Option output="bin/Debug/simuleau" prefix_auto="1" extension_auto="1" /> + <Option working_dir="bin/Debug" /> + <Option object_output="obj/Debug/" /> + <Option type="1" /> + <Option compiler="gcc" /> + <Compiler> + <Add option="-w" /> + <Add option="-pg" /> + <Add option="-g" /> + <Add option="-Wunused-result" /> + <Add option="-O0" /> + <Add option="-D_SIMULEAU_DEBUG_" /> + <Add directory="src" /> + <Add directory="src/bpn" /> + <Add directory="src/interf" /> + <Add directory="src/simul" /> + </Compiler> + <Linker> + <Add option="-pg" /> + <Add option="-static-libstdc++" /> + <Add option="-static-libgcc" /> + <Add library="glpk" /> + <Add library="libglpk" /> + <Add directory="/usr/local/lib" /> + <Add directory="/usr/local/include" /> + <Add directory="/usr/include" /> + <Add directory="/usr/lib/x86_64-linux-gnu/" /> + </Linker> + <ExtraCommands> + <Add before="lex -o src/interf/y.tab.cpp src/interf/tokens.l" /> + <Add before="yacc -tdv -o src/interf/y.tab.cpp src/interf/glc.y" /> + <Mode after="always" /> + </ExtraCommands> + </Target> + <Target title="Release"> + <Option output="bin/Release/simuleau" prefix_auto="1" extension_auto="1" /> + <Option object_output="obj/Release/" /> + <Option type="1" /> + <Option compiler="gcc" /> + <Compiler> + <Add option="-O2" /> + <Add directory="src/bpn" /> + <Add directory="src/simul" /> + <Add directory="src" /> + <Add directory="src/interf" /> + </Compiler> + <Linker> + <Add option="-s" /> + <Add library="glpk" /> + </Linker> + <ExtraCommands> + <Add before="yacc -tdv -o src/interf/y.tab.cpp src/interf/glc.y" /> + </ExtraCommands> + </Target> + </Build> + <Compiler> + <Add option="-Wall" /> + <Add option="-std=c++11" /> + <Add option="-fexceptions" /> + <Add option="-fpermissive" /> + <Add directory="src" /> + </Compiler> + <Linker> + <Add library="glpk" /> + <Add library="dl" /> + </Linker> + <Unit filename="src/bpn/arc.cpp" /> + <Unit filename="src/bpn/arc.h" /> + <Unit filename="src/bpn/batch.cpp" /> + <Unit filename="src/bpn/batch.h" /> + <Unit filename="src/bpn/batchplace.cpp" /> + <Unit filename="src/bpn/batchtransition.cpp" /> + <Unit filename="src/bpn/bpn.cpp" /> + <Unit filename="src/bpn/bpn.h" /> + <Unit filename="src/bpn/continuousplace.cpp" /> + <Unit filename="src/bpn/continuoustransition.cpp" /> + <Unit filename="src/bpn/controllablebatch.cpp" /> + <Unit filename="src/bpn/discreteplace.cpp" /> + <Unit filename="src/bpn/discretetransition.cpp" /> + <Unit filename="src/bpn/firingquantity.cpp" /> + <Unit filename="src/bpn/firingquantity.h" /> + <Unit filename="src/bpn/flow.cpp" /> + <Unit filename="src/bpn/flow.h" /> + <Unit filename="src/bpn/node.cpp" /> + <Unit filename="src/bpn/node.h" /> + <Unit filename="src/bpn/place.cpp" /> + <Unit filename="src/bpn/place.h" /> + <Unit filename="src/bpn/transition.cpp" /> + <Unit filename="src/bpn/transition.h" /> + <Unit filename="src/bpn/triangularbatchplace.cpp" /> + <Unit filename="src/interf/bpnfile.h" /> + <Unit filename="src/interf/error_msgs.h" /> + <Unit filename="src/interf/interf.cpp" /> + <Unit filename="src/interf/interf.h" /> + <Unit filename="src/interf/lex.yy.cpp"> + <Option compilerVar="CC" /> + </Unit> + <Unit filename="src/interf/prf.cpp" /> + <Unit filename="src/interf/prf.h" /> + <Unit filename="src/interf/timer.cpp" /> + <Unit filename="src/interf/timer.h" /> + <Unit filename="src/interf/y.tab.cpp"> + <Option compilerVar="CC" /> + </Unit> + <Unit filename="src/interf/y.tab.h" /> + <Unit filename="src/interf/y.tab.hpp" /> + <Unit filename="src/simul/breakpoint.cpp" /> + <Unit filename="src/simul/breakpoint.h" /> + <Unit filename="src/simul/event.cpp" /> + <Unit filename="src/simul/event.h" /> + <Unit filename="src/simul/schedule.cpp" /> + <Unit filename="src/simul/schedule.h" /> + <Unit filename="src/simul/simtime.cpp" /> + <Unit filename="src/simul/simtime.h" /> + <Unit filename="src/simul/simulate.cpp" /> + <Unit filename="src/simul/simulate.h" /> + <Unit filename="src/simuleau.cpp" /> + <Unit filename="src/simuleau.h" /> + <Extensions /> + </Project> +</CodeBlocks_project_file> diff --git a/simuleau.layout b/simuleau.layout new file mode 100644 index 0000000000000000000000000000000000000000..631861721591fcab3a7cf8a926cd0bc5a14cda9c --- /dev/null +++ b/simuleau.layout @@ -0,0 +1,230 @@ +<?xml version="1.0" encoding="UTF-8" standalone="yes" ?> +<CodeBlocks_layout_file> + <FileVersion major="1" minor="0" /> + <ActiveTarget name="Debug" /> + <File name="src/bpn/arc.cpp" open="0" top="0" tabpos="1" split="0" active="1" splitpos="0" zoom_1="0" zoom_2="0"> + <Cursor> + <Cursor1 position="1012" topLine="0" /> + </Cursor> + </File> + <File name="src/interf/interf.h" open="0" top="0" tabpos="19" split="0" active="1" splitpos="0" zoom_1="0" zoom_2="0"> + <Cursor> + <Cursor1 position="2344" topLine="27" /> + </Cursor> + </File> + <File name="src/bpn/triangularbatchplace.cpp" open="0" top="0" tabpos="9" split="0" active="1" splitpos="0" zoom_1="0" zoom_2="0"> + <Cursor> + <Cursor1 position="26249" topLine="763" /> + </Cursor> + </File> + <File name="src/simul/event.h" open="0" top="0" tabpos="15" split="0" active="1" splitpos="0" zoom_1="0" zoom_2="0"> + <Cursor> + <Cursor1 position="1583" topLine="47" /> + </Cursor> + </File> + <File name="src/bpn/firingquantity.h" open="0" top="0" tabpos="17" split="0" active="1" splitpos="0" zoom_1="0" zoom_2="0"> + <Cursor> + <Cursor1 position="1151" topLine="0" /> + </Cursor> + </File> + <File name="src/bpn/continuousplace.cpp" open="0" top="0" tabpos="6" split="0" active="1" splitpos="0" zoom_1="0" zoom_2="0"> + <Cursor> + <Cursor1 position="14296" topLine="165" /> + </Cursor> + </File> + <File name="src/simul/simulate.cpp" open="1" top="0" tabpos="3" split="0" active="1" splitpos="0" zoom_1="0" zoom_2="0"> + <Cursor> + <Cursor1 position="5815" topLine="328" /> + </Cursor> + </File> + <File name="src/simul/event.cpp" open="0" top="0" tabpos="6" split="0" active="1" splitpos="0" zoom_1="0" zoom_2="0"> + <Cursor> + <Cursor1 position="4108" topLine="201" /> + </Cursor> + </File> + <File name="src/bpn/continuoustransition.cpp" open="0" top="0" tabpos="11" split="0" active="1" splitpos="0" zoom_1="0" zoom_2="0"> + <Cursor> + <Cursor1 position="5687" topLine="255" /> + </Cursor> + </File> + <File name="src/bpn/arc.h" open="0" top="0" tabpos="2" split="0" active="1" splitpos="0" zoom_1="0" zoom_2="0"> + <Cursor> + <Cursor1 position="827" topLine="1" /> + </Cursor> + </File> + <File name="src/bpn/batch.cpp" open="0" top="0" tabpos="14" split="0" active="1" splitpos="0" zoom_1="0" zoom_2="0"> + <Cursor> + <Cursor1 position="3680" topLine="87" /> + </Cursor> + </File> + <File name="src/simuleau.h" open="1" top="0" tabpos="4" split="0" active="1" splitpos="0" zoom_1="0" zoom_2="0"> + <Cursor> + <Cursor1 position="2051" topLine="12" /> + </Cursor> + </File> + <File name="src/bpn/flow.cpp" open="0" top="0" tabpos="12" split="0" active="1" splitpos="0" zoom_1="0" zoom_2="0"> + <Cursor> + <Cursor1 position="4499" topLine="34" /> + </Cursor> + </File> + <File name="src/bpn/batchplace.cpp" open="0" top="0" tabpos="3" split="0" active="1" splitpos="0" zoom_1="-1" zoom_2="0"> + <Cursor> + <Cursor1 position="20802" topLine="645" /> + </Cursor> + </File> + <File name="src/simul/simtime.cpp" open="0" top="0" tabpos="11" split="0" active="1" splitpos="0" zoom_1="0" zoom_2="0"> + <Cursor> + <Cursor1 position="2749" topLine="71" /> + </Cursor> + </File> + <File name="src/interf/prf.h" open="0" top="0" tabpos="11" split="0" active="1" splitpos="0" zoom_1="0" zoom_2="0"> + <Cursor> + <Cursor1 position="1362" topLine="0" /> + </Cursor> + </File> + <File name="src/bpn/place.h" open="0" top="0" tabpos="7" split="0" active="1" splitpos="0" zoom_1="0" zoom_2="0"> + <Cursor> + <Cursor1 position="3812" topLine="183" /> + </Cursor> + </File> + <File name="src/simul/breakpoint.cpp" open="0" top="0" tabpos="12" split="0" active="1" splitpos="0" zoom_1="0" zoom_2="0"> + <Cursor> + <Cursor1 position="5659" topLine="142" /> + </Cursor> + </File> + <File name="src/bpn/transition.h" open="0" top="0" tabpos="1" split="0" active="1" splitpos="0" zoom_1="0" zoom_2="0"> + <Cursor> + <Cursor1 position="2798" topLine="123" /> + </Cursor> + </File> + <File name="src/bpn/discreteplace.cpp" open="0" top="0" tabpos="16" split="0" active="1" splitpos="0" zoom_1="0" zoom_2="0"> + <Cursor> + <Cursor1 position="6047" topLine="139" /> + </Cursor> + </File> + <File name="src/simul/simulate.h" open="0" top="0" tabpos="12" split="0" active="1" splitpos="0" zoom_1="0" zoom_2="0"> + <Cursor> + <Cursor1 position="1402" topLine="0" /> + </Cursor> + </File> + <File name="src/simul/breakpoint.h" open="0" top="0" tabpos="16" split="0" active="1" splitpos="0" zoom_1="0" zoom_2="0"> + <Cursor> + <Cursor1 position="2086" topLine="15" /> + </Cursor> + </File> + <File name="src/bpn/node.cpp" open="0" top="0" tabpos="7" split="0" active="1" splitpos="0" zoom_1="0" zoom_2="0"> + <Cursor> + <Cursor1 position="6150" topLine="171" /> + </Cursor> + </File> + <File name="src/simul/schedule.cpp" open="0" top="0" tabpos="3" split="0" active="1" splitpos="0" zoom_1="0" zoom_2="0"> + <Cursor> + <Cursor1 position="25197" topLine="710" /> + </Cursor> + </File> + <File name="src/interf/lex.yy.cpp" open="0" top="0" tabpos="0" split="0" active="1" splitpos="0" zoom_1="0" zoom_2="0"> + <Cursor> + <Cursor1 position="0" topLine="513" /> + </Cursor> + </File> + <File name="src/bpn/flow.h" open="0" top="0" tabpos="6" split="0" active="1" splitpos="0" zoom_1="0" zoom_2="0"> + <Cursor> + <Cursor1 position="1549" topLine="20" /> + </Cursor> + </File> + <File name="src/bpn/firingquantity.cpp" open="0" top="0" tabpos="1" split="0" active="1" splitpos="0" zoom_1="0" zoom_2="0"> + <Cursor> + <Cursor1 position="2746" topLine="36" /> + </Cursor> + </File> + <File name="src/bpn/bpn.h" open="0" top="0" tabpos="5" split="0" active="1" splitpos="0" zoom_1="0" zoom_2="0"> + <Cursor> + <Cursor1 position="6212" topLine="105" /> + </Cursor> + </File> + <File name="src/interf/error_msgs.h" open="0" top="0" tabpos="15" split="0" active="1" splitpos="0" zoom_1="0" zoom_2="0"> + <Cursor> + <Cursor1 position="4237" topLine="64" /> + </Cursor> + </File> + <File name="src/bpn/place.cpp" open="0" top="0" tabpos="16" split="0" active="1" splitpos="0" zoom_1="0" zoom_2="0"> + <Cursor> + <Cursor1 position="2431" topLine="51" /> + </Cursor> + </File> + <File name="src/bpn/controllablebatch.cpp" open="0" top="0" tabpos="12" split="0" active="1" splitpos="0" zoom_1="0" zoom_2="0"> + <Cursor> + <Cursor1 position="4136" topLine="57" /> + </Cursor> + </File> + <File name="src/interf/interf.cpp" open="1" top="0" tabpos="1" split="0" active="1" splitpos="0" zoom_1="0" zoom_2="0"> + <Cursor> + <Cursor1 position="22430" topLine="510" /> + </Cursor> + </File> + <File name="src/simul/simtime.h" open="0" top="0" tabpos="13" split="0" active="1" splitpos="0" zoom_1="0" zoom_2="0"> + <Cursor> + <Cursor1 position="1485" topLine="2" /> + </Cursor> + </File> + <File name="src/interf/y.tab.cpp" open="0" top="0" tabpos="21" split="0" active="1" splitpos="0" zoom_1="0" zoom_2="0"> + <Cursor> + <Cursor1 position="6548" topLine="124" /> + </Cursor> + </File> + <File name="src/interf/bpnfile.h" open="0" top="0" tabpos="14" split="0" active="1" splitpos="0" zoom_1="0" zoom_2="0"> + <Cursor> + <Cursor1 position="39" topLine="0" /> + </Cursor> + </File> + <File name="src/simuleau.cpp" open="1" top="1" tabpos="2" split="0" active="1" splitpos="0" zoom_1="0" zoom_2="0"> + <Cursor> + <Cursor1 position="5708" topLine="102" /> + </Cursor> + </File> + <File name="src/simul/schedule.h" open="0" top="0" tabpos="14" split="0" active="1" splitpos="0" zoom_1="0" zoom_2="0"> + <Cursor> + <Cursor1 position="2038" topLine="46" /> + </Cursor> + </File> + <File name="src/interf/prf.cpp" open="0" top="0" tabpos="12" split="0" active="1" splitpos="0" zoom_1="0" zoom_2="0"> + <Cursor> + <Cursor1 position="4727" topLine="181" /> + </Cursor> + </File> + <File name="src/bpn/batchtransition.cpp" open="0" top="0" tabpos="2" split="0" active="1" splitpos="0" zoom_1="0" zoom_2="0"> + <Cursor> + <Cursor1 position="8375" topLine="200" /> + </Cursor> + </File> + <File name="src/bpn/batch.h" open="0" top="0" tabpos="7" split="0" active="1" splitpos="0" zoom_1="0" zoom_2="0"> + <Cursor> + <Cursor1 position="3511" topLine="76" /> + </Cursor> + </File> + <File name="src/bpn/node.h" open="0" top="0" tabpos="9" split="0" active="1" splitpos="0" zoom_1="0" zoom_2="0"> + <Cursor> + <Cursor1 position="1882" topLine="22" /> + </Cursor> + </File> + <File name="src/bpn/bpn.cpp" open="0" top="0" tabpos="4" split="0" active="1" splitpos="0" zoom_1="0" zoom_2="0"> + <Cursor> + <Cursor1 position="24657" topLine="671" /> + </Cursor> + </File> + <File name="src/bpn/transition.cpp" open="0" top="0" tabpos="2" split="0" active="1" splitpos="0" zoom_1="0" zoom_2="0"> + <Cursor> + <Cursor1 position="5446" topLine="334" /> + </Cursor> + </File> + <File name="src/interf/timer.cpp" open="0" top="0" tabpos="0" split="0" active="1" splitpos="0" zoom_1="0" zoom_2="0"> + <Cursor> + <Cursor1 position="1364" topLine="45" /> + </Cursor> + </File> + <File name="src/bpn/discretetransition.cpp" open="0" top="0" tabpos="2" split="0" active="1" splitpos="0" zoom_1="0" zoom_2="0"> + <Cursor> + <Cursor1 position="2748" topLine="46" /> + </Cursor> + </File> +</CodeBlocks_layout_file> diff --git a/src/.DS_Store b/src/.DS_Store new file mode 100644 index 0000000000000000000000000000000000000000..9cda2562d7da1a9fc4dedf9de3925e9687f8ea4c Binary files /dev/null and b/src/.DS_Store differ diff --git a/src/bpn/arc.cpp b/src/bpn/arc.cpp new file mode 100644 index 0000000000000000000000000000000000000000..80bd388b5e556332f9025d89fb00840a0e758e48 --- /dev/null +++ b/src/bpn/arc.cpp @@ -0,0 +1,22 @@ +//====================================================================================// +// // +// Arc class // +// // +//====================================================================================// +// This File: arc.cpp Language: C++ (xlC and CC) // +// Software: SIMULEAU // +//====================================================================================// +// Creation: 22/apr/16 by: Leonardo.Brenner@lsis.org // +// Last Change: 22/apr/16 by: Leonardo.Brenner@lsis.org // +//====================================================================================// +#include "simuleau.h" + +Arc::Arc() +{ + //ctor +} + +Arc::~Arc() +{ + //dtor +} diff --git a/src/bpn/arc.h b/src/bpn/arc.h new file mode 100644 index 0000000000000000000000000000000000000000..98fbc1f963637cfc8e7f404a8b0c43f5f9f92d41 --- /dev/null +++ b/src/bpn/arc.h @@ -0,0 +1,29 @@ +//====================================================================================// +// // +// Arc class // +// // +//====================================================================================// +// This File: arc.h Language: C++ (xlC and CC) // +// Software: SIMULEAU // +//====================================================================================// +// Creation: 22/apr/16 by: Leonardo.Brenner@lsis.org // +// Last Change: 22/apr/16 by: Leonardo.Brenner@lsis.org // +//====================================================================================// +#ifndef ARC_H +#define ARC_H + +class Arc +{ + public: + Arc(); + virtual ~Arc(); + + protected: + double weight; // weight associated to this arc + Node *input; // pointer to the input node + Node *output; // pointer to the input node + + private: +}; + +#endif // ARC_H diff --git a/src/bpn/batch.cpp b/src/bpn/batch.cpp new file mode 100644 index 0000000000000000000000000000000000000000..1628cbc15a0b9099ceb598d3428a7792cbfb434c --- /dev/null +++ b/src/bpn/batch.cpp @@ -0,0 +1,260 @@ +//====================================================================================// +// // +// Batch class // +// // +//====================================================================================// +// This File: batch.cpp Language: C++ (xlC and CC) // +// Software: SIMULEAU // +//====================================================================================// +// Creation: 28/apr/16 by: Leonardo.Brenner@lsis.org // +// Last Change: 28/apr/16 by: Leonardo.Brenner@lsis.org // +//====================================================================================// +#include "simuleau.h" + +//------------------------------------------------------------------------------ +//------------------------------------------------------------------------------ +// Methods of the Batch class +//------------------------------------------------------------------------------ +//------------------------------------------------------------------------------ + +//------------------------------------------------------------------------------ +// Constructor +//------------------------------------------------------------------------------ +Batch::Batch() +{ + strcpy(name,""); + length = 0.0; + density = 0.0; + position = 0.0; + outputflow = 0.0; +} + +//------------------------------------------------------------------------------ +// Constructor +//------------------------------------------------------------------------------ +Batch::Batch(char *_name) +{ + strcpy(name,"_name"); + length = 0.0; + density = 0.0; + position = 0.0; + outputflow = 0.0; +} + +//------------------------------------------------------------------------------ +// Initialized constructor +//------------------------------------------------------------------------------ +Batch::Batch(double _length, double _density, double _position) +{ + length = _length; + density = _density; + position = _position; + outputflow = 0.0; +} + +//------------------------------------------------------------------------------ +// Initialized constructor +//------------------------------------------------------------------------------ +Batch::Batch(double _inputflow, double _speed) +{ + length = 0.0; + density = _inputflow/_speed; + position = 0.0; + outputflow = 0.0; +} + +//------------------------------------------------------------------------------ +// Destructor +//------------------------------------------------------------------------------ +Batch::~Batch() +{ + //dtor +} + +//------------------------------------------------------------------------------ +// It returns the batch name +//------------------------------------------------------------------------------ +char* Batch::GetName() +{ + return (name); +} + +//------------------------------------------------------------------------------ +// Copy +//------------------------------------------------------------------------------ +void Batch::Copy(const Batch &_batch) +{ + strcpy(name, _batch.name); + length = _batch.length; + density = _batch.density; + position = _batch.position; + outputflow = _batch.outputflow; +} + +//------------------------------------------------------------------------------ +// IsEqual +//------------------------------------------------------------------------------ +int Batch::IsEqual(const Batch &_batch) +{ + if (abs(length - _batch.length) > PRF::prf.Min_Err()) + return 0; + if (abs(density - _batch.density) > PRF::prf.Min_Err()) + return 0; + if (abs(position - _batch.position) > PRF::prf.Min_Err()) + return 0; + return 1; +} + +//------------------------------------------------------------------------------ +// It sets a new density +//------------------------------------------------------------------------------ +void Batch::SetDensity(double _density) +{ + density = _density; +} + +//------------------------------------------------------------------------------ +// It sets a new length +//------------------------------------------------------------------------------ +void Batch::SetLength(double _length) +{ + length = _length; +} + +//------------------------------------------------------------------------------ +// It sets a new position +//------------------------------------------------------------------------------ +void Batch::SetPosition(double _position) +{ + position = _position; +} + +//------------------------------------------------------------------------------ +// It moves the position +//------------------------------------------------------------------------------ +void Batch::MovePosition(double _length) +{ + position += _length; +} + +//------------------------------------------------------------------------------ +// It returns the density +//------------------------------------------------------------------------------ +double Batch::GetDensity() +{ + return (density); +} + +//------------------------------------------------------------------------------ +// It returns the length +//------------------------------------------------------------------------------ +double Batch::GetLength() +{ + return (length); +} + +//------------------------------------------------------------------------------ +// It returns the position +//------------------------------------------------------------------------------ +double Batch::GetPosition() +{ + return (position); +} + +//------------------------------------------------------------------------------ +// It computes and returns the output flow of a batch +//------------------------------------------------------------------------------ +double Batch::GetOutputFlow(double _speed) +{ + outputflow = density * _speed; + return (outputflow); +} + +//------------------------------------------------------------------------------ +// It applies the free behaviour at this batch +//------------------------------------------------------------------------------ +void Batch::EvolveInFreeBehaviour(Simtime *_stime, BatchPlace *bp) +{ + double newposition; + + newposition = position + (bp->GetInstantaneousSpeed() * _stime->StepTime()); + if ((position == 0.0) && (length == 0.0)){ //new batch, input in free behaviour + length = newposition; + position = newposition; + } + else{ + if ((bp->GetLength() - position) < PRF::prf.Min_Err()){ + length -= (bp->GetInstantaneousSpeed() * _stime->StepTime()); + position = bp->GetLength(); + } + else{ + position = newposition; + } + } +} + +//------------------------------------------------------------------------------ +// It applies the accumulated behaviour to the outpout batch +//------------------------------------------------------------------------------ +void Batch::EvolveInAccumulatedOuputBehaviour(Simtime *_stime, BatchPlace *bp, double _flow) +{ + length = length - (_stime->StepTime() * _flow / bp->GetDensity()); +} + +//------------------------------------------------------------------------------ +// It applies the free to accumulated behaviour in the accumulated batch +//------------------------------------------------------------------------------ +void Batch::EvolveInFreeToAccumulatedBehaviourAccBatch(Simtime *_stime, BatchPlace *bp, double _flow) +{ + length = (((bp->GetInstantaneousSpeed() * density - _flow) / ( bp->GetDensity() - density)) * _stime->StepTime()); + density = bp->GetDensity(); +} + + +//------------------------------------------------------------------------------ +// It applies the free to accumulated behaviour in the free batch +//------------------------------------------------------------------------------ +void Batch::EvolveInFreeToAccumulatedBehaviourFreeBatch(Simtime *_stime, BatchPlace *bp, double outputbatchlength, double _flow) +{ + length = length + ((_flow - bp->GetInstantaneousSpeed() * bp->GetDensity()) / (bp->GetDensity() - density)) * _stime->StepTime() ; + position = bp->GetLength() - outputbatchlength; +} + + + +//------------------------------------------------------------------------------ +// It applies the partially accumulated behaviour in the accumulated batch +//------------------------------------------------------------------------------ +void Batch::EvolveInPartiallyAccumulatedBehaviourAccBatch(Simtime *_stime, BatchPlace *bp, double outputbatchlength, double _flow) +{ + length = ((density / (bp->GetDensity() - density)) * _stime->StepTime() *(bp->GetInstantaneousSpeed() - (_flow/bp->GetDensity()))) ; + density = bp->GetDensity(); + position = bp->GetLength() - outputbatchlength; +} + +//------------------------------------------------------------------------------ +// It applies the partially accumulated behaviour in the free batch +//------------------------------------------------------------------------------ +void Batch::EvolveInPartiallyAccumulatedBehaviourFreeBatch(Simtime *_stime, BatchPlace *bp, double outputbatchlength, double batch2length, double _flow) +{ + length = length +((bp->GetDensity() / (density - bp->GetDensity())) * _stime->StepTime() * (bp->GetInstantaneousSpeed() - (_flow/bp->GetDensity()))) ; + position = bp->GetLength() - outputbatchlength - batch2length; +} + + +//------------------------------------------------------------------------------ +// Print +//------------------------------------------------------------------------------ +void Batch::Print(ostream &fout) +{ + fout << " (" << length << ", " << density << ", " << position << ")" << endl; +} + +//------------------------------------------------------------------------------ +// Write +//------------------------------------------------------------------------------ +void Batch::Write(ostream &fout) +{ + fout << " (" << length << ", " << density << ", " << position << ")" << endl; +} + diff --git a/src/bpn/batch.h b/src/bpn/batch.h new file mode 100644 index 0000000000000000000000000000000000000000..3983ae7b2eb0b804f6ee6740a12c8241c204aebf --- /dev/null +++ b/src/bpn/batch.h @@ -0,0 +1,131 @@ +//====================================================================================// +// // +// Batch class // +// // +//====================================================================================// +// This File: batch.h Language: C++ (xlC and CC) // +// Software: SIMULEAU // +//====================================================================================// +// Creation: 28/apr/16 by: Leonardo.Brenner@lsis.org // +// Last Change: 28/apr/16 by: Leonardo.Brenner@lsis.org // +//====================================================================================// +#ifndef BATCH_H +#define BATCH_H + + +class Batch // batch.cpp +{ + public: + Batch(); + Batch(char *_name); + Batch(double _length, double _density, double _position); + Batch(double _inputflow, double _speed); + virtual ~Batch(); + + virtual batch_type IsA(){return Batch_bt;}; + char* GetName(); + void Copy(const Batch &_batch); + int IsEqual(const Batch &_batch); + + // input functions + void SetDensity(double _density); + void SetLength(double _length); + void SetPosition(double _position); + void MovePosition(double _length); + + // output functions + double GetDensity(); + double GetLength(); + double GetPosition(); + double GetOutputFlow(double _speed); + + // batch evolution functions + void EvolveInFreeBehaviour(Simtime *_stime, BatchPlace *bp); //RL + void EvolveInAccumulatedOuputBehaviour(Simtime *_stime, BatchPlace *bp, double _flow); //SA + void EvolveInFreeToAccumulatedBehaviourAccBatch(Simtime *_stime, BatchPlace *bp, double _flow); //RLAa + void EvolveInFreeToAccumulatedBehaviourFreeBatch(Simtime *_stime, BatchPlace *bp, double ouputbatchlength, double _flow); //RLAl + void EvolveInPartiallyAccumulatedBehaviourAccBatch(Simtime *_stime, BatchPlace *bp, double ouputbatchlength, double _flow); //RAPa1 + void EvolveInPartiallyAccumulatedBehaviourFreeBatch(Simtime *_stime, BatchPlace *bp, double outputbatchlength, double batch2length, double _flow); //RAPl + + //print function + virtual void Print(ostream &fout); + virtual void Write(ostream &fout); + + + protected: + simuleau_name name; + double length; + double density; + double position; + double outputflow; + + private: +}; + + +class ControllableBatch : public Batch // controllablebatch.cpp +{ + public: + typedef void (ControllableBatch::*EvolveFunction)(Simtime *_stime, TriangularBatchPlace *tbp, ControllableBatch *pcb, ControllableBatch *ncb); + + public: + ControllableBatch(); + ControllableBatch(char *_name); + ControllableBatch(double _length, double _density, double _position, double _speed); + ControllableBatch(double _inputflow, double _speed); + virtual ~ControllableBatch(); + + virtual batch_type IsA(){return Controllable_bt;}; + void Copy(const ControllableBatch &_controllablebatch); + int IsEqual(const ControllableBatch &_controllablebatch); + + + // input functions + void SetSpeed(double _speed); + void SetState(ctrl_batch_state _state); + void SetBehaviour(ctrl_batch_behaviour _behaviour); + + // output functions + double GetSpeed(); + double GetFlow(); + ctrl_batch_state GetState(); + ctrl_batch_state GetState(TriangularBatchPlace *tbp); + char* GetStateName(); + ctrl_batch_behaviour GetBehaviour(); + char* GetBehaviourName(); + + int IsOutputControllableBatch(BatchPlace *bp); + int IsInContactWithByFront(ControllableBatch &cb); + int IsInContactWithByRear(ControllableBatch &cb); + + + // controllable batch evolution functions + void SetEvolveFunction(EvolveFunction _func); + void Evolve(Simtime *_stime, TriangularBatchPlace *tbp, ControllableBatch *pcb, ControllableBatch *ncb); + + void EvolveInFreeBehaviour(Simtime *_stime, TriangularBatchPlace *tbp, ControllableBatch *pcb, ControllableBatch *ncb); //RL + void EvolveInCongestingOutputBehaviour(Simtime *_stime, TriangularBatchPlace *tbp, ControllableBatch *pcb, ControllableBatch *ncb); //RL + void EvolveInFreeToCongestingBehaviourCongBatch(Simtime *_stime, TriangularBatchPlace *tbp, ControllableBatch *pcb, ControllableBatch *ncb); //RL + void EvolveInFreeToCongestingBehaviourFreeBatch(Simtime *_stime, TriangularBatchPlace *tbp, ControllableBatch *pcb, ControllableBatch *ncb); //RL + void EvolveInFreeToCongestingBehaviourMiddlePlaceWithContactCongBatch(Simtime *_stime, TriangularBatchPlace *tbp, ControllableBatch *pcb, ControllableBatch *ncb); //RL + void EvolveInFreeToCongestingBehaviourMiddlePlaceWithContactFreeBatch(Simtime *_stime, TriangularBatchPlace *tbp, ControllableBatch *pcb, ControllableBatch *ncb); //RL + void EvolveInUncongestingOutputBehaviour(Simtime *_stime, TriangularBatchPlace *tbp, ControllableBatch *pcb, ControllableBatch *ncb); //RL + void EvolveInUncongestingToFreeBehaviourCongBatch(Simtime *_stime, TriangularBatchPlace *tbp, ControllableBatch *pcb, ControllableBatch *ncb); //RL + void EvolveInUncongestingToFreeBehaviourFreeBatch(Simtime *_stime, TriangularBatchPlace *tbp, ControllableBatch *pcb, ControllableBatch *ncb); //RL + + + //print function + void Print(ostream &fout); + void Write(ostream &fout); + + + protected: + double speed; + ctrl_batch_state state; + ctrl_batch_behaviour behaviour; + EvolveFunction evolvefunction; + + private: +}; + +#endif // BATCH_H diff --git a/src/bpn/batchplace.cpp b/src/bpn/batchplace.cpp new file mode 100644 index 0000000000000000000000000000000000000000..34e5f7d346464c9b1d7d4e8afee8765cc9e2be0a --- /dev/null +++ b/src/bpn/batchplace.cpp @@ -0,0 +1,1622 @@ +//====================================================================================// +// // +// Batch place classes inherit of place class // +// // +//====================================================================================// +// This File: batchplace.cpp Language: C++ (xlC and CC) // +// Software: SIMULEAU // +//====================================================================================// +// Creation: 22/apr/16 by: Leonardo.Brenner@lsis.org // +// Last Change: 22/apr/16 by: Leonardo.Brenner@lsis.org // +//====================================================================================// +#include "simuleau.h" + +//------------------------------------------------------------------------------ +//------------------------------------------------------------------------------ +// Methods of the Batch Place class +//------------------------------------------------------------------------------ +//------------------------------------------------------------------------------ + +//------------------------------------------------------------------------------ +// Constructor +//------------------------------------------------------------------------------ +BatchPlace::BatchPlace() +{ + behaviour = Free_behaviour; + formalisation = no; + speed = 0.0; + maxspeed = 0.0; + instantaneousspeed = 0.0; + density = 0.0; + length = 0.0; + + marks = new list<Batch>; + marks->clear(); + initialmarks = new list<Batch>; + initialmarks->clear(); + steadymarks = new list<Batch>; + steadymarks->clear(); + +} + +//------------------------------------------------------------------------------ +// Initialized Constructor +//------------------------------------------------------------------------------ +BatchPlace::BatchPlace(simuleau_name _name, double _speed, double _density, double _length):Place(_name) +{ + behaviour = Free_behaviour; + formalisation = no; + speed = _speed; + maxspeed = _speed; + instantaneousspeed = _speed; + density = _density; + length = _length; + + marks = new list<Batch>; + marks->clear(); + initialmarks = new list<Batch>; + initialmarks->clear(); + steadymarks = new list<Batch>; + steadymarks->clear(); + +} + +//------------------------------------------------------------------------------ +// Destructor +//------------------------------------------------------------------------------ +BatchPlace::~BatchPlace() +{ + if (marks) + delete[] marks; + if (initialmarks) + delete[] initialmarks; + if (steadymarks) + delete[] steadymarks; +} + +//------------------------------------------------------------------------------ +// Copy +//------------------------------------------------------------------------------ +void BatchPlace::Copy(const BatchPlace * _place) +{ + TransferNode(_place); + + conflict = _place->conflict; + structuralconflict = _place->structuralconflict; + + // batch place + behaviour = _place->behaviour; + formalisation = _place->formalisation; + + + density = _place->density; + speed = _place->speed; + maxspeed = _place->maxspeed; + instantaneousspeed = _place->instantaneousspeed; + + length = _place->length; + + marks = new list<Batch>; + marks->clear(); + + for (list<Batch>::iterator it=_place->marks->begin(); it!=_place->marks->end(); ++it) { + Batch *newbatch = new Batch; + newbatch->Copy(*it); + marks->push_back(*newbatch); + } + + initialmarks = new list<Batch>; + initialmarks->clear(); + + for (list<Batch>::iterator it=_place->initialmarks->begin(); it!=_place->initialmarks->end(); ++it) { + Batch *newbatch = new Batch; + newbatch->Copy(*it); + initialmarks->push_back(*newbatch); + } + + steadymarks = new list<Batch>; + steadymarks->clear(); + + for (list<Batch>::iterator it=_place->steadymarks->begin(); it!=_place->steadymarks->end(); ++it) { + Batch *newbatch = new Batch; + newbatch->Copy(*it); + steadymarks->push_back(*newbatch); + } + +} + +//------------------------------------------------------------------------------ +// It adds the initial marking of the place +//------------------------------------------------------------------------------ +void BatchPlace::AddBatchToInitialMarking(Batch &b) +{ + initialmarks->push_back(b); + marks->push_back(b); +} + +//------------------------------------------------------------------------------ +// It adds a batch to steady marking of the place +//------------------------------------------------------------------------------ +void BatchPlace::AddBatchToSteadyMarking(Batch &b) +{ + steadymarks->push_back(b); +} +//------------------------------------------------------------------------------ +// It adds a batch to marking of the place +//------------------------------------------------------------------------------ +void BatchPlace::AddBatchToMarking(Batch &b) +{ + marks->push_back(b); +} + +//------------------------------------------------------------------------------ +// It replace the current marking of a place +// TODO test this method +//------------------------------------------------------------------------------ +void BatchPlace::ChangeMarks(list<Batch> *lb) +{ + marks->clear(); + delete marks; + marks = lb; +} + +//------------------------------------------------------------------------------ +// It sets the new speed +//------------------------------------------------------------------------------ +void BatchPlace::SetSpeed(double _speed) +{ + speed = _speed; + instantaneousspeed = _speed; +} + +//------------------------------------------------------------------------------ +// It sets the new maximum speed +//------------------------------------------------------------------------------ +void BatchPlace::SetMaxSpeed(double _maxspeed) +{ + maxspeed = _maxspeed; +} + +//------------------------------------------------------------------------------ +// It sets the new density +//------------------------------------------------------------------------------ +void BatchPlace::SetDensity(double _density) +{ + density = _density; +} + +//------------------------------------------------------------------------------ +// It sets the new length +//------------------------------------------------------------------------------ +void BatchPlace::SetLength(double _length) +{ + length = _length; +} + +//------------------------------------------------------------------------------ +// It returns the current speed +//------------------------------------------------------------------------------ +double BatchPlace::GetSpeed() +{ + return (speed); +} + +//------------------------------------------------------------------------------ +// It returns the maximum/initial speed +//------------------------------------------------------------------------------ +double BatchPlace::GetMaxSpeed() +{ + return (maxspeed); +} + + +//------------------------------------------------------------------------------ +// It returns the instantaneous speed +//------------------------------------------------------------------------------ +double BatchPlace::GetInstantaneousSpeed() +{ + return (instantaneousspeed); +} + +//------------------------------------------------------------------------------ +// It returns the current density +//------------------------------------------------------------------------------ +double BatchPlace::GetDensity() +{ + return (density); +} + +//-------------------Near-optimal--------------------------------------------------------- +// It returns the free steady marking quantity +//----------------------------------------------------------------------------- +double BatchPlace::GetSteadyDensity() +{ + double steadydensity; + + if (steadymarks->size() != 0){ + for (list<Batch>::iterator b=steadymarks->begin(); b!=steadymarks->end();b++) { + steadydensity = b->GetDensity(); + } + } + return(steadydensity); +} + + + + +//------------------------------------------------------------------------------ +// It returns the length +//------------------------------------------------------------------------------ +double BatchPlace::GetLength() +{ + return (length); +} + +//------------------------------------------------------------------------------ +// It returns the place flow +//------------------------------------------------------------------------------ +double BatchPlace::GetOutputFlow() +{ + double outputflow = 0.0; + list<Batch>::iterator b; + + if(!HasOutputBatch()) + return outputflow; + + b = marks->begin(); + outputflow = b->GetOutputFlow(instantaneousspeed); + + return outputflow; +} + +//-----------------------------MCFF------------------------------------------------- +// It returns the place steadyinputflow or output flow in a place +//------------------------------------------------------------------------------ +double BatchPlace::GetSteadyPlaceFlow() +{ + double steadyplaceflow = 0.0; + Transition *t; + Flow *f; + + for (int i=0; i<numberofarcs; i++){ + if (inputarcs[i] != 0){ + t = (Transition*)inputnodes[i]; + f = t->GetFlow(); + steadyplaceflow += f->GetSteadyFlow(); + } + } + return (steadyplaceflow); +} + + +//------------------------------------------------------------------------------ +// It returns the place marks +//------------------------------------------------------------------------------ +list<Batch>* BatchPlace::GetMarking() +{ + return (marks); +} + +//------------------------------------------------------------------------------ +// It returns the place initial marks +//------------------------------------------------------------------------------ +list<Batch>* BatchPlace::GetInitialMarking() +{ + return (initialmarks); +} + +//------------------------------------------------------------------------------ +// It returns the place steady marks +//------------------------------------------------------------------------------ +list<Batch>* BatchPlace::GetSteadyMarking() +{ + return (steadymarks); +} + +//-------------------------------------- +//It returns the quantity +//-------------------------------------- +double BatchPlace::GetInitialQuantity() +{ + if (marks->size() != 0){ + for (list<Batch>::iterator b=marks->begin(); b!=marks->end(); b++) { + quantity += b->GetDensity() * b->GetLength(); + } + } + return(quantity); +} + +//---------------------------------------------------------------------------- +// It returns the free steady marking quantity +//----------------------------------------------------------------------------- +double BatchPlace::GetFreeSteadyQuantity() +{ + + double freesteadyquantity = 0.0; + double steadyplaceflow; + + Flow *f; + Transition *t; + + for (int i=0; i<numberofarcs; i++){ + if (inputarcs[i] != 0){ + t = (Transition*)inputnodes[i]; + f = t->GetFlow(); + steadyplaceflow += f->GetSteadyFlow(); + } + } + + if (steadymarks->size() == 1){ + for (list<Batch>::iterator b=steadymarks->begin(); b!=steadymarks->end();b++) { + if (b->GetDensity() == steadyplaceflow / maxspeed ){ + freesteadyquantity = b->GetDensity() * b->GetLength(); + } + else{ + freesteadyquantity = 0; + } + } + } + if (steadymarks->size() == 2){ + for (list<Batch>::iterator b=steadymarks->begin(); b!=steadymarks->end(); b++){ + freesteadyquantity = b->GetDensity() * b->GetLength(); + } + } + return(freesteadyquantity); +} + +//---------------------------------------------------------------------------- +// It returns the steady marking quantity +//----------------------------------------------------------------------------- + +double BatchPlace::GetSteadyQuantity() +{ + + if (steadymarks->size() != 0){ + for (list<Batch>::iterator b=steadymarks->begin(); b!=steadymarks->end(); b++) { + steadyquantity += b->GetDensity() * b->GetLength(); + } + return(steadyquantity); + +} +} + + + +//------------------------------------------------------------------------------ +// It returns the place behaviour +//------------------------------------------------------------------------------ +int BatchPlace::GetBehaviour() +{ + return (behaviour); +} + +//------------------------------------------------------------------------------ +// It returns the place behaviour +// We suppose only one output transition +// TODO verify if two or more tranistion +//------------------------------------------------------------------------------ +double BatchPlace::GetFlowOfOutputTransition() +{ + double outputtransitionflow = -1.0; + + Transition *t; + Flow *f; + + for (int i=0; i<numberofarcs; i++){ + if (outputarcs[i] != 0.0){ + t = outputnodes[i]; + switch (t->IsA()){ + case Batch_tr: f = t->GetFlow(); + outputtransitionflow = f->GetCurrentFlow(); + break; + } + } + } + return (outputtransitionflow); +} + +//------------------------------------------------------------------------------ +// It returns the output flow of all input transitions. +//------------------------------------------------------------------------------ +double BatchPlace::GetInputTransitonsFlow() +{ + double inflow = 0.0; + Transition *t; + Flow *f; + + for (int i=0; i<numberofarcs; i++){ + if (inputarcs[i] != 0.0){ + t = inputnodes[i]; + f = t->GetFlow(); + inflow += f->GetCurrentFlow(); + } + } + + return (inflow); +} + + +//------------------------------------------------------------------------------ +// It returns the output flow of all output transitions +//------------------------------------------------------------------------------ +double BatchPlace::GetOutputTransitonsFlow() +{ + double outflow = 0.0; + Transition *t; + Flow *f; + + for (int i=0; i<numberofarcs; i++){ + if (outputarcs[i] != 0.0){ + t = outputnodes[i]; + f = t->GetFlow(); + outflow += f->GetCurrentFlow(); + } + } + + return (outflow); +} + +//------------------------------------------------------------------------------ +// It returns true if the place has an output batch +//------------------------------------------------------------------------------ +int BatchPlace::HasOutputBatch() +{ + int result; + + Batch b; + + if (marks->size() == 0){ + result = 0; + } + else{ + b = marks->front(); + if ((length - b.GetPosition()) <= PRF::prf.Min_Err()){ + result = 1; + } + else{ + result = 0; + } + } + return (result); +} + + +//------------------------------------------------------------------------------ +// It returns the output batch +//------------------------------------------------------------------------------ +Batch* BatchPlace::GetOutputBatch() +{ + return (&marks->front()); +} + +//------------------------------------------------------------------------------ +// It returns the density of the output batch +//------------------------------------------------------------------------------ +double BatchPlace::GetDensityOutputBatch() +{ + double densityoutputbatch = 0.0; + Batch *b; + + if (HasOutputBatch()){ + b = GetOutputBatch(); + densityoutputbatch = b->GetDensity(); + } + return (densityoutputbatch); +} + +//------------------------------------------------------------------------------ +// It returns true if the batch place is full +//------------------------------------------------------------------------------ +int BatchPlace::IsFull() +{ + double full = length * density; + quantity = 0.0; + + if (marks->size() != 0){ + for (list<Batch>::iterator b=marks->begin(); b!=marks->end(); b++) { + quantity += b->GetDensity() * b->GetLength(); + } + if (abs(quantity - full) < PRF::prf.Min_Err()){ + return 1; + } + else{ + return 0; + } + } + else { + return 0; + } +} + +//===========================ON/Off============================================== +//------------------------------------------------------------------------------ +// It returns true if the batch place reaches steady marking quantity +//------------------------------------------------------------------------------ +int BatchPlace::IsEqualSteadyQuantity() +{ + ComputeQuantities(); + + if (abs(quantity - steadyquantity) < PRF::prf.Min_Err()){ + return 1; + } + else{ + return 0; + } +} + + +//------------------------------------------------------------------------------ +// It returns true if the marking quantity is greater than steady marking quantity +//------------------------------------------------------------------------------ +int BatchPlace::IsGreaterThanSteadyQuantity() +{ + ComputeQuantities(); + if ((quantity - steadyquantity) > PRF::prf.Min_Err()){ + return 1; + } + else{ + return 0; + } +} + + +//------------------------------------------------------------------------------ +// It returns true if the marking quantity is less than steady marking quantity +//------------------------------------------------------------------------------ +int BatchPlace::IsLessThanSteadyQuantity() +{ + + ComputeQuantities(); + + if (((abs(quantity - steadyquantity) > PRF::prf.Min_Err()) && ((quantity - steadyquantity) < 0.0))){ + return 1; + } + else{ + return 0; + } +} + +//------------------------------------------------------------------------------ +// It returns true if the marking is equal than steady marking +//------------------------------------------------------------------------------ +int BatchPlace::IsSteadyMarkingReached() +{ + if (steadymarks->size() != marks->size()) + return 0; + + list<Batch>::iterator b=marks->begin(); + if (steadymarks->size() != 0){ + for (list<Batch>::iterator sb=steadymarks->begin() ; sb!=steadymarks->end(); ++b,++sb) { + if(!sb->IsEqual(*b)) + return 0; + } + } + + return 1; +} +//============================================================================== + + +//===================Vecos================================================== +// It returns ture if the marking of continuous place is equal to steady marking +// and all of its input and output transition belongs to T_Z. +//========================================================================== +int BatchPlace::IsSteadyMarkingQuantityReachedandInputOutputTransitionBelongTz() +{ + Transition *t; + double weight; + int placestate =0; + int counter = 0; + int countertz=0; + + ComputeQuantities(); + + if (abs(steadyquantity - quantity) < PRF::prf.Min_Err()){ + if (GetNumberOfOutputArcs() == 0){ + return 1; // the conservative net and consistent net + } + else{ + for (int i=0; i<numberofarcs; i++){ + if (outputarcs[i] != 0.0){ +// t = simulation->sbpn->GetTransition(i); + t=outputnodes[i]; + counter++; + } + if (outputarcs[i] != 0.0 && t->IsFiringQuantityOnState()==0) + countertz++; + + } + } + + if (GetNumberOfInputArcs() == 0){ + return 1; // the conservative net and consistent net + } + else{ + for (int i=0; i<numberofarcs; i++){ + if (inputarcs[i] != 0.0){ +// t = simulation->sbpn->GetTransition(i); + t=inputnodes[i]; + counter++; + } + if (inputarcs[i] != 0.0 && t->IsFiringQuantityOnState()==0) + countertz++; + + } + } + if (counter == countertz) + return 1; + return placestate; + } + return placestate; +} + + + + + + + + + + +//------------------------------------------------------------------------------ +// It computes the state of the batch place +//------------------------------------------------------------------------------ +void BatchPlace::ComputeState() +{ + if (marks->empty()){ + state = 0.0; + } + else{ + if (HasOutputBatch() == 1){ + state = 1.0; + } + else{ + state = 0.0; + } + } +} + +//------------------------------------------------------------------------------ +// It creates a batch if the place has a least an input transition (continuous or batch) +// and the input flow is non-null +// It returns a positive value if a batch was created and 0 otherwise +// TODO verify multiple input transitions +//------------------------------------------------------------------------------ +int BatchPlace::CreateBatches() +{ + double inputtransflow = 0.0; + int result = 0; + + Transition *t; + Flow *f; + Batch *newb; + + formalisation = no; + + if (GetNumberOfInputArcs() != 0){ + for (int i=0; i<numberofarcs; i++){ + if (inputarcs[i] != 0.0){ + t = inputnodes[i]; + switch (t->IsA()){ + case Continuous_tr: + case Batch_tr: f = t->GetFlow(); + inputtransflow = f->GetCurrentFlow(); + if (inputtransflow > 0.0){ + if (!marks->empty()){ + Batch &b = marks->back(); + if ((b.GetLength() != 0.0 ) && (b.GetPosition() != 0.0)){ + newb = new Batch(inputtransflow, instantaneousspeed); + AddBatchToMarking(*newb); + i = numberofarcs; + result += 1; + } + } + else{ + newb = new Batch(inputtransflow, instantaneousspeed); + AddBatchToMarking(*newb); + i = numberofarcs; + result += 1; + } + } + break; + } + } + } + } +} + +//------------------------------------------------------------------------------ +// It merges the batch that have the same speed and density and are in contact +//------------------------------------------------------------------------------ +void BatchPlace::MergeBatches() +{ + int merged = 0; + double endposition; + double newlength; + int numberofbatches = marks->size(); + Batch *newbatch; + list<Batch> *newmarks = new list<Batch>; + list<Batch>::iterator b1, b2, bi; + + if (numberofbatches > 1){ + b1 = marks->begin(); + bi = marks->begin(); + bi++; + for (int i=1; i<numberofbatches; i++){ + endposition = b1->GetPosition() - b1->GetLength(); + b2 = bi; + + if ((abs(b1->GetDensity() - b2->GetDensity()) < PRF::prf.Min_Err()) && + (abs(b2->GetPosition() - endposition) < PRF::prf.Min_Err())){ // merge batches + newlength = b1->GetLength() + b2->GetLength(); + b1->SetLength(newlength); + bi++; + merged = 1; + } + else{ + newbatch = new Batch; + newbatch->Copy(*b1); + newmarks->push_back(*newbatch); + b1 = b2; + bi++; + merged = 0; + } + } + + newbatch = new Batch; + if (merged){ + newbatch->Copy(*b1); + } + else{ + newbatch->Copy(*b2); + } + + newmarks->push_back(*newbatch); + marks->clear(); + marks = newmarks; + } +} + +//------------------------------------------------------------------------------ +// It destructs the batches that have a length or density equal to 0 and are not +// the input batch (position equal to length) +//------------------------------------------------------------------------------ +void BatchPlace::DestructBatches() +{ + int numberofbatches = marks->size(); + Batch *newbatch; + list<Batch> *newmarks = new list<Batch>; + list<Batch>::iterator b1; + + double batchquantity = 1.0; + + if (numberofbatches != 0){ + for (b1=marks->begin(); b1!=marks->end(); ++b1) { + batchquantity = b1->GetDensity() * b1->GetLength() ; +// last next date + if ((b1->GetPosition() - PRF::prf.Min_Err() ) > length){ + b1->SetLength(0.0); + b1->SetPosition(length); + } +// end + +// maybe compute batchquantity as a pourcentage of the total place capacity + + if (((b1->GetLength() > PRF::prf.Min_Err()) || (batchquantity > (PRF::prf.Min_Err()/10))) || ((b1->GetPosition() == 0.0) && (b1->GetLength() == 0.0))){ + newbatch = new Batch; + newbatch->Copy(*b1); + newmarks->push_back(*newbatch); + } + } + marks->clear(); + marks = newmarks; + } +} + +//------------------------------------------------------------------------------ +// It destructs the batches that have a length or density equal to 0 and are not +// the input batch (position equal to length) +//------------------------------------------------------------------------------ +void BatchPlace::ComputeQuantities() +{ + steadyquantity = 0.0; + quantity = 0.0; + + if (steadymarks->size() != 0){ + for (list<Batch>::iterator b=steadymarks->begin(); b!=steadymarks->end(); b++) { + steadyquantity += b->GetDensity() * b->GetLength(); + } + } + + if (marks->size() != 0){ + for (list<Batch>::iterator b=marks->begin(); b!=marks->end(); b++) { + quantity += b->GetDensity() * b->GetLength(); + } + } +} + + + +//--------------------------------------------------------------------------------------------- +// It computes that two types of quantity in the free part and accumulated part of steady state. +//---------------------------------------------------------------------------------------------- +//void BatchPlace::ComputeTwoTypesSteadyQuantities() +//{ +// steadyquantity = 0.0; +// double freesteadyquantity = 0.0; +// double accumulatedsteadyquantity = 0.0; +// +// +// if (steadymarks->size() != 0){ +// for (list<Batch>::iterator b=steadymarks->begin(); b!=steadymarks->end(); b++) { +// steadyquantity += b->GetDensity() * b->GetLength(); +// } +// } +// +// if (steadymarks->size() ==2){ +// for (list<Batch>::iterator b=steadymarks->begin(); b!=steadymarks->begin(); b++) { +// freesteadyquantity += b->GetDensity() * b->GetLength(); +// accumulatedsteadyquantity = steadyquantity-freesteadyquantity; +// } +// } +// if (steadymarks->size() ==1){ +// for (list<Batch>::iterator b=steadymarks->begin(); b!=steadymarks->begin(); b++){ +// if ( GetSteadyPlaceFlow() == b->GetDensity() * GetSpeed() ){ +// freesteadyquantity = b->GetDensity() * b->GetLength(); +// accumulatedsteadyquantity = 0.0; +// } +// else{ +// freesteadyquantity = 0.0; +// accumulatedsteadyquantity = b->GetDensity() * b->GetLength(); +// } +// } +// } +// } + + +//------------------------------------------------------------------------------ +// It computes the behaviour of a batch place +// TODO all batch places have no structural conflit +//------------------------------------------------------------------------------ +void BatchPlace::ComputeBehaviour() +{ + double outputtransitionflow; + double outputtransitionflowth; + Transition *t; + Flow *f; + + if (state == 0.0){ + behaviour = Free_behaviour; + return; + } + + outputtransitionflow = GetOutputTransitonsFlow(); // all output transitions flow + outputtransitionflowth = GetOutputFlow(); + + if (outputtransitionflow < outputtransitionflowth){ + behaviour = Accumulating_behaviour; + } + else{ + behaviour = Free_behaviour; + } + +/* for (int i=0; i<numberofarcs; i++){ + if (outputarcs[i] != 0.0){ + t = outputnodes[i]; + switch (t->IsA()){ + case Batch_tr: f = t->GetFlow(); + //outputtransitionflow = f->GetCurrentFlow(); + ((BatchTransition*)t)->ComputeInputTheoreticalFlow(); + outputtransitionflowth = ((BatchTransition*)t)->GetInputTheoreticalFlow(); + if (outputtransitionflow < outputtransitionflowth){ + behaviour = Accumulating_behaviour; + } + else{ + behaviour = Free_behaviour; + } + break; + } + } + }*/ +} + + +//------------------------------------------------------------------------------ +// It evolves the marks (batches) of the batch place +//------------------------------------------------------------------------------ +void BatchPlace::EvolveMarks(double _date) +{ + Batch *ob; + list<Batch>::iterator b; + + if (formalisation == yes) + return; + + if (behaviour == Free_behaviour){ + EvolveInFreeBehaviour(simulation->stime); + } + else{ + if (HasOutputBatch() == 1){ // place is in accumulating behaviour and has an output batch + ob = GetOutputBatch(); + if ((density - ob->GetDensity()) <= PRF::prf.Min_Err()){ // the output batch is full accumulated + if (marks->size() > 1){ // new marking depends of a second batch + b = marks->begin(); + b++; + if (b->GetPosition() > (length - ob->GetLength())){ + b->SetPosition(length - ob->GetLength()); + } + + if (abs(b->GetPosition() - (length - ob->GetLength())) <= PRF::prf.Min_Err()) { // two batches are in contact + EvolveInPartiallyAccumulatedBehaviour(simulation->stime); + } + else{ // batch are not in contact + EvolveInAccumulatedOutputBehaviour(simulation->stime); + } + } + else{ // only one batch + EvolveInAccumulatedOutputBehaviour(simulation->stime); + } + } + else{ // the output batch has a different density of the place density + EvolveInFreeToAccumulatedBehaviour(simulation->stime); + } + } + } + formalisation == yes; + steadyquantity = 0.0; + if (steadymarks->size() != 0){ + for (list<Batch>::iterator b=steadymarks->begin(); b!=steadymarks->end(); b++) { + steadyquantity += b->GetDensity() * b->GetLength(); + } + } + quantity = 0.0; + if (marks->size() != 0){ + for (list<Batch>::iterator b=marks->begin(); b!=marks->end(); b++) { + quantity += b->GetDensity() * b->GetLength(); + } + } + +} + +//------------------------------------------------------------------------------ +// It computes the date of the next event to a Batch becomes an Output Batch type +// returns -1.0 if no BOB event is possible +//------------------------------------------------------------------------------ +double BatchPlace::GetBOBEvent() +{ + double pos; + double date; + Batch b; + + if (marks->empty()){ + return (-1.0); // no event of this type + } + + if (state != 1.0){ + b = marks->front(); + pos = b.GetPosition(); + date = (length - pos) / instantaneousspeed; + date += simulation->stime->GetCurrentDate(); + return (date); + } + return (-1.0); +} + + +//------------------------------------------------------------------------------ +// It computes the date of the next event to a Destruction of an Output Batch type +//------------------------------------------------------------------------------ +double BatchPlace::GetDOBEvent() +{ + double date = -1.0; + double outputtransitionflow = GetOutputTransitonsFlow(); + Transition *t; + Flow *f; + Batch *b; + + if (HasOutputBatch() == 1){ + b = GetOutputBatch(); + if ((density - b->GetDensity()) > PRF::prf.Min_Err()){ + if ((behaviour == Free_behaviour) && (instantaneousspeed != 0.0)){ + date = simulation->stime->GetCurrentDate() + (b->GetLength()/instantaneousspeed); + } + } + else{ + if (outputtransitionflow != 0.0){ + date = b->GetLength() * density / outputtransitionflow; + date += simulation->stime->GetCurrentDate(); + } +/* for (int i=0; i<numberofarcs; i++){ + if (outputarcs[i] != 0.0){ + t = outputnodes[i]; + switch (t->IsA()){ + case Batch_tr: f = t->GetFlow(); + outputtransitionflow = f->GetCurrentFlow(); + if (outputtransitionflow != 0.0){ + date = b->GetLength() * density / outputtransitionflow; + date += simulation->stime->GetCurrentDate(); + } + break; + } + } + } +*/ + } + } + return (date); +} + + +//------------------------------------------------------------------------------ +// It computes the date of the next event to a Full accumulation/congestion of a batch +// (Batch Becomes Dense) type +//------------------------------------------------------------------------------ +double BatchPlace::GetBBDEvent() +{ + double date = -1.0; + double outputtransitionflow = GetOutputTransitonsFlow(); + Transition *t; + Flow *f; + Batch *b; + + if (HasOutputBatch() == 1){ + b = GetOutputBatch(); + if ((density - b->GetDensity()) > PRF::prf.Min_Err()){ + if ((behaviour == Accumulating_behaviour)){ + if (((instantaneousspeed * density) - outputtransitionflow) != 0.0){ + date = b->GetLength() * (density - b->GetDensity()) / (instantaneousspeed * density - outputtransitionflow); + date += simulation->stime->GetCurrentDate(); + } + +/* + for (int i=0; i<numberofarcs; i++){ + if (outputarcs[i] != 0.0){ + t = outputnodes[i]; + switch (t->IsA()){ + case Batch_tr: f = t->GetFlow(); + outputtransitionflow = f->GetCurrentFlow(); + if (((instantaneousspeed * density) - outputtransitionflow) != 0.0){ + date = b->GetLength() * (density - b->GetDensity()) / (instantaneousspeed * density - outputtransitionflow); + date += simulation->stime->GetCurrentDate(); + } + break; + } + } + } +*/ + } + } + } + return (date); +} + + +//------------------------------------------------------------------------------ +// It computes the date of the next event to Two Batches Meet type +// TODO verify multiple output transitions +//------------------------------------------------------------------------------ +double BatchPlace::GetTBMEvent() +{ + double date = -1.0; + double outputtransitionflow = GetOutputTransitonsFlow(); + Transition *t; + Flow *f; + list<Batch>::iterator b; + Batch *outputbatch; + + if ((marks->size() < 2) || (HasOutputBatch() == 0)){ + return (date); + } + + outputbatch = GetOutputBatch(); + b = marks->begin(); + b++; + if (((density - outputbatch->GetDensity()) < PRF::prf.Min_Err()) && (behaviour == Accumulating_behaviour)){ + if (((length - outputbatch->GetLength()) - b->GetPosition()) > PRF::prf.Min_Err()){ + if ((instantaneousspeed * density - outputtransitionflow) != 0.0){ + date = (density * (length - outputbatch->GetLength() - b->GetPosition())/(instantaneousspeed * density - outputtransitionflow)); + date += simulation->stime->GetCurrentDate(); + } + + +/* for (int i=0; i<numberofarcs; i++){ + if (outputarcs[i] != 0.0){ + t = outputnodes[i]; + switch (t->IsA()){ + case Batch_tr : f = t->GetFlow(); + outputtransitionflow = f->GetCurrentFlow(); + if ((instantaneousspeed * density - outputtransitionflow) != 0.0){ + date = (density * (length - outputbatch->GetLength() - b->GetPosition())/(instantaneousspeed * density - outputtransitionflow)); + date += simulation->stime->GetCurrentDate(); + } + break; + } + } + } +*/ + } + else{ + if (((density - b->GetDensity()) > PRF::prf.Min_Err()) && (instantaneousspeed != 0.0) && (density != 0.0) && (b->GetLength() != 0.0)){ +// outputtransitionflow = GetOutputTransitonsFlow(); + date = (density - b->GetDensity()) * b->GetLength()/(instantaneousspeed * density - outputtransitionflow); + date += simulation->stime->GetCurrentDate(); + } + } + } + return (date); +} + +//----------------- On off considered events------------------------------------------------- +// It computes the date of the next event to marking quantity of a batch place +// reaches its steady marking quantity (Place reaches Steady marking Quantity). +//------------------------------------------------------------------------------ +double BatchPlace::GetPSQEvent() +{ + double steadyquantity; // we need input this value before the simulation. !!! + double quantity = 0.0; + double date; + double transitionflow=0.0; + double weightflow=0.0; + Batch *b; + Transition *t; + Flow *f; + + if (steadymarks->size() != 0){ + for (list<Batch>::iterator b=steadymarks->begin(); b!=steadymarks->end(); b++) { + steadyquantity += b->GetDensity() * b->GetLength(); + } + } + + if (marks->size() != 0){ + for (list<Batch>::iterator b=marks->begin(); b!=marks->end(); b++) { + quantity += b->GetDensity() * b->GetLength(); + } + } + + if (abs(quantity - steadyquantity) < PRF::prf.Min_Err()){ + date= simulation->stime->GetCurrentDate(); + } + + else{ + if (GetNumberOfOutputArcs()){ + for (int i=0; i<numberofarcs; i++){ + if (outputarcs[i] != 0.0){ +// t = simulation->sbpn->GetTransition(i); + t = outputnodes[i]; + switch (t->IsA()){ + case Continuous_tr: + case Batch_tr: f = t->GetFlow(); + transitionflow = f->GetCurrentFlow(); + weightflow -= (outputarcs[i] * transitionflow); + break; + } + } + } + } + + if (GetNumberOfInputArcs()){ + for (int i=0; i<numberofarcs; i++){ + if (inputarcs[i] != 0){ +// t = simulation->sbpn->GetTransition(i); + t = inputnodes[i]; + switch (t->IsA()){ + case Continuous_tr: + case Batch_tr: f = t->GetFlow(); + transitionflow = f->GetCurrentFlow(); + + weightflow += (inputarcs[i] * transitionflow); + + break; + } + } + } + } + + if ((weightflow != 0.0)){ + date = simulation->stime->GetCurrentDate() - ((quantity-steadyquantity)/weightflow); + } + return (date); +} +} + + + + + + + /* if (HasOutputBatch() == 1){ + b = GetOutputBatch(); + if ((density - b->GetDensity()) > PRF::prf.Min_Err()){ + for (int i=0; i<numberofarcs; i++){ + if (outputarcs[i] != 0.0){ + t = outputnodes[i]; + switch (t->IsA()){ + case Batch_tr: u = t->GetFlow(); + outputtransitionflow = u->GetCurrentFlow(); + if (((instantaneousspeed * density) - outputtransitionflow) != 0.0){ + date = b->GetLength() * (density - b->GetDensity()) / (instantaneousspeed * density - outputtransitionflow); + date += simulation->stime->GetCurrentDate(); + } + break; + } + } + } + } + } + return (date); +} +} +*/ + +//-----------------------end---------------------------------------------------- + +//------------------------------------------------------------------------------ +// Print +//------------------------------------------------------------------------------ +void BatchPlace::Print(ostream& fout) +{ + fout << "Name: " << name << endl; + fout << " Type: " << "Batch" << endl; + fout << " Behaviour: " << behaviour << endl; + fout << " Density: " << density << endl; + fout << " Maximum speed: " << maxspeed << endl; + fout << " Speed: " << speed << endl; + fout << " Length: " << length << endl; + fout << " Initial Batches:" << initialmarks->size() << endl; + + for (list<Batch>::iterator it=initialmarks->begin(); it!=initialmarks->end(); ++it) { + it->Print(fout); + } + + if (!steadymarks->empty()){ + fout << " Steady Batches:" << steadymarks->size() << endl; + + for (list<Batch>::iterator it=steadymarks->begin(); it!=steadymarks->end(); ++it) { + it->Print(fout); + } + } + + fout << " Batches: " << marks->size() << endl; + + for (list<Batch>::iterator it=marks->begin(); it!=marks->end(); ++it) { + it->Print(fout); + } + + fout << " Arcs: " << endl; + PrintArcs(fout); +} + +//------------------------------------------------------------------------------ +// Write +//------------------------------------------------------------------------------ +void BatchPlace::Write(ostream &fout) +{ + ComputeQuantities(); + fout << "Name: " << name << endl; + fout << " Type: " << "Batch" << endl; + fout << " Density: " << density << endl; + fout << " Speed: " << speed << endl; + fout << " Length: " << length << endl; + fout << " Batches: " << marks->size() << ": " << quantity << endl; + + for (list<Batch>::iterator it=marks->begin(); it!=marks->end(); ++it) { + it->Write(fout); + } + + if (!steadymarks->empty()){ + fout << " Steady Batches:" << steadymarks->size() ; + if (IsSteadyMarkingReached()) + fout << "(steady marking reached) "; + fout << ": " << steadyquantity << endl; + + for (list<Batch>::iterator it=steadymarks->begin(); it!=steadymarks->end(); ++it) { + it->Write(fout); + } + } +} + +//------------------------------------------------------------------------------ +// It evolves the marking in a free behaviour +// old fonctionRL +//------------------------------------------------------------------------------ +void BatchPlace::EvolveInFreeBehaviour(Simtime *st) +{ + if (!marks->empty()){ + for (list<Batch>::iterator b = marks->begin(); b!=marks->end(); b++){ + b->EvolveInFreeBehaviour(st, this); + } + } +} + +//------------------------------------------------------------------------------ +// It evolves the marking in a accumulated output behaviour +// Non other batch in contact with the output batch +// old fonctionSA +// TODO verify structural conflit +//------------------------------------------------------------------------------ +void BatchPlace::EvolveInAccumulatedOutputBehaviour(Simtime *st) +{ + int i; + double flowofoutputtransition = GetOutputTransitonsFlow(); + Transition *t; + Flow *f; + list<Batch>::iterator b; + + if (!marks->empty()){ + for (i=0, b = marks->begin(); b!=marks->end(); b++, i++){ + if ((HasOutputBatch()) && (i == 0)){ // the accumulated output batch + b->EvolveInAccumulatedOuputBehaviour(st, this, flowofoutputtransition); +/* for (int j=0; j<numberofarcs; j++){ + if (outputarcs[j] != 0.0){ + t = outputnodes[j]; + switch (t->IsA()){ + case Batch_tr : f = t->GetFlow(); + flowofoutputtransition = f->GetCurrentFlow(); + b->EvolveInAccumulatedOuputBehaviour(st, this, flowofoutputtransition); + break; + } + } + } +*/ + + } + else{ + b->EvolveInFreeBehaviour(st, this); // other free batches + } + } + } + +} + +//------------------------------------------------------------------------------ +// It evolves the marking when it has an output batch and a second batch in contact not completely accumulated +// old fonctionRAP +//------------------------------------------------------------------------------ +void BatchPlace::EvolveInPartiallyAccumulatedBehaviour(Simtime *st) +{ + int i; + double flowofoutputtransition = GetOutputTransitonsFlow(); + double lengthofoutputbatch; + Batch *newbatch, *newbatch2; + Batch *outputbatch; + list<Batch> *newmarks = new list<Batch>; + list<Batch>::iterator b; + + newmarks->clear(); + + if (!marks->empty()){ + for (i=0, b = marks->begin(); b!=marks->end(); b++, i++){ + if ((HasOutputBatch()) && (i == 0)){ // output batch + b->EvolveInAccumulatedOuputBehaviour(st, this, flowofoutputtransition); + newbatch = new Batch; + newbatch->Copy(*b); + newmarks->push_back(*newbatch); + } + else{ + if (i == 1){ // first batch after output batch + outputbatch = GetOutputBatch(); + lengthofoutputbatch = outputbatch->GetLength(); + newbatch = new Batch; + newbatch->Copy(*b); + newbatch->EvolveInPartiallyAccumulatedBehaviourAccBatch(st, this, lengthofoutputbatch, flowofoutputtransition); + + newbatch2 = new Batch; + newbatch2->Copy(*b); + newbatch2->EvolveInPartiallyAccumulatedBehaviourFreeBatch(st, this, lengthofoutputbatch, newbatch->GetLength(), flowofoutputtransition); + + newmarks->push_back(*newbatch); + newmarks->push_back(*newbatch2); + } + else{ + newbatch = new Batch; + newbatch->Copy(*b); + newbatch->EvolveInFreeBehaviour(st, this); + newmarks->push_back(*newbatch); + } + } + } + marks->clear(); + marks = newmarks; + } +} + + +//------------------------------------------------------------------------------ +// It evolves the marking when the batch passe from free to accumulated +// old fonctionRLA +//------------------------------------------------------------------------------ +void BatchPlace::EvolveInFreeToAccumulatedBehaviour(Simtime *st) +{ + double outputtransitionflow = GetOutputTransitonsFlow();; + int i; + double lengthofoutputbatch; + Batch *newbatch, *newbatch2; + Batch outputbatch; + list<Batch> *newmarks = new list<Batch>; + list<Batch>::iterator b; + Transition *t; + Flow *f; + + if (!marks->empty()){ + for (i=0, b = marks->begin(); b!=marks->end(); b++, i++){ + if ((HasOutputBatch()) && (i == 0)){ // output batch + newbatch = new Batch; + newbatch->Copy(*b); + newbatch->EvolveInFreeToAccumulatedBehaviourAccBatch(st, this, outputtransitionflow); + + newbatch2 = new Batch; + newbatch2->Copy(*b); + newbatch2->EvolveInFreeToAccumulatedBehaviourFreeBatch(st, this, newbatch->GetLength(), outputtransitionflow); + + newmarks->push_back(*newbatch); + newmarks->push_back(*newbatch2); +/* for (int j=0; j<numberofarcs; j++){ + if (outputarcs[j] != 0.0){ + t = outputnodes[j]; + switch (t->IsA()){ + case Batch_tr : f = t->GetFlow(); + _flow = f->GetCurrentFlow(); + newbatch = new Batch; + newbatch->Copy(*b); + newbatch->EvolveInFreeToAccumulatedBehaviourAccBatch(st, this, _flow); + + newbatch2 = new Batch; + newbatch2->Copy(*b); + newbatch2->EvolveInFreeToAccumulatedBehaviourFreeBatch(st, this, newbatch->GetLength(), _flow); + + newmarks->push_back(*newbatch); + newmarks->push_back(*newbatch2); + break; + } + } + } +*/ + } + else{ + newbatch = new Batch; + newbatch->Copy(*b); + newbatch->EvolveInFreeBehaviour(st, this); + newmarks->push_back(*newbatch); + } + } + marks->clear(); + marks = newmarks; + } +} + +//-----------------------------------Near-optimal case--------------------------------------------- +// It returns ture if the batch place satisies the conditions. +// condition: 1) It has an output batch whose density greater than d_i^s +// 2) The last several batches having marking quantity greater than free steady marking quantity -mininus the quantity of +// first steady batch +// 3) Before output batch is destroyed, the next batch becomes output batch, we assume that it keeps a steady output flow value. +//-------------------------------------------------------------------------------------------------- +int BatchPlace::IsHoldSteadyPlaceFlowUntilSteadyState() +{ + double frontquantity; + double remainingfreesteadyquantity; + double currentfreesteadyquantity; + int placestate = 0; + Transition *t; + list<Batch>::iterator bl; + Batch *outputbatch; + Batch bf; + + if ((marks->size() == 0) || (HasOutputBatch() == 0) || (IsSteadyMarkingQuantityReachedandInputOutputTransitionBelongTz() == 1)){ + return 0; + } + bl = marks->begin(); + + if (bl->GetDensity() != GetSteadyDensity()){ + currentfreesteadyquantity = 0; + } + else{ + currentfreesteadyquantity = bl->GetDensity() * bl->GetLength(); + } + + + outputbatch = GetOutputBatch(); + bf = marks->front(); + + if (GetSteadyDensity() >= outputbatch->GetDensity() ){ + frontquantity = outputbatch->GetDensity() * outputbatch->GetLength(); + if (frontquantity >= (GetFreeSteadyQuantity()-currentfreesteadyquantity)){ + // bf++; + } + } +} + +// if (((length - outputbatch->GetLength()) - b->GetPosition()) > PRF::prf.Min_Err()){ +// if ((instantaneousspeed * density - outputtransitionflow) != 0.0){ +// date = (density * (length - outputbatch->GetLength() - b->GetPosition())/(instantaneousspeed * density - outputtransitionflow)); +// date += simulation->stime->GetCurrentDate(); +// } +// +//// +//// +//// +////} +// +// +////int BatchPlace::IsSteadyMarkingQuantityReachedandInputOutputTransitionBelongTz() +////{ +//// Transition *t; +//// double weight; +//// int placestate =0; +//// int counter = 0; +//// int countertz=0; +//// +//// ComputeQuantities(); +//// +//// if (abs(steadyquantity - quantity) < PRF::prf.Min_Err()){ +//// if (GetNumberOfOutputArcs() == 0){ +//// return 1; // the conservative net and consistent net +//// } +//// else{ +//// for (int i=0; i<numberofarcs; i++){ +//// if (outputarcs[i] != 0.0){ +////// t = simulation->sbpn->GetTransition(i); +//// t=outputnodes[i]; +//// counter++; +//// } +//// if (outputarcs[i] != 0.0 && t->IsFiringQuantityOnState()==0) +//// countertz++; +//// +//// } +//// } +//// +//// if (GetNumberOfInputArcs() == 0){ +//// return 1; // the conservative net and consistent net +//// } +//// else{ +//// for (int i=0; i<numberofarcs; i++){ +//// if (inputarcs[i] != 0.0){ +////// t = simulation->sbpn->GetTransition(i); +//// t=inputnodes[i]; +//// counter++; +//// } +//// if (inputarcs[i] != 0.0 && t->IsFiringQuantityOnState()==0) +//// countertz++; +//// +//// } +//// } +//// if (counter == countertz) +//// return 1; +//// return placestate; +//// } +//// return placestate; +////} +// steadyquantity = 0.0; +// double freesteadyquantity = 0.0; +// double accumulatedsteadyquantity = 0.0; +// +// +// if (steadymarks->size() != 0){ +// for (list<Batch>::iterator b=steadymarks->begin(); b!=steadymarks->end(); b++) { +// steadyquantity += b->GetDensity() * b->GetLength(); +// } +// } +// +// if (steadymarks->size() ==2){ +// for (list<Batch>::iterator b=steadymarks->begin(); b!=steadymarks->begin(); b++) { +// freesteadyquantity += b->GetDensity() * b->GetLength(); +// steadydensity=b->GetInstan +// accumulatedsteadyquantity = steadyquantity-freesteadyquantity; +// } +// } +// if (steadymarks->size() ==1){ +// for (list<Batch>::iterator b=steadymarks->begin(); b!=steadymarks->begin(); b++){ +// if ( p->GetSteadyPlaceFlow() == b->GetDensity() * p->GetSpeed() ){ +// freesteadyquantity = b->GetDensity() * b->GetLength(); +// accumulatedsteadyquantity = 0.0; +// } +// else{ +// freesteadyquantity = 0.0; +// accumulatedsteadyquantity = b->GetDensity() * b->GetLength(); +// } +// } +// } + + + diff --git a/src/bpn/batchtransition.cpp b/src/bpn/batchtransition.cpp new file mode 100644 index 0000000000000000000000000000000000000000..b1766f4dfaf90540d1845998f650fcfae82c2476 --- /dev/null +++ b/src/bpn/batchtransition.cpp @@ -0,0 +1,269 @@ + +//====================================================================================// +// // +// Batch transition classes inherit of continuous transition class // +// // +//====================================================================================// +// This File: batchtransition.cpp Language: C++ (xlC and CC) // +// Software: SIMULEAU // +//====================================================================================// +// Creation: 22/apr/16 by: Leonardo.Brenner@lsis.org // +// Last Change: 22/apr/16 by: Leonardo.Brenner@lsis.org // +//====================================================================================// +#include "simuleau.h" + +//------------------------------------------------------------------------------ +//------------------------------------------------------------------------------ +// Methods of the Batch Transition class +//------------------------------------------------------------------------------ +//------------------------------------------------------------------------------ + +//------------------------------------------------------------------------------ +// Constructor +//------------------------------------------------------------------------------ +BatchTransition::BatchTransition():ContinuousTransition() +{ + inputtheoreticalflow = -1.0; + outputtheoreticalflow = -1.0; +} + +//------------------------------------------------------------------------------ +// Initialized Constructor +//------------------------------------------------------------------------------ +BatchTransition::BatchTransition(simuleau_name _name, double _flow, double _steadyflow):ContinuousTransition(_name, _flow, _steadyflow) +{ + inputtheoreticalflow = -1.0; + outputtheoreticalflow = -1.0; +} + +//------------------------------------------------------------------------------ +// Destructor +//------------------------------------------------------------------------------ +BatchTransition::~BatchTransition() +{ + if (flow) + delete flow; +} + +//------------------------------------------------------------------------------ +// Copy +//------------------------------------------------------------------------------ +void BatchTransition::Copy(const BatchTransition *_transition) +{ + TransferNode(_transition); + flow = new Flow; + flow->Copy(_transition->flow); // transition flows + firingquantity = new FiringQuantity; + firingquantity->Copy(_transition->firingquantity); + inputtheoreticalflow = _transition->inputtheoreticalflow; + outputtheoreticalflow = _transition->outputtheoreticalflow; +} + +//------------------------------------------------------------------------------ +// It returns the input theoretical flow +//------------------------------------------------------------------------------ +double BatchTransition::GetInputTheoreticalFlow() +{ + return (inputtheoreticalflow); +} + +//------------------------------------------------------------------------------ +// It returns the output theoretical flow +//------------------------------------------------------------------------------ +double BatchTransition::GetOutputTheoreticalFlow() +{ + return (outputtheoreticalflow); +} + +//------------------------------------------------------------------------------ +// It computes the input theoretical flow +//------------------------------------------------------------------------------ +void BatchTransition::ComputeInputTheoreticalFlow() +{ + BatchPlace *p; + list<Batch>::iterator b; + list<Batch> *placemarks; + + double placespeed; + double placestate; + + + if (GetNumberOfInputArcs() == 0){ + inputtheoreticalflow = -1.0; // no input place, infinite flow + return; + } + + for (int i=0; i<numberofarcs; i++){ + if (inputarcs[i] != 0.0){ + p = inputnodes[i]; + switch (p->IsA()){ + case Batch_pl: + case Triangular_pl: placestate = p->GetState(); + if (placestate == 1.0){ // test for output batch + placespeed = p->GetInstantaneousSpeed(); + placemarks = p->GetMarking(); + b = placemarks->begin(); + inputtheoreticalflow = b->GetOutputFlow(placespeed); + } + else{ + inputtheoreticalflow = 0.0; + } + i = numberofarcs; + break; + default: inputtheoreticalflow = -1.0; + break; + } + } + } +} + +//------------------------------------------------------------------------------ +// It computes the output theoretical flow +// TODO verify why only one conection is used +//------------------------------------------------------------------------------ +void BatchTransition::ComputeOutputTheoreticalFlow() +{ + BatchPlace *p; + double placespeed; + double placedensity; + + if (GetNumberOfOutputArcs() == 0){ + outputtheoreticalflow = -1.0; // no input place, infinite flow + return; + } + + outputtheoreticalflow = -1.0; + for (int i=0; i<numberofarcs; i++){ + if (outputarcs[i] != 0.0){ + p = outputnodes[i]; + switch (p->IsA()){ + case Batch_pl: + case Triangular_pl: placespeed = p->GetSpeed(); + placedensity = p->GetDensity(); + outputtheoreticalflow = placedensity * placespeed; + break; + } + } + } +} + + +//------------------------------------------------------------------------------ +// It computes the transition theoretical flow +//------------------------------------------------------------------------------ +void BatchTransition::ComputeTheoreticalFlow() +{ + double flowvalue; + + if (state == 0.0){ + flow->SetTheoreticalFlow(0.0); + return; + } + + ComputeInputTheoreticalFlow(); + ComputeOutputTheoreticalFlow(); + if (state == 1.0){ + flowvalue = ComputeMinimumFlow(flow->GetMaximumFlow(), inputtheoreticalflow); + flowvalue = ComputeMinimumFlow(flowvalue, outputtheoreticalflow); + } + else{ + flowvalue = ComputeMinimumFlow(flow->GetMaximumFlow(), inputtheoreticalflow); + flowvalue = ComputeMinimumFlow(flowvalue, outputtheoreticalflow); + flowvalue = ComputeMinimumFlow(flowvalue, ComputeTheoreticalFlowOfPlace()); + } + flow->SetTheoreticalFlow(flowvalue); +} + + +//------------------------------------------------------------------------------ +// Print +//------------------------------------------------------------------------------ +void BatchTransition::Print(ostream &fout) +{ + fout << "Name: " << name << endl; + fout << " Type: " << "Batch" << endl; + fout << " Flow: " << endl; + flow->Print(fout); + fout << " Arcs: " << endl; + PrintArcs(fout); +} + +//------------------------------------------------------------------------------ +// It writes the transition flows +//------------------------------------------------------------------------------ +void BatchTransition::Write(ostream &fout) +{ + fout << "Name: " << name << endl; + fout << " Type: " << "Batch" << endl; + fout << " State: " << state << endl; + fout << " Current Flow: " << flow->GetCurrentFlow() << endl; + if (flow->GetSteadyFlow() != -1.0) + fout << " Steady Flow: " << flow->GetSteadyFlow() << endl; +} + + +//========================RBF========Event================================= +// It gets the rbf event. (a new ) objective : +//=========================================================================== +double BatchTransition::GetRBFEvent() +{ + double date; + double min_date=-1.0; + double weight; + double transitionflow; + Place *p; +// Transition *t; +// FiringQuantity *q; + double Zs; + double z; + + // q=t->GetFiringQuantity(); + Zs=firingquantity->GetSteadyFiringQuantity(); + z =firingquantity->GetCurrentFiringQuantity(); + + if (GetNumberOfOutputArcs() == 0){ + return (-1.0); + } + else if(z >= Zs){ + return (-1.0); + } + else{ + for (int i=0; i<numberofarcs; i++){ + if (outputarcs[i] != 0){ +// p = simulation->sbpn->GetPlace(i); + p = (Place*)outputnodes[i]; + + weight = outputarcs[i]; + // f=t->GetFlow(); + transitionflow=flow->GetCurrentFlow(); + switch (p->IsA()){ + case Continuous_pl : + date = (Zs-z) / transitionflow; // FreeSteadyMarkingQuantity= 0 in P^C + date += simulation->stime->GetCurrentDate(); + + break; + case Batch_pl : + date = (Zs-z -(((BatchPlace*)p)->GetFreeSteadyQuantity() / weight)) / transitionflow; + if (date < 0){ + return (-1.0); + } + else{ + date += simulation->stime->GetCurrentDate(); + + } + break; + + } + + if (date < min_date || min_date==-1.0){ + min_date= date; + } + } + + + } + return (min_date); + } + return (-1.0); +} +//----------------------------------------------------------------------------------- diff --git a/src/bpn/bpn.cpp b/src/bpn/bpn.cpp new file mode 100644 index 0000000000000000000000000000000000000000..539a62620f49b8edff6bfcc649a1c8c3cc9d0ad2 --- /dev/null +++ b/src/bpn/bpn.cpp @@ -0,0 +1,4117 @@ + +//====================================================================================// +// // +// Batch Petri Nets main class // +// // +//====================================================================================// +// This File: bpn.cpp Language: C++ (xlC and CC) // +// Software: SIMULEAU // +//====================================================================================// +// Creation: 21/apr/16 by: Leonardo.Brenner@lsis.org // +// Last Change: 21/apr/16 by: Leonardo.Brenner@lsis.org // +//====================================================================================// +#include "simuleau.h" + +//------------------------------------------------------------------------------ +// Empty contructor +//------------------------------------------------------------------------------ +BPN::BPN() +{ + strcpy(bpnname,""); + + numberofdiscreteplaces = 0; + numberofcontinuousplaces = 0; + numberofbatchplaces = 0; + numberoftriangularplaces = 0; + + numberofdiscretetransitions = 0; + numberofcontinuoustransitions = 0; + numberofbatchtransitions = 0; + + places = NULL; + transitions = NULL; +} + +//------------------------------------------------------------------------------ +// Sized contructor +//------------------------------------------------------------------------------ +BPN::BPN(const int _numberofplaces, const int _numberoftransitions) +{ + strcpy(bpnname,""); + + numberofdiscreteplaces = 0; + numberofcontinuousplaces = 0; + numberofbatchplaces = 0; + numberoftriangularplaces = 0; + + numberofdiscretetransitions = 0; + numberofcontinuoustransitions = 0; + numberofbatchtransitions = 0; + + places = new Place* [_numberofplaces]; + for (int i=0; i<_numberofplaces; i++) + places[i] = NULL; + + transitions = new Transition* [_numberoftransitions]; + for (int i=0; i<_numberoftransitions; i++) + transitions[i] = NULL; +} + + +//------------------------------------------------------------------------------ +// Destructor +//------------------------------------------------------------------------------ +BPN::~BPN() +{ + if (places) + delete [] places; + if (transitions) + delete [] transitions; +} + + +//------------------------------------------------------------------------------ +// copy +//------------------------------------------------------------------------------ +void BPN::Copy(const BPN * _bpn) +{ + strcpy(bpnname, _bpn->bpnname); + + numberofdiscreteplaces = _bpn->numberofdiscreteplaces; + numberofcontinuousplaces = _bpn->numberofcontinuousplaces; + numberofbatchplaces = _bpn->numberofbatchplaces; + numberoftriangularplaces = _bpn->numberoftriangularplaces; + + numberofdiscretetransitions = _bpn->numberofdiscretetransitions; + numberofcontinuoustransitions = _bpn->numberofcontinuoustransitions;; + numberofbatchtransitions = _bpn->numberofbatchtransitions;; + + places = new Place* [NumberOfPlaces()]; + + int j = 0; + int k = numberofdiscreteplaces; + for (int i=j; i<k; i++){ + DiscretePlace *place = new DiscretePlace; + place->Copy(_bpn->places[i]); + places[i] = place; + } + + j = k; + k += numberofcontinuousplaces; + for (int i=j; i<k; i++){ + ContinuousPlace *place = new ContinuousPlace; + place->Copy(_bpn->places[i]); + places[i] = place; + } + + j = k; + k += numberofbatchplaces; + for (int i=j; i<k; i++){ + BatchPlace *place = new BatchPlace; + place->Copy(_bpn->places[i]); + places[i] = place; + } + + j = k; + k += numberoftriangularplaces; + for (int i=j; i<k; i++){ + TriangularBatchPlace *place = new TriangularBatchPlace; + place->Copy(_bpn->places[i]); + places[i] = place; + } + + transitions = new Transition* [NumberOfTransitions()]; + + j = 0; + k = numberofdiscretetransitions; + for (int i=j; i<k; i++){ + DiscreteTransition *transition = new DiscreteTransition; + transition->Copy(_bpn->transitions[i]); + transitions[i] = transition; + } + + j = k; + k += numberofcontinuoustransitions; + for (int i=j; i<k; i++){ + ContinuousTransition *transition = new ContinuousTransition; + transition->Copy(_bpn->transitions[i]); + transitions[i] = transition; + } + + j = k; + k += numberofbatchtransitions; + for (int i=j; i<k; i++){ + BatchTransition *transition = new BatchTransition; + transition->Copy(_bpn->transitions[i]); + transitions[i] = transition; + } + + //update node pointes + for (int i=0; i<NumberOfPlaces(); i++){ + places[i]->AddInputNodes(transitions); + places[i]->AddOutputNodes(transitions); + } + + for (int i=0; i<NumberOfTransitions(); i++){ + transitions[i]->AddInputNodes(places); + transitions[i]->AddOutputNodes(places); + } + +} + +//------------------------------------------------------------------------------ +// It allocs input/output array for nodes +//------------------------------------------------------------------------------ +void BPN::AllocArcs() +{ + for (int i=0; i<NumberOfPlaces(); i++) + places[i]->AllocArcs(NumberOfTransitions()); + + for (int i=0; i<NumberOfTransitions(); i++) + transitions[i]->AllocArcs(NumberOfPlaces()); +} + +//------------------------------------------------------------------------------ +// It links input/output arc to nodes +//------------------------------------------------------------------------------ +void BPN::AddNodeLinks() +{ + //update node pointes + for (int i=0; i<NumberOfPlaces(); i++){ + places[i]->AddInputNodes(transitions); + places[i]->AddOutputNodes(transitions); + } + + for (int i=0; i<NumberOfTransitions(); i++){ + transitions[i]->AddInputNodes(places); + transitions[i]->AddOutputNodes(places); + } +} + +//------------------------------------------------------------------------------ +// It assigns a name to the model +//------------------------------------------------------------------------------ +void BPN::PutName(simuleau_name _name) +{ + strcpy(bpnname, _name); +} + +//------------------------------------------------------------------------------ +// It set the number of discrete places in the model +//------------------------------------------------------------------------------ +void BPN::NumberOfDiscretePlaces(const int n) +{ + numberofdiscreteplaces = n; +} + +//------------------------------------------------------------------------------ +// It set the number of continuous places in the model +//------------------------------------------------------------------------------ +void BPN::NumberOfContinuousPlaces(const int n) +{ + numberofcontinuousplaces = n; +} + +//------------------------------------------------------------------------------ +// It set the number of batch places in the model +//------------------------------------------------------------------------------ +void BPN::NumberOfBatchPlaces(const int n) +{ + numberofbatchplaces = n; +} + +//------------------------------------------------------------------------------ +// It set the number of triangular batch places in the model +//------------------------------------------------------------------------------ +void BPN::NumberOfTriangularBatchPlaces(const int n) +{ + numberoftriangularplaces = n; +} + +//------------------------------------------------------------------------------ +// It adds the new place to the model in the position pos +//------------------------------------------------------------------------------ +int BPN::AddPlace(int pos, Place *p) +{ + if (places[pos] != NULL) + return (1); + places[pos] = p; + return (0); +} + +//------------------------------------------------------------------------------ +// It set the initial marking of a discrete place in the position pos to m +//------------------------------------------------------------------------------ +void BPN::SetInitialMarking(int pos, int m) +{ + places[pos]->SetInitialMarking(m); +} + +//------------------------------------------------------------------------------ +// It set the steady marking of a discrete place in the position pos to m +//------------------------------------------------------------------------------ +void BPN::SetSteadyMarking(int pos, int m) +{ + places[pos]->SetSteadyMarking(m); +} + +//------------------------------------------------------------------------------ +// It set the initial marking of a continuous place in the position pos to m +//------------------------------------------------------------------------------ +void BPN::SetInitialMarking(int pos, double m) +{ + places[pos]->SetInitialMarking(m); +} + +//------------------------------------------------------------------------------ +// It set the steady marking of a continuous place in the position pos to m +//------------------------------------------------------------------------------ +void BPN::SetSteadyMarking(int pos, double m) +{ + places[pos]->SetSteadyMarking(m); +} + +//------------------------------------------------------------------------------ +// It set the initial marking of a batch place in the position pos to m +//------------------------------------------------------------------------------ +void BPN::AddBatchToInitialMarking(int pos, Batch &b) +{ + places[pos]->AddBatchToInitialMarking(b); +} + +//------------------------------------------------------------------------------ +// It set the steady marking of a batch place in the position pos to m +//------------------------------------------------------------------------------ +void BPN::AddBatchToSteadyMarking(int pos, Batch &b) +{ + places[pos]->AddBatchToSteadyMarking(b); +} + +//------------------------------------------------------------------------------ +// It set the initial marking of a batch place in the position pos to m +//------------------------------------------------------------------------------ +void BPN::AddTriangularToInitialMarking(int pos, ControllableBatch &b) +{ + places[pos]->AddBatchToInitialMarking(b); +} + +//------------------------------------------------------------------------------ +// It set the steady marking of a batch place in the position pos to m +//------------------------------------------------------------------------------ +void BPN::AddTriangularToSteadyMarking(int pos, ControllableBatch &b) +{ + places[pos]->AddBatchToSteadyMarking(b); +} + +//------------------------------------------------------------------------------ +// It adds an output arc from the place in position _place to the transition in +// in position _position with weight +//------------------------------------------------------------------------------ +int BPN::AddPlaceOutputArc(int _place, int _transition, double _weight) +{ + places[_place]->AddOutputArc(_transition, _weight); + transitions[_transition]->AddInputArc(_place, _weight); +} + +//------------------------------------------------------------------------------ +// It set the number of discrete transitions in the model +//------------------------------------------------------------------------------ +void BPN::NumberOfDiscreteTransitions(const int n) +{ + numberofdiscretetransitions = n; +} + +//------------------------------------------------------------------------------ +// It set the number of continuous transitions in the model +//------------------------------------------------------------------------------ +void BPN::NumberOfContinuousTransitions(const int n) +{ + numberofcontinuoustransitions = n; +} + +//------------------------------------------------------------------------------ +// It set the number of batch transitions in the model +//------------------------------------------------------------------------------ +void BPN::NumberOfBatchTransitions(const int n) +{ + numberofbatchtransitions = n; +} + +//------------------------------------------------------------------------------ +// It adds the new transition to the model in the position pos +//------------------------------------------------------------------------------ +int BPN::AddTransition(int pos, Transition *t) +{ + if (transitions[pos] != NULL) + return (1); + transitions[pos] = t; + return (0); +} + +//------------------------------------------------------------------------------ +// It adds an output arc from the place in position _place to the transition in +// in position _position with weight +//------------------------------------------------------------------------------ +int BPN::AddTransitionOutputArc(int _transition, int _place, double _weight) +{ transitions[_transition]->AddOutputArc(_place, _weight); + places[_place]->AddInputArc(_transition, _weight); +} + +//------------------------------------------------------------------------------ +// It verifies if the name is already used for another place/transition +//------------------------------------------------------------------------------ +int BPN::VerifyName(simuleau_name _name) +{ + for (int i=0; i<NumberOfPlaces(); i++){ + if (places[i] != NULL){ + if (!strcmp(places[i]->GetName(),_name)) + return (1); + } + } + for (int i=0; i<NumberOfTransitions(); i++){ + if (transitions[i] != NULL){ + if (!strcmp(transitions[i]->GetName(),_name)) + return (1); + } + } + return (0); +} + +//------------------------------------------------------------------------------ +// It returns the bpn model name +//------------------------------------------------------------------------------ +char* BPN::GetName() +{ + return (bpnname); +} + +//------------------------------------------------------------------------------ +// It returns the addresse of the node name +//------------------------------------------------------------------------------ +Node* BPN::GetNode(simuleau_name _name) +{ + for (int i=0; i<NumberOfPlaces(); i++){ + if (places[i] != NULL){ + if (!strcmp(places[i]->GetName(),_name)) + return (places[i]); + } + } + for (int i=0; i<NumberOfTransitions(); i++){ + if (transitions[i] != NULL){ + if (!strcmp(transitions[i]->GetName(),_name)) + return (transitions[i]); + } + } + return (NULL); +} +//------------------------------------------------------------------------------ +// It returns the number of discrete places in the model +//------------------------------------------------------------------------------ +int BPN::NumberOfDiscretePlaces() +{ + return (numberofdiscreteplaces); +} + +//------------------------------------------------------------------------------ +// It returns the number of continuous places in the model +//------------------------------------------------------------------------------ +int BPN::NumberOfContinuousPlaces() +{ + return (numberofcontinuousplaces); +} + +//------------------------------------------------------------------------------ +// It returns the number of batch places in the model +//------------------------------------------------------------------------------ +int BPN::NumberOfBatchPlaces() +{ + return (numberofbatchplaces); +} + +//------------------------------------------------------------------------------ +// It returns the number of triangular batch places in the model +//------------------------------------------------------------------------------ +int BPN::NumberOfTriangularBatchPlaces() +{ + return (numberoftriangularplaces); +} + +//------------------------------------------------------------------------------ +// It returns the number of all places in the model +//------------------------------------------------------------------------------ +int BPN::NumberOfPlaces() +{ + return (numberofdiscreteplaces + numberofcontinuousplaces + numberofbatchplaces + numberoftriangularplaces); +} + +//------------------------------------------------------------------------------ +// It returns the position of the place _name +//------------------------------------------------------------------------------ +int BPN::GetPlacePosition(simuleau_name _name) +{ + for (int i=0; i<NumberOfPlaces(); i++){ + if (places[i] != NULL){ + if (!strcmp(places[i]->GetName(),_name)) + return (i); + } + } + return (-1); +} + + +//------------------------------------------------------------------------------ +// It returns the name of the place in the position _place +//------------------------------------------------------------------------------ +char* BPN::GetPlaceName(place_id _place) +{ + return(places[_place]->GetName()); +} + +//------------------------------------------------------------------------------ +// It returns the pointer of the place in the position _place +//------------------------------------------------------------------------------ +Place* BPN::GetPlace(place_id _place) +{ + return(places[_place]); +} + +//------------------------------------------------------------------------------ +// It returns the place type +//------------------------------------------------------------------------------ +place_type BPN::GetPlaceType(simuleau_name _name) +{ + int j = 0; + int k = numberofdiscreteplaces; + for (int i=j; i<k; i++){ + if (places[i] != NULL){ + if (!strcmp(places[i]->GetName(),_name)) + return (Discrete_pl); + } + } + + j = k; + k += numberofcontinuousplaces; + for (int i=j; i<k; i++){ + if (places[i] != NULL){ + if (!strcmp(places[i]->GetName(),_name)) + return (Continuous_pl); + } + } + + j = k; + k += numberofbatchplaces; + for (int i=j; i<k; i++){ + if (places[i] != NULL){ + if (!strcmp(places[i]->GetName(),_name)) + return (Batch_pl); + } + } + + j = k; + k += numberoftriangularplaces; + for (int i=j; i<k; i++){ + if (places[i] != NULL){ + if (!strcmp(places[i]->GetName(),_name)) + return (Triangular_pl); + } + } +} + +//------------------------------------------------------------------------------ +// It returns the number of discrete transitions in the model +//------------------------------------------------------------------------------ +int BPN::NumberOfDiscreteTransitions() +{ + return (numberofdiscretetransitions); +} + +//------------------------------------------------------------------------------ +// It returns the number of continuous transitions in the model +//------------------------------------------------------------------------------ +int BPN::NumberOfContinuousTransitions() +{ + return (numberofcontinuoustransitions); +} + +//------------------------------------------------------------------------------ +// It returns the number of batch transitions in the model +//------------------------------------------------------------------------------ +int BPN::NumberOfBatchTransitions() +{ + return (numberofbatchtransitions); +} + + +//------------------------------------------------------------------------------ +// It returns the number of all transitions in the model +//------------------------------------------------------------------------------ +int BPN::NumberOfTransitions() +{ + return (numberofdiscretetransitions + numberofcontinuoustransitions + numberofbatchtransitions); +} + +//------------------------------------------------------------------------------ +// It returns the position of the transition _name +//------------------------------------------------------------------------------ +int BPN::GetTransitionPosition(simuleau_name _name) +{ + for (int i=0; i<NumberOfTransitions(); i++){ + if (transitions[i] != NULL){ + if (!strcmp(transitions[i]->GetName(),_name)) + return (i); + } + } + return (-1); +} + +//------------------------------------------------------------------------------ +// It returns the name of the transition in the position _trans +//------------------------------------------------------------------------------ +char* BPN::GetTransitionName(trans_id _trans) +{ + return(transitions[_trans]->GetName()); +} + +//------------------------------------------------------------------------------ +// It returns the pointer of the transition in the position _trans +//------------------------------------------------------------------------------ +Transition* BPN::GetTransition(trans_id _trans) +{ + return(transitions[_trans]); +} + + +//------------------------------------------------------------------------------ +// It returns the place type +//------------------------------------------------------------------------------ +trans_type BPN::GetTransitionType(simuleau_name _name) +{ + int j = 0; + int k = numberofdiscretetransitions; + for (int i=j; i<k; i++){ + if (transitions[i] != NULL){ + if (!strcmp(transitions[i]->GetName(),_name)) + return (Discrete_tr); + } + } + + j = k; + k += numberofcontinuoustransitions; + for (int i=j; i<k; i++){ + if (transitions[i] != NULL){ + if (!strcmp(transitions[i]->GetName(),_name)) + return (Continuous_tr); + } + } + + j = k; + k += numberofbatchtransitions; + for (int i=j; i<k; i++){ + if (transitions[i] != NULL){ + if (!strcmp(transitions[i]->GetName(),_name)) + return (Batch_tr); + } + } +} + +//------------------------------------------------------------------------------ +// It prints the bpn model +//------------------------------------------------------------------------------ +void BPN::Print(ostream &fout) +{ + fout << "BPN model name: " << bpnname << endl << endl; + + fout << "======" << endl; + fout << "Places" << endl; + fout << "======" << endl << endl; + + fout << "Number of places: " << (numberofdiscreteplaces + numberofcontinuousplaces + + numberofbatchplaces + numberoftriangularplaces) << endl; + fout << " Discrete places: " << numberofdiscreteplaces << endl; + fout << " Continuous places: " << numberofcontinuousplaces << endl; + fout << " Batch places: " << numberofbatchplaces << endl; + fout << " Triangular batch places: " << numberoftriangularplaces << endl << endl; + + fout << "Description of places " << endl; + fout << "=====================" << endl << endl; + + for (int i=0; i<NumberOfPlaces(); i++){ + places[i]->Print(fout); + } + + fout << "===========" << endl; + fout << "Transitions" << endl; + fout << "===========" << endl << endl; + + fout << "Number of transitions: " << (numberofdiscretetransitions + numberofcontinuoustransitions + + numberofbatchtransitions) << endl; + fout << " Discrete transitions: " << numberofdiscretetransitions << endl; + fout << " Continuous transitions: " << numberofcontinuoustransitions << endl; + fout << " Batch transitions: " << numberofbatchtransitions << endl << endl; + + fout << "Description of Transitions" << endl; + fout << "==========================" << endl << endl; + + for (int i=0; i<NumberOfTransitions(); i++){ + transitions[i]->Print(fout); + } +} + +//------------------------------------------------------------------------------ +// It writes place marks in the file +//------------------------------------------------------------------------------ +void BPN::WritePlaces(ostream &fout) +{ + for (int i=0; i<NumberOfPlaces(); i++){ + places[i]->Write(fout); + } +} + +//------------------------------------------------------------------------------ +// It writes continuous and batch transitions after to compute IFF +//------------------------------------------------------------------------------ +void BPN::WriteFlows(ostream &fout) +{ + for (int i=numberofdiscretetransitions; i<NumberOfTransitions(); i++){ + ((ContinuousTransition*)transitions[i])->Write(fout); + } +} + +//------------------------------------------------------------------------------ +// Compute new marks +//------------------------------------------------------------------------------ +void BPN::ComputeNewMarks(double duration) +{ + for (int i=0; i<NumberOfTransitions(); i++){ + transitions[i]->WalkThrough(duration); + } + + for (int i=0; i<NumberOfPlaces(); i++){ + places[i]->EvolveMarks(simulation->stime->GetPreviousDate()); + } +} + +//------------------------------------------------------------------------------ +// Reserve marks in discrete places +//------------------------------------------------------------------------------ +void BPN::ReserveMarks() +{ + for (int i=0; i<numberofdiscretetransitions; i++){ + if (transitions[i]->GetState() == 1.0){ + ((DiscreteTransition*)transitions[i])->SetEnabledDate(simulation->stime->GetCurrentDate()); + ((DiscreteTransition*)transitions[i])->ReserveMarksInputPlaces(); + } + } +} + +//------------------------------------------------------------------------------ +// Create batches in batch places with input flow non-zero +// TODO verify correct function call +//------------------------------------------------------------------------------ +void BPN::CreateBatches() +{ + int k = numberofdiscreteplaces + numberofcontinuousplaces; + + for (int i=k; i<NumberOfPlaces(); i++){ + switch (places[i]->IsA()){ + case Batch_pl : ((BatchPlace*)places[i])->CreateBatches(); + break; + case Triangular_pl: ((TriangularBatchPlace*)places[i])->CreateBatches(); + break; + } + } +} + +//------------------------------------------------------------------------------ +// Destruct batch into the batch places +//------------------------------------------------------------------------------ +void BPN::DestructBatches() +{ + int k = numberofdiscreteplaces + numberofcontinuousplaces; + + for (int i=k; i<NumberOfPlaces(); i++){ + ((BatchPlace*)places[i])->DestructBatches(); + } +} + +//------------------------------------------------------------------------------ +// Merge batches into the batch places +//------------------------------------------------------------------------------ +void BPN::MergeBatches() +{ + int k = numberofdiscreteplaces + numberofcontinuousplaces; + + for (int i=k; i<NumberOfPlaces(); i++){ + ((BatchPlace*)places[i])->MergeBatches(); + } +} + +//------------------------------------------------------------------------------ +// Compute the state of each transition +// TODO verify transitions +//------------------------------------------------------------------------------ +int BPN::ComputeTransitionsStates() +{ + + if( (NumberOfPlaces() == 0) && (NumberOfTransitions() == 0)){ + return 0; // No place or transition + } + + double p[NumberOfPlaces()]; + double t[NumberOfTransitions()]; + int steps = 0; + + for (int i=0; i<NumberOfPlaces(); i++){ + places[i]->SetState(0.0); + } + + for (int i=0; i<NumberOfTransitions(); i++){ + t[i] = transitions[i]->GetState(); + transitions[i]->SetPreviousState(t[i]); + transitions[i]->SetState(0.0); + } + + do{ + steps++; + + for (int i=0; i<NumberOfPlaces(); i++){ + p[i] = places[i]->GetState(); + places[i]->ComputeState(); + } + + for (int i=0; i<NumberOfTransitions(); i++){ + t[i] = transitions[i]->GetState(); + transitions[i]->ComputeState(); // to verify + } + + } while (StateStability(p,t) != 0); + + return (steps); +} + +//------------------------------------------------------------------------------ +// Verify the stabilty of the state of each place and transition +//------------------------------------------------------------------------------ +int BPN::StateStability(double *p, double *t) +{ + int result = 0; + + for (int i=0; i<NumberOfPlaces(); i++){ + if (p[i] != places[i]->GetState()) + result++; + } + + for (int i=0; i<NumberOfTransitions(); i++){ + if (t[i] != transitions[i]->GetState()) + result++; + } + return (result); +} + +//------------------------------------------------------------------------------ +// Compute batches behaviors +//------------------------------------------------------------------------------ +void BPN::ComputeBatchesBehaviours() +{ +// cout << "Compute batches behaviours\n"; + + int k = numberofdiscreteplaces + numberofcontinuousplaces; // only batch places + + for (int i=k; i<NumberOfPlaces(); i++){ + switch (places[i]->IsA()){ + case Batch_pl : ((BatchPlace*)places[i])->ComputeBehaviour(); + break; + case Triangular_pl: ((TriangularBatchPlace*)places[i])->ComputeBehaviour(); + break; + } + } +} + +//------------------------------------------------------------------------------ +// Merge batches into the batch places +//------------------------------------------------------------------------------ +void BPN::SetBehaviourFunctions() +{ + int k = numberofdiscreteplaces + numberofcontinuousplaces + numberofbatchplaces; + + for (int i=k; i<NumberOfPlaces(); i++){ + ((TriangularBatchPlace*)places[i])->SetBehaviourFunctions(); + } +} + + +//------------------------------------------------------------------------------ +// Research structural conflit in the model +//------------------------------------------------------------------------------ +void BPN::ResearchStructuralConflict() +{ + for(int i=0; i<NumberOfPlaces(); i++){ + places[i]->ResearchStructuralConflict(); + } +} + +//------------------------------------------------------------------------------ +// Verify conflit in the model +// 0 - No conflit +// 1 - Conflit in discrete place +// 2 - Conflit in continuous place +//------------------------------------------------------------------------------ +int BPN::VerifyConflict() +{ +// cout << "Verifying conflicts\n"; + int conflict = 0; + + for(int i=0; i<NumberOfPlaces(); i++){ + if (places[i]->GetStructuralConflict()){ + conflict = places[i]->VerifyConflict(); + if (conflict) + return (conflict); + } + } + return (0); +} + +//------------------------------------------------------------------------------ +// It verifies if the net reaches the steady state +//------------------------------------------------------------------------------ +int BPN::IsSteadyStateReached() +{ + + for(int i=numberofdiscreteplaces; i<NumberOfPlaces(); i++){ + switch(places[i]->IsA()){ + case Continuous_pl : if (!((ContinuousPlace*)places[i])->IsSteadyMarkingReached()) + return 0; + break; + + case Batch_pl : if (!((BatchPlace*)places[i])->IsSteadyMarkingReached()) + return 0; + break; + } + } + + for(int i=numberofdiscretetransitions; i<NumberOfTransitions(); i++){ + if (!((ContinuousTransition*)transitions[i])->IsSteadyFlowReached()){ + return 0; + } + } + + return (1); +} + + + + +//------------------------------------------------------------------------------ +// Compute next event to Discrete Transition Fire type and put it in dtf list +//------------------------------------------------------------------------------ +void BPN::ComputeNextEventDTF(list<Event> * _dtf) +{ + double eventdate = 0.0; + + cout << "ComputeNextEventDTF\n"; + + for(int i=0; i<numberofdiscretetransitions; i++){ + if (transitions[i]->GetState() != 0.0){ + eventdate = ((DiscreteTransition*)transitions[i])->GetTime() + ((DiscreteTransition*)transitions[i])->GetEnabledDate(); + if ((eventdate - simulation->stime->GetCurrentDate()) >= PRF::prf.Min_Err_Date()){ + cout << "adding event DTF\n"; + Event *e = new Event(*transitions[i], eventdate, Discr_trans_fires); + _dtf->push_back(*e); + } + } + } +} + +//------------------------------------------------------------------------------ +// Compute next event to Continuous Place becomes Empty type and put it in cpe list +//------------------------------------------------------------------------------ +void BPN::ComputeNextEventCPE(list<Event> * _cpe) +{ + double eventdate = 0.0; + + cout << "ComputeNextEventCPE\n"; + + int beginofcp = numberofdiscreteplaces; // start from the end of discrete places + int endofcp = numberofdiscreteplaces+numberofcontinuousplaces; // stop to the end of continuous places + + for (int i=beginofcp; i<endofcp; i++){ + if (places[i]->GetState() == 1){ + eventdate = ((ContinuousPlace*)places[i])->GetCPEEvent(); + if ((eventdate - simulation->stime->GetCurrentDate()) >= PRF::prf.Min_Err_Date()){ + cout << "adding event CPE\n"; + Event *e = new Event(*places[i], eventdate, Cont_place_empty); + _cpe->push_back(*e); + } + } + } + +} + +//------------------------------------------------------------------------------ +// Compute next event to Discrete transistion becomes enabled type and put it in dte list +//------------------------------------------------------------------------------ +void BPN::ComputeNextEventDTE(list<Event> * _dte) +{ + double eventdate = 0.0; + + cout << "ComputeNextEventDTE\n"; + + int beginofcp = numberofdiscreteplaces; // start from the end of discrete places + int endofcp = numberofdiscreteplaces+numberofcontinuousplaces; // stop to the end of continuous places + + for (int i=beginofcp; i<endofcp; i++){ + eventdate = ((ContinuousPlace*)places[i])->GetDTEEvent(); + if ((eventdate - simulation->stime->GetCurrentDate()) >= PRF::prf.Min_Err_Date()){ + cout << "adding event DTE\n"; + Event *e = new Event(*places[i], eventdate, Discr_trans_enabled); + _dte->push_back(*e); + } + } +} + +//------------------------------------------------------------------------------ +// Compute next event to BOB type and put it in bob list +//------------------------------------------------------------------------------ +void BPN::ComputeNextEventBOB(list<Event> * _bob) +{ + double eventdate = 0.0; + + cout << "ComputeNextEventBOB\n"; + + int beginofbp = numberofdiscreteplaces+numberofcontinuousplaces; // start from the end of continuous places + int endofbp = NumberOfPlaces(); // stop to the end of all places + + for (int i=beginofbp; i<endofbp; i++){ + switch(places[i]->IsA()){ + case Batch_pl : eventdate = ((BatchPlace*)places[i])->GetBOBEvent(); + break; + case Triangular_pl : eventdate = ((TriangularBatchPlace*)places[i])->GetBOBEvent(); + break; + } + + if ((eventdate - simulation->stime->GetCurrentDate()) >= PRF::prf.Min_Err_Date()){ + cout << "adding event BOB\n"; + Event *e = new Event(*places[i], eventdate, Becomes_output_batch); + _bob->push_back(*e); + } + } +} + +//------------------------------------------------------------------------------ +// Compute next event to DOB type and put it in dob list +//------------------------------------------------------------------------------ +void BPN::ComputeNextEventDOB(list<Event> * _dob) +{ + double eventdate = 0.0; + + cout << "ComputeNextEventDOB\n"; + + int beginofbp = numberofdiscreteplaces+numberofcontinuousplaces; // start from the end of continuous places + int endofbp = NumberOfPlaces(); // stop to the end of all places + + for (int i=beginofbp; i<endofbp; i++){ + switch(places[i]->IsA()){ + case Batch_pl : eventdate = ((BatchPlace*)places[i])->GetDOBEvent(); + break; + case Triangular_pl : eventdate = ((TriangularBatchPlace*)places[i])->GetDOBEvent(); + break; + } + if ((eventdate - simulation->stime->GetCurrentDate()) >= PRF::prf.Min_Err_Date()){ + cout << "adding event DOB\n"; + Event *e = new Event(*places[i], eventdate, Destr_output_batch); + _dob->push_back(*e); + } + } +} + +//------------------------------------------------------------------------------ +// Compute next event to BBD type and put it in dtf list +//------------------------------------------------------------------------------ +void BPN::ComputeNextEventBBD(list<Event> * _bbd) +{ + double eventdate = 0.0; + + cout << "ComputeNextEventBBD\n"; + + int beginofbp = numberofdiscreteplaces+numberofcontinuousplaces; // start from the end of continuous places + int endofbp = NumberOfPlaces(); // stop to the end of all places + + for (int i=beginofbp; i<endofbp; i++){ + switch(places[i]->IsA()){ + case Batch_pl : eventdate = ((BatchPlace*)places[i])->GetBBDEvent(); + break; + case Triangular_pl : eventdate = ((TriangularBatchPlace*)places[i])->GetBBDEvent(); + break; + } + if ((eventdate - simulation->stime->GetCurrentDate()) >= PRF::prf.Min_Err_Date()){ + cout << "adding event BBD\n"; + Event *e = new Event(*places[i], eventdate, Batch_becomes_dense); + _bbd->push_back(*e); + } + } +} + +//------------------------------------------------------------------------------ +// Compute next event to TBM type and put it in tbm list +//------------------------------------------------------------------------------ +void BPN::ComputeNextEventTBM(list<Event> * _tbm) +{ + double eventdate = 0.0; + + cout << "ComputeNextEventTBM\n"; + + int beginofbp = numberofdiscreteplaces+numberofcontinuousplaces; // start from the end of continuous places + int endofbp = NumberOfPlaces(); // stop to the end of all places + + for (int i=beginofbp; i<endofbp; i++){ + switch(places[i]->IsA()){ + case Batch_pl : eventdate = ((BatchPlace*)places[i])->GetTBMEvent(); + break; + case Triangular_pl : eventdate = ((TriangularBatchPlace*)places[i])->GetTBMEvent(); + break; + } + if ((eventdate - simulation->stime->GetCurrentDate()) >= PRF::prf.Min_Err_Date()){ + cout << "adding event TBM\n"; + Event *e = new Event(*places[i], eventdate, Two_batches_meet); + _tbm->push_back(*e); + } + } +} + +//------------------------------------------------------------------------------ +// Compute next event to BMOB type and put it in bmob list +//------------------------------------------------------------------------------ +void BPN::ComputeNextEventBMOB(list<Event> * _bmob) +{ + double eventdate = 0.0; + + cout << "ComputeNextEventBMOB\n"; + + int beginoftbp = numberofdiscreteplaces + numberofcontinuousplaces + numberofbatchplaces; // start from the end of batch places + int endoftbp = NumberOfPlaces(); // stop to the end of all places + + for (int i=beginoftbp; i<endoftbp; i++){ + eventdate = ((TriangularBatchPlace*)places[i])->GetBMOBEvent(); + if ((eventdate - simulation->stime->GetCurrentDate()) >= PRF::prf.Min_Err_Date()){ + cout << "adding event BMOB\n"; + Event *e = new Event(*places[i], eventdate, Batch_meets_output_batch); + _bmob->push_back(*e); + } + } +} + +//------------------------------------------------------------------------------ +// Compute next event to OBD (outpu batch decongestion) type and put it in obd list +//------------------------------------------------------------------------------ +void BPN::ComputeNextEventOBD(list<Event> * _obd) +{ + double eventdate = 0.0; + + cout << "ComputeNextEventOBD\n"; + + int beginoftbp = numberofdiscreteplaces + numberofcontinuousplaces + numberofbatchplaces; // start from the end of batch places + int endoftbp = NumberOfPlaces(); // stop to the end of all places + + for (int i=beginoftbp; i<endoftbp; i++){ + eventdate = ((TriangularBatchPlace*)places[i])->GetOBDEvent(); + if ((eventdate - simulation->stime->GetCurrentDate()) >= PRF::prf.Min_Err_Date()){ + cout << "adding event OBD\n"; + Event *e = new Event(*places[i], eventdate, Output_batch_decongestion); + _obd->push_back(*e); + } + } +} + +//------------------------------------------------------------------------------ +// Compute next event to BD type and put it in bd list +//------------------------------------------------------------------------------ +void BPN::ComputeNextEventBD(list<Event> * _bd) +{ + double eventdate = 0.0; + + cout << "ComputeNextEventBD\n"; + + int beginoftbp = numberofdiscreteplaces + numberofcontinuousplaces + numberofbatchplaces; // start from the end of batch places + int endoftbp = NumberOfPlaces(); // stop to the end of all places + + for (int i=beginoftbp; i<endoftbp; i++){ + eventdate = ((TriangularBatchPlace*)places[i])->GetBDEvent(); + if ((eventdate - simulation->stime->GetCurrentDate()) >= PRF::prf.Min_Err_Date()){ + cout << "adding event BD\n"; + Event *e = new Event(*places[i], eventdate, Batch_decongestion); + _bd->push_back(*e); + } + } +} + +//------------------------------------------------------------------------------ +// Compute next event to BBF type and put it in bbf list +//------------------------------------------------------------------------------ +void BPN::ComputeNextEventBBF(list<Event> * _bbf) +{ + double eventdate = 0.0; + + cout << "ComputeNextEventBBF\n"; + + int beginoftbp = numberofdiscreteplaces + numberofcontinuousplaces + numberofbatchplaces; // start from the end of batch places + int endoftbp = NumberOfPlaces(); // stop to the end of all places + + for (int i=beginoftbp; i<endoftbp; i++){ + eventdate = ((TriangularBatchPlace*)places[i])->GetBBFEvent(); + if ((eventdate - simulation->stime->GetCurrentDate()) >= PRF::prf.Min_Err_Date()){ + cout << "adding event BBF\n"; + Event *e = new Event(*places[i], eventdate, Batch_becomes_free); + _bbf->push_back(*e); + } + } +} + +//=============================Onoff======CFF====================================== +//------------------------------------------------------------------------------ +// Compute next event to Place reaches steadying marking quantity and put it in psq list +//------------------------------------------------------------------------------ +void BPN::ComputeNextEventPSQ(list<Event> * _psq) +{ + double eventdate = 0.0; + + cout << "ComputeNextEventPSQ\n"; + + int beginofcbp = numberofdiscreteplaces; // start from the end of discrete places + int endofcbp = numberofdiscreteplaces + numberofcontinuousplaces + numberofbatchplaces; // stop at the end of batch places + + for (int i=beginofcbp; i<endofcbp; i++){ + switch (places[i] ->IsA()){ + case Continuous_pl: eventdate = ((ContinuousPlace*)places[i])->GetPSQEvent(); // + break; + case Batch_pl:eventdate = ((BatchPlace*)places[i])->GetPSQEvent(); // + break; + } + if ((eventdate - simulation->stime->GetCurrentDate()) >= PRF::prf.Min_Err_Date()){ + cout << "adding event PSQ\n"; + Event *e = new Event(*places[i], eventdate, Place_steady_quan); // + _psq->push_back(*e); + } + } +} + +//=============================MCFF======event=======RBF=============================== +//------------------------------------------------------------------------------ +// Compute next event that the firing quantity satisfies the remaining marking quantity +// becomes free steady marking quantity of its output place and put it in rbf list +// + +// q_{i,j}^{r,s} = Post(p_i,t_j)(z_j^s - z_j(m)) <= q_i^{f,s} +//------------------------------------------------------------------------------ +void BPN::ComputeNextEventRBF(list<Event> * _rbf) +{ + double eventdate = 0.0; + + cout << "ComputeNextEventRBF\n"; + + + int beginofcbt = numberofdiscretetransitions; // start from the end of discrete transitions + int endofcbt = numberofdiscretetransitions + numberofcontinuoustransitions + numberofbatchtransitions; // stop at the end of batch transitions + + for (int i=beginofcbt; i<endofcbt; i++){ + switch(transitions[i]->IsA()){ + case Discrete_tr: + case Continuous_tr: eventdate = ((ContinuousTransition*)transitions[i])->GetRBFEvent(); + break; + case Batch_tr: eventdate = ((BatchTransition*)transitions[i])->GetRBFEvent(); + break; + + } + if ((eventdate - simulation->stime->GetCurrentDate()) >= PRF::prf.Min_Err_Date()){ + cout << "adding event RBF\n"; + Event *e = new Event(*transitions[i], eventdate, Remaining_becomes_freesteadyquan); // + _rbf->push_back(*e); + } + } +} + +//------------------------------------------------------------------------------ +// Compute Instantaneous Firing Flow (IFF) +//------------------------------------------------------------------------------ +void BPN::ComputeIFF() +{ + cout << "\nCompute IFF\n\n"; + + Flow *f; + double maxflow; + + // contraints a and b + int beginofcbt = numberofdiscretetransitions; + int endofcbt = NumberOfTransitions(); + + int numberofcontandbatchtransitions = numberofcontinuoustransitions + numberofbatchtransitions; + int numberofnotenabledcontandbatchtransitions = 0; + for (int i=beginofcbt; i<endofcbt; i++){ + if (transitions[i]->GetState() == 0.0){ + numberofnotenabledcontandbatchtransitions++; + } + } + + if (numberofcontandbatchtransitions == 0) // no need to compute IFF + return; + + // contraint c empty continuous place set + int beginofcp = numberofdiscreteplaces; + int endofcp = numberofdiscreteplaces + numberofcontinuousplaces; + int numberofemptycontinuousplaces = 0; + for (int i=beginofcp; i<endofcp; i++){ + if (((ContinuousPlace*)places[i])->GetMarks() == 0.0){ +// cout << "Empty place[" << i << "] : " << ((ContinuousPlace*)places[i])->GetMarks() << endl; + numberofemptycontinuousplaces++; + } + } + + // contraint d full batch place set + int beginofbp = numberofdiscreteplaces + numberofcontinuousplaces; + int endofbp = NumberOfPlaces(); + int numberoffullbatchplaces = 0; + for (int i=beginofbp; i<endofbp; i++){ + if (((BatchPlace*)places[i])->IsFull() == 1){ + numberoffullbatchplaces++; + } + } + + // contraints e, f + int numberofallbatchplaces = numberofbatchplaces + numberoftriangularplaces; + + // contraint g + int beginoftbp = numberofdiscreteplaces + numberofcontinuousplaces + numberofbatchplaces; + int endoftbp = NumberOfPlaces(); + + + int nc = 0; // total of contraints + int r = 0; // current contraint + char rname[256]; // row name + + double V[NumberOfTransitions()]; // used to compute the incidence matrix, only continuous and batch positions are used + + + // variables to the linear program + glp_prob *lp; + double IFF[numberofcontandbatchtransitions]; // to store the result of the linear program + + nc = numberofcontandbatchtransitions; // contraint a + nc+= numberofnotenabledcontandbatchtransitions; // contraint b + nc+= numberofemptycontinuousplaces; // contraint c + nc+= numberoffullbatchplaces; // contraint d + nc+= (numberofallbatchplaces * 2); // contraints e and f + nc+= numberoftriangularplaces; // contraints g + + // contraints matrix + int ia[nc * numberofcontandbatchtransitions]; + int ja[nc * numberofcontandbatchtransitions]; + double ar[nc * numberofcontandbatchtransitions]; + int arindex; + + + // initialising linear program + lp = glp_create_prob(); + glp_set_prob_name(lp, "IFF"); + glp_set_obj_dir(lp, GLP_MAX); + glp_add_cols(lp, numberofcontandbatchtransitions); + glp_add_rows(lp, nc); + + // initialising transitions bound +// cout << "\nTransitions bound\n\n"; + for (int i=1, k=beginofcbt; k<endofcbt; k++, i++) { + glp_set_obj_coef(lp, i, 1.0); // weigth of each transition + glp_set_col_name(lp, i, transitions[k]->GetName()); // name of the transition + f = transitions[k]->GetFlow(); + if (f->GetMaximumFlow() != 0.0) + glp_set_col_bnds(lp, i, GLP_DB, 0.0, f->GetMaximumFlow()); + else + glp_set_col_bnds(lp, i, GLP_FX, 0.0, 0.0); + +// cout << transitions[k]->GetName() << " : 0.0 - " << f->GetMaximumFlow() << endl; + } + + r = 1; + arindex = 1; + +// cout << "\nStart contraints\n\n"; + // constraint a +// cout << "Contraint a\n"; + for (int i=1, k=beginofcbt; k<endofcbt; k++, i++) { + sprintf(rname, "a.%d", i); + f = transitions[k]->GetFlow(); + glp_set_row_name(lp, r, rname); + if (f->GetMaximumFlow() != 0.0) + glp_set_row_bnds(lp, r, GLP_DB, 0.0, f->GetMaximumFlow()); + else + glp_set_row_bnds(lp, r, GLP_FX, 0.0, 0.0); + + ia[arindex] = r; + ja[arindex] = i; + ar[arindex] = 1.0; // weigth + arindex++; + r++; + +// cout << rname << " : " << "0.0 <= x <= " << f->GetMaximumFlow() << endl; + } + + // constraint b +// cout << "Contraint b\n"; + for (int i=1, k=beginofcbt; k<endofcbt; k++, i++) { + sprintf(rname, "b.%d", i); + if (transitions[k]->GetState() == 0.0){ + glp_set_row_name(lp, r, rname); + glp_set_row_bnds(lp, r, GLP_FX, 0.0, 0.0); + + ia[arindex] = r; + ja[arindex] = i; + ar[arindex] = 1.0; // weigth + arindex++; + r++; +// cout << rname << " : " << ja[arindex-1] << ": 0.0 = x = 0.0 " << endl; + } + } + + // constraint c +// cout << "Contraint c\n"; + for (int i=1, k=beginofcp; k<endofcp; k++, i++) { + sprintf(rname, "c.%d", i); + if (((ContinuousPlace*)places[k])->GetMarks() == 0.0){ + glp_set_row_name(lp, r, rname); + glp_set_row_bnds(lp, r, GLP_LO, 0.0, 0.0); + for (int j=0; j<NumberOfTransitions(); j++) { + V[j] = 0.0; + } + + for (int j=0; j<NumberOfTransitions(); j++){ + if (places[k]->GetWeightOfOutputArc(j) != 0.0 ){ + V[j] = - places[k]->GetWeightOfOutputArc(j); +// cout << " - V [" << j << "] " ; + } + if (places[k]->GetWeightOfInputArc(j) != 0.0 ){ +// cout << " + V [" << j << "] " ; + V[j] += places[k]->GetWeightOfInputArc(j); + } + } +// cout << endl; +// cout << rname << " : "; + for (int j=1, l=beginofcbt; l<endofcbt; j++, l++) { + if (V[l] != 0.0){ + ia[arindex] = r; + ja[arindex] = j; + ar[arindex] = V[l]; + arindex++; +// cout << j << "(" << V[l] << ") - "; + } + } +// cout << " >= 0.0" << endl; + r++; + } + } + + + // constraint d +// cout << "Contraint d\n"; + for (int i=1, k=beginofbp; k<endofbp; k++, i++) { + sprintf(rname, "d.%d", i); + if (((BatchPlace *)places[k])->IsFull() == 1.0){ + glp_set_row_name(lp, r, rname); + glp_set_row_bnds(lp, r, GLP_UP, 0.0, 0.0); + for (int j=0; j<NumberOfTransitions(); j++) { + V[j] = 0.0; + } + for (int j=0; j<NumberOfTransitions(); j++){ + if (places[k]->GetWeightOfOutputArc(j) != 0.0 ){ + V[j] = - places[k]->GetWeightOfOutputArc(j); + } + if (places[k]->GetWeightOfInputArc(j) != 0.0 ){ + V[j] += places[k]->GetWeightOfInputArc(j); + } + } +// cout << rname << " : "; + for (int j=1, l=beginofcbt; l<endofcbt; j++, l++) { + if (V[l] != 0.0){ + ia[arindex] = r; + ja[arindex] = j; + ar[arindex] = V[l]; + arindex++; +// cout << j << "(" << V[l] << ") - "; + } + } +// cout << " <= 0.0" << endl; + r++; + } + } + + // constraint e +// cout << "Contraint e\n"; + for (int i=1, k=beginofbp; k<endofbp; k++, i++) { + switch (places[k]->IsA()){ + case Batch_pl: maxflow = ((BatchPlace*)places[k])->GetInstantaneousSpeed() * ((BatchPlace*)places[k])->GetDensity(); + break; + case Triangular_pl: maxflow = ((TriangularBatchPlace*)places[k])->GetInstantaneousSpeed() * ((TriangularBatchPlace*)places[k])->GetCriticalDensity(); + break; + } + sprintf(rname, "e.%d", i); + glp_set_row_name(lp, r, rname); + glp_set_row_bnds(lp, r, GLP_UP, 0.0, maxflow); + + for (int j=0; j<NumberOfTransitions(); j++) { + V[j] = 0.0; + } + for (int j=0; j<NumberOfTransitions(); j++){ + if (places[k]->GetWeightOfInputArc(j) != 0.0 ){ + V[j] = places[k]->GetWeightOfInputArc(j); + } + } +// cout << rname << " : "; + for (int j=1, l=beginofcbt; l<endofcbt; j++, l++) { + if (V[l] != 0.0){ + ia[arindex] = r; + ja[arindex] = j; + ar[arindex] = V[l]; + arindex++; +// cout << j << "(" << V[l] << ") - "; + } + } +// cout << "0.0 - " << maxflow << endl; + r++; + } + + + // constraint f +// cout << "Contraint f\n"; + for (int i=1, k=beginofbp; k<endofbp; k++, i++) { + maxflow = ((BatchPlace*)places[k])->GetInstantaneousSpeed() * ((BatchPlace*)places[k])->GetDensityOutputBatch(); + sprintf(rname, "f.%d", i); + glp_set_row_name(lp, r, rname); + glp_set_row_bnds(lp, r, GLP_UP, 0.0, maxflow); + + for (int j=0; j<NumberOfTransitions(); j++) { + V[j] = 0.0; + } + for (int j=0; j<NumberOfTransitions(); j++){ + if (places[k]->GetWeightOfOutputArc(j) != 0.0 ){ + V[j] = places[k]->GetWeightOfOutputArc(j); + } + } +// cout << rname << " : "; + for (int j=1, l=beginofcbt; l<endofcbt; j++, l++) { + if (V[l] != 0.0){ + ia[arindex] = r; + ja[arindex] = j; + ar[arindex] = V[l]; + arindex++; +// cout << j << "(" << V[l] << ") - "; + } + } +// cout << "0.0 - " << maxflow << endl; + r++; + } + + // constraint g +// cout << "Contraint g\n"; + for (int i=1, k=beginoftbp; k<endoftbp; k++, i++) { + maxflow = ((TriangularBatchPlace*)places[k])->GetInstantaneousSpeed() * ((TriangularBatchPlace*)places[k])->GetCriticalDensity(); + sprintf(rname, "g.%d", i); + glp_set_row_name(lp, r, rname); + glp_set_row_bnds(lp, r, GLP_UP, 0.0, maxflow); + + for (int j=0; j<NumberOfTransitions(); j++) { + V[j] = 0.0; + } + for (int j=0; j<NumberOfTransitions(); j++){ + if (places[k]->GetWeightOfOutputArc(j) != 0.0 ){ + V[j] = places[k]->GetWeightOfOutputArc(j); + } + } +// cout << rname << " : "; + for (int j=1, l=beginofcbt; l<endofcbt; j++, l++) { + if (V[l] != 0.0){ + ia[arindex] = r; + ja[arindex] = j; + ar[arindex] = V[l]; + arindex++; +// cout << j << "(" << V[l] << ") - "; + } + } +// cout << "0.0 - " << maxflow << endl; + r++; + } + + glp_term_out(GLP_OFF); + glp_load_matrix(lp, arindex-1, ia, ja, ar); + glp_simplex(lp, NULL); + + for (int i=0, k=beginofcbt; k<endofcbt; k++, i++) { + IFF[i] = glp_get_col_prim(lp, (i+1)); + f = ((ContinuousTransition*)transitions[k])->GetFlow(); + f->SetTheoreticalFlow(IFF[i]); + f->SetCurrentFlow(IFF[i]); + +// cout << transitions[k]->GetName() << " : " << IFF[i] << endl; + } + + int col[numberofcontandbatchtransitions]; + double val[numberofcontandbatchtransitions]; + +/* for (int i=1; i<=glp_get_num_rows(lp); i++){ + cout << glp_get_row_name(lp, i) << " : "; + for (int j=1; j<=glp_get_mat_row(lp, i, col, val); j++){ + cout << col[j] << "(" << val[j] << ") - "; + } + cout << glp_get_row_lb(lp, i) << " - " << glp_get_row_ub(lp, i) << endl; + } +*/ + glp_delete_prob(lp); +} + +//------------------------------------------------------------------------------ +// Compute Controlled Firing Flow (CFF) based on steady flow +//------------------------------------------------------------------------------ +void BPN::ComputeCFF() +{ + cout << "\nCompute CFF\n\n"; + + Flow *u; + double steadyflow; + double maxflow; + + + // Verify if the marking is reached in this procedure + + + + // contraints a and b ==> not enabled transition set + int beginofcbt = numberofdiscretetransitions; + int endofcbt = numberofdiscretetransitions + numberofcontinuoustransitions + numberofbatchtransitions; + + int numberofcontandbatchtransitions = numberofcontinuoustransitions + numberofbatchtransitions; + int numberofnotenabledcontandbatchtransitions = 0; + int numberofnotenabledorlesssteadcontandbatchtransitions = 0; + for (int i=beginofcbt; i<endofcbt; i++){ + if (transitions[i]->GetState() == 0.0 ){ + numberofnotenabledcontandbatchtransitions++; + } + + if ((transitions[i]->GetState() == 0.0) || (transitions[i]->IsOnState() == 0)){ + numberofnotenabledorlesssteadcontandbatchtransitions++; + } + } + + if (numberofcontandbatchtransitions == 0) // no need to compute CFF + return; + + // contraint c ===>continuous and batch place whose marking quantity is greater than steady marking quantity + int beginofcbp = numberofdiscreteplaces; + int endofcbp = numberofdiscreteplaces + numberofcontinuousplaces + numberofbatchplaces; + int numberofgreatercontandbatchplaces = 0; + for (int i=beginofcbp; i<endofcbp; i++){ + switch (places[i] ->IsA()){ + case Continuous_pl: if (((ContinuousPlace*)places[i])->IsGreaterThanSteadyQuantity() == 1){ + numberofgreatercontandbatchplaces++; + } + break; + case Batch_pl: if (((BatchPlace*)places[i])->IsGreaterThanSteadyQuantity() == 1){ + numberofgreatercontandbatchplaces++; + } + break; + + } + } + + // contraint d ===>continuous and batch place whose marking quantity is equal to steady marking quantity (S_E) + // int beginofcbp = numberofdiscreteplaces; + // int endofcbp = numberofdiscreteplaces + numberofcontinuousplaces + numberofbatchplaces; + int numberofequalcontandbatchplaces = 0; + for (int i=beginofcbp; i<endofcbp; i++){ + switch (places[i] ->IsA()){ + case Continuous_pl: if (((ContinuousPlace*)places[i])->IsEqualSteadyQuantity() == 1){ + numberofequalcontandbatchplaces++; + } + break; + case Batch_pl: if (((BatchPlace*)places[i])->IsEqualSteadyQuantity() == 1){ + numberofequalcontandbatchplaces++; + } + break; + } + } + + + // contraint e ===>continuous and batch place whose marking quantity is less than steady marking quantity(S_L) + int beginofbp = numberofdiscreteplaces + numberofcontinuousplaces; + int endofbp = numberofdiscreteplaces + numberofcontinuousplaces + numberofbatchplaces; + int numberoflesscontandbatchplaces = 0; + for (int i=beginofcbp; i<endofcbp; i++){ + switch (places[i] ->IsA()){ + case Continuous_pl: if (((ContinuousPlace*)places[i])->IsLessThanSteadyQuantity() == 1){ + numberoflesscontandbatchplaces++; + } + break; + case Batch_pl: if (((BatchPlace*)places[i])->IsLessThanSteadyQuantity() == 1){ + numberoflesscontandbatchplaces++; + } + break; + } + } + +// contraint f ===>transition with at least one of its input places belonging to S_L. +// int beginofcbt = numberofdiscretetransitions; + // int endofcbt = numberofdiscretetransitions + numberofcontinuoustransitions + numberofbatchtransitions; +// int numberofcontandbatchtransitions = numberofcontinuoustransitions + numberofbatchtransitions; + int numberofinputplacelesscontandbatchtransitions = 0; + for (int i=beginofcbt; i<endofcbt; i++){ + switch (transitions[i] ->IsA()){ + case Continuous_tr: if (((ContinuousTransition*)transitions[i])->GetState()==0.0){ //GetCFFState()= 0.0 + numberofinputplacelesscontandbatchtransitions++; + break; + } + case Batch_tr: if (((BatchTransition*)transitions[i])->GetState()== 0.0){ + numberofinputplacelesscontandbatchtransitions++; + } + break; + } +} +//constraint g + // int numberofbatchplaces; + + + + + int nc = 0; // total of contraints + int r = 0; // current contraint + char rname[256]; // row name + + double V[NumberOfTransitions()]; // used to compute the incidence matrix, only continuous and batch positions are used + + + // variables to the linear program + glp_prob *lp; + double CFF[numberofcontandbatchtransitions]; // to store the result of the linear program + + nc = numberofcontandbatchtransitions; // contraint a + nc+= numberofnotenabledorlesssteadcontandbatchtransitions; // contraint b + nc+= numberofgreatercontandbatchplaces; // contraint c + nc+= numberofequalcontandbatchplaces; // contraint d + //nc+= numberoflesscontandbatchplaces; // contraint e + //nc+= numberofinputplacelesscontandbatchtransitions; // contraint f + nc+= numberofbatchplaces; // contraints g + + + // contraints matrix + int ia[nc * numberofcontandbatchtransitions]; + int ja[nc * numberofcontandbatchtransitions]; + double ar[nc * numberofcontandbatchtransitions]; + int arindex; + + + // initialising linear program + lp = glp_create_prob(); + glp_set_prob_name(lp, "CFF"); + glp_set_obj_dir(lp, GLP_MAX); + glp_add_cols(lp, numberofcontandbatchtransitions); + glp_add_rows(lp, nc); + + // initialising transitions bound + cout << "\nTransitions bound\n\n"; + for (int i=1, k=beginofcbt; k<endofcbt; k++, i++) { + glp_set_obj_coef(lp, i, 1.0); // set (change) objective coefficient or constant term + glp_set_col_name(lp, i, transitions[k]->GetName()); // name of the transition + u = transitions[k]->GetFlow(); + if (u->GetSteadyFlow() != 0.0) + glp_set_col_bnds(lp, i, GLP_DB, 0.0, u->GetSteadyFlow());//set (change) column bounds + else + glp_set_col_bnds(lp, i, GLP_FX, 0.0, 0.0); + + cout << transitions[k]->GetName() << " : 0.0 - " << u->GetSteadyFlow() << endl; + } + + r = 1; + arindex = 1; + + cout << "\nStart contraints\n\n"; + // constraint a + cout << "Contraint a\n"; + for (int i=1, k=beginofcbt; k<endofcbt; k++, i++) { + sprintf(rname, "a.%d", i); + u = transitions[k]->GetFlow(); + glp_set_row_name(lp, r, rname); + if (u->GetSteadyFlow() != 0.0) + glp_set_row_bnds(lp, r, GLP_DB, 0.0, u->GetSteadyFlow()); //compare with steadyflow + else + glp_set_row_bnds(lp, r, GLP_FX, 0.0, 0.0); + + ia[arindex] = r; + ja[arindex] = i; + ar[arindex] = 1.0; // weigth + arindex++; + r++; + + cout << rname << " : " << "0.0 <= x <= " << u->GetSteadyFlow() << endl; + } + + // constraint b + cout << "Contraint b\n"; + for (int i=1, k=beginofcbt; k<endofcbt; k++, i++) { + sprintf(rname, "b.%d", i); + if (transitions[k]->GetState() == 0.0 || (transitions[k]->IsOnState() == 0)){ + glp_set_row_name(lp, r, rname); + glp_set_row_bnds(lp, r, GLP_FX, 0.0, 0.0); + + ia[arindex] = r; + ja[arindex] = i; + ar[arindex] = 1.0; // weigth + arindex++; + r++; + cout << rname << " : " << ja[arindex-1] << ": 0.0 = x = 0.0 " << endl; + } + } + + // constraint c + cout << "Contraint c\n"; + for (int i=1, k=beginofcbp; k<endofcbp; k++, i++) { + switch (places[k] ->IsA()){ + case Continuous_pl: if (((ContinuousPlace*)places[k])->IsGreaterThanSteadyQuantity() == 0) + continue; + break; + case Batch_pl: if (((BatchPlace*)places[k])->IsGreaterThanSteadyQuantity() == 0) + continue; + break; + } + sprintf(rname, "c.%d", i); + glp_set_row_name(lp, r, rname); + glp_set_row_bnds(lp, r, GLP_UP, 0.0, 0.0); //look after + for (int j=0; j<NumberOfTransitions(); j++) { + V[j] = 0.0; + } + + for (int j=0; j<NumberOfTransitions(); j++){ + if (places[k]->GetWeightOfOutputArc(j) != 0.0 ){ + V[j] = - places[k]->GetWeightOfOutputArc(j); + cout << " - V [" << j << "] " ; + } + if (places[k]->GetWeightOfInputArc(j) != 0.0 ){ + cout << " + V [" << j << "] " ; + V[j] += places[k]->GetWeightOfInputArc(j); + } + } + cout << endl; + cout << rname << " : "; + for (int j=1, l=beginofcbt; l<endofcbt; j++, l++) { + if (V[l] != 0.0){ + ia[arindex] = r; + ja[arindex] = j; + ar[arindex] = V[l]; + arindex++; + cout << j << "(" << V[l] << ") - "; + } + } + cout << " <= 0.0" << endl; + r++; + } + + //constraint d + cout << "Contraint d\n"; + for (int i=1, k=beginofcbp; k<endofcbp; k++, i++) { + switch (places[k] ->IsA()){ + case Continuous_pl: if (((ContinuousPlace*)places[k])->IsEqualSteadyQuantity() == 0) + continue; + break; + case Batch_pl: if (((BatchPlace*)places[k])->IsEqualSteadyQuantity() == 0) + continue; + break; + } + sprintf(rname, "d.%d", i); + glp_set_row_name(lp, r, rname); + glp_set_row_bnds(lp, r, GLP_FX, 0.0, 0.0); + for (int j=0; j<NumberOfTransitions(); j++) { + V[j] = 0.0; + } + + for (int j=0; j<NumberOfTransitions(); j++){ + if (places[k]->GetWeightOfOutputArc(j) != 0.0 ){ + V[j] = - places[k]->GetWeightOfOutputArc(j); + cout << " - V [" << j << "] " ; + } + if (places[k]->GetWeightOfInputArc(j) != 0.0 ){ + cout << " + V [" << j << "] " ; + V[j] += places[k]->GetWeightOfInputArc(j); + } + } + cout << endl; + cout << rname << " : "; + for (int j=1, l=beginofcbt; l<endofcbt; j++, l++) { + if (V[l] != 0.0){ + ia[arindex] = r; + ja[arindex] = j; + ar[arindex] = V[l]; + arindex++; + cout << j << "(" << V[l] << ") - "; + } + } + cout << " = 0.0" << endl; + r++; + } + + // constraint d +// cout << "Contraint d\n"; + /* for (int i=1, k=beginofcbp; k<endofcbp; k++, i++) { + switch (places[k] ->IsA()){ + case Continuous_pl: if (((ContinuousPlace*)places[k])->IsEqualSteadyQuantity() == 1.0){ + } + break; + case Batch_pl: if (((BatchPlace*)places[k])->IsEqualSteadyQuantity() == 1.0){ + } + break; + } + sprintf(rname, "d.%d", i); + glp_set_row_name(lp, r, rname); + glp_set_row_bnds(lp, r, GLP_UP, 0.0, 0.0); + for (int j=0; j<NumberOfTransitions(); j++) { + V[j] = 0.0; + } + for (int j=0; j<NumberOfTransitions(); j++){ + if (places[k]->GetWeightOfOutputArc(j) != 0.0 ){ + V[j] = - places[k]->GetWeightOfOutputArc(j); + } + if (places[k]->GetWeightOfInputArc(j) != 0.0 ){ + V[j] += places[k]->GetWeightOfInputArc(j); + } + } +// cout << rname << " : "; + for (int j=1, l=beginofcbt; l<endofcbt; j++, l++) { + if (V[l] != 0.0){ + ia[arindex] = r; + ja[arindex] = j; + ar[arindex] = V[l]; + arindex++; +// cout << j << "(" << V[l] << ") - "; + } + } +// cout << " <= 0.0" << endl; + r++; + } +*/ + + // constraint e //input place's marking quantity is less than steady marking quantity. + cout << "Contraint e\n"; + + for (int i=1, k=beginofbp; k<endofbp; k++, i++) { + maxflow = ((BatchPlace*)places[k])->GetInstantaneousSpeed() * ((BatchPlace*)places[k])->GetDensityOutputBatch(); + sprintf(rname, "e.%d", i); + glp_set_row_name(lp, r, rname); + glp_set_row_bnds(lp, r, GLP_UP, 0.0, maxflow); + + for (int j=0; j<NumberOfTransitions(); j++) { + V[j] = 0.0; + } + for (int j=0; j<NumberOfTransitions(); j++){ + if (places[k]->GetWeightOfOutputArc(j) != 0.0 ){ + V[j] = places[k]->GetWeightOfOutputArc(j); + } + } + cout << rname << " : "; + for (int j=1, l=beginofcbt; l<endofcbt; j++, l++) { + if (V[l] != 0.0){ + ia[arindex] = r; + ja[arindex] = j; + ar[arindex] = V[l]; + arindex++; + cout << j << "(" << V[l] << ") - "; + } + } + cout << "0.0 <= x <= " << maxflow << endl; + r++; +} + + glp_term_out(GLP_OFF); + glp_load_matrix(lp, arindex-1, ia, ja, ar); + glp_simplex(lp, NULL); + + for (int i=0, k=beginofcbt; k<endofcbt; k++, i++) { + CFF[i] = glp_get_col_prim(lp, (i+1)); + u = ((ContinuousTransition*)transitions[k])->GetFlow(); + u->SetTheoreticalFlow(CFF[i]); + u->SetCurrentFlow(CFF[i]); + +// cout << transitions[k]->GetName() << " : " << CFF[i] << endl; + } + + + + int col[numberofcontandbatchtransitions]; + double val[numberofcontandbatchtransitions]; + +/* for (int i=1; i<=glp_get_num_rows(lp); i++){ + cout << glp_get_row_name(lp, i) << " : "; + for (int j=1; j<=glp_get_mat_row(lp, i, col, val); j++){ + cout << col[j] << "(" << val[j] << ") - "; + } + cout << glp_get_row_lb(lp, i) << " - " << glp_get_row_ub(lp, i) << endl; + } +*/ + glp_delete_prob(lp); +}//======================================================================= + + + +//--------------------------------------------------------------------------- +// Compute current firing quantity at each time step +//------------------------------------------------------------------------------- +void BPN::ComputeCurrentFiringQuantity(double steptime) +{ + FiringQuantity *z; + Flow *f; + double currentfiringquantity1; + + for (int i=0; i<NumberOfTransitions(); i++){ + f=transitions[i]->GetFlow(); + z=transitions[i]->GetFiringQuantity(); + // currentfiringquantity=transitions[i]->CurrentFiringQuantity(); + currentfiringquantity1 = (f->GetCurrentFlow() * steptime) + z->GetCurrentFiringQuantity(); + // cout<<"current first: "<<currentfiringquantity<<endl; + z->SetCurrentFiringQuantity(currentfiringquantity1); + // cout<<"current second: "<<currentfiringquantity<<endl; + // currentfiringquantity-= f->GetCurrentFlow() * steptime; + // cout<<"current third: "<<currentfiringquantity<<endl; + } +} + +//-------------------------------------------------------------------------- +// Compute steady firing quantity vector (minimal firing count vector) +//-------------------------------------------------------------------------- +// Solve the LLP: +// min Z^s +// q^s=q^0 + C * Z^s +// Z^s >= 0 +//-------------------------------------------------------------------------- +void BPN::ComputeSteadyFiringQuantity() +{ + Transition *t; + Place *p; + Flow *f; + FiringQuantity *z; + double steadyfiringquantity; + double remainingquantity; + + // contraints a + int beginofcbp = numberofdiscreteplaces; + int endofcbp = numberofdiscreteplaces + numberofcontinuousplaces + numberofbatchplaces; + int numberofcontandbatchplaces = numberofcontinuousplaces + numberofbatchplaces; + + //constraints b + int beginofcbt = numberofdiscretetransitions; + int endofcbt = numberofdiscretetransitions + numberofcontinuoustransitions + numberofbatchtransitions; + int numberofcontandbatchtransitions = numberofcontinuoustransitions + numberofbatchtransitions; + + + int nc = 0; // total of contraints + int r = 0; // current contraint + char rname[256]; // row name + + double V[NumberOfTransitions()]; // used to compute the incidence matrix, only continuous and batch positions are used + + + // variables to the linear program + glp_prob *lp; + double SS[numberofcontandbatchtransitions+1]; // to store the result of the linear program + //double *SS; + + nc = numberofcontandbatchplaces; // contraint a + nc+= numberofcontandbatchtransitions; // contraint b + + + // contraints matrix + int ia[nc * (numberofcontandbatchtransitions)]; + int ja[nc * (numberofcontandbatchtransitions)]; + double ar[nc * (numberofcontandbatchtransitions)]; + int arindex; + + // initialising linear program + lp = glp_create_prob(); + glp_set_prob_name(lp, "ZS"); + glp_set_obj_dir(lp, GLP_MAX); + glp_add_cols(lp, (numberofcontandbatchtransitions)); + glp_add_rows(lp, nc); + + + + cout << "\nSteady firing quantities bound\n\n"; + for (int k=beginofcbt; k<endofcbt; k++) { + glp_set_obj_coef(lp, k+1, -1.0); // set (change) objective coefficient or constant term + glp_set_col_name(lp, k+1, transitions[k]->GetName()); // name of the transition + f = transitions[k]->GetFlow(); + if (f->GetMaximumFlow() != 0.0) + glp_set_col_bnds(lp, k+1, GLP_LO, 0.0, 0.0);//set (change) column bounds + else + glp_set_col_bnds(lp, k+1, GLP_FX, 0.0, 0.0); + + cout << transitions[k]->GetName() << " z: >= " << 0.0 << endl; + } + + + + r = 1; + arindex = 1; + + + cout << "\nStart contraints\n\n"; + // constraint a + cout << "Contraint a\n"; + for (int i=1, k=beginofcbp; k<endofcbp; k++, i++) { + switch (places[k] ->IsA()){ + case Continuous_pl: + remainingquantity = ((ContinuousPlace*)places[k])->GetSteadyMarks()- ((ContinuousPlace*)places[k])->GetInitialMarks(); + break; + case Batch_pl: + remainingquantity = ((BatchPlace*)places[k])->GetSteadyQuantity()-((BatchPlace*)places[k])->GetInitialQuantity(); + + break; + } + + sprintf(rname, "a.%d", i); + glp_set_row_name(lp, r, rname); + glp_set_row_bnds(lp, r, GLP_FX, remainingquantity, remainingquantity); + + + for (int j=0; j<NumberOfTransitions(); j++) { + V[j] = 0.0; + } + + for (int j=0; j<NumberOfTransitions(); j++){ + if (places[k]->GetWeightOfOutputArc(j) != 0.0 ){ + V[j] = - places[k]->GetWeightOfOutputArc(j); + cout << " - V [" << j << "] " ; + } + if (places[k]->GetWeightOfInputArc(j) != 0.0 ){ + cout << " + V [" << j << "] " ; + V[j] += places[k]->GetWeightOfInputArc(j); + } + } + + cout << endl; + cout << rname << " : "; + for (int j=0, l=beginofcbt; l<endofcbt; j++, l++) { + if (V[j] != 0.0){ + ia[arindex] = r; + ja[arindex] = l+1; + ar[arindex] = V[j]; + arindex++; + cout << "Zs"<< j << "(" << V[j] << ") + "; + } + } + cout << " = "<< remainingquantity << endl; + r++; + } + + + // constraint b + cout << "Contraint b\n"; + + for (int i=1, k=beginofcbt; k<endofcbt; k++, i++) { + sprintf(rname, "b.%d", i); + glp_set_row_name(lp, r, rname); + glp_set_row_bnds(lp, r, GLP_LO, 0.0, 0.0); + + ia[arindex] = r; + ja[arindex] = k+1; + ar[arindex] = 1.0; // weight + arindex++; + r++; + cout << rname << " : " << "Zs " << i << " >= 0.0 " << endl; + } + + + glp_term_out(GLP_OFF); + glp_load_matrix(lp, arindex-1, ia, ja, ar); + glp_simplex(lp, NULL); + + + for (int i=1;i<(numberofcontandbatchtransitions+1); i++){ + SS[i]=glp_get_col_prim(lp, i); + cout<< "SS[" << i <<"] = " << SS[i]<<endl; + z=transitions[i-1]->GetFiringQuantity(); + z->SetSteadyFiringQuantity(SS[i]); + +// transitions[i]->SetSteadyFiringQuantity(SS[i]); + //steadyfiringquantity->SetSteadyFiringQuantity(SS[i]); + //SS = calloc(1+numberofcontandbatchplaces+2*numberofcontandbatchtransitions, sizeof(double)); + } + +// for (int i=1;i<(numberofcontandbatchtransitions+1); i++){ +// printf("z=%lf,SS[i]=%lf\n",z,i, SS[i]); +// } + + // f = ((ContinuousTransition*)transitions[k-numberofcontandbatchplaces])->GetFlow(); + // f->SetTheoreticalFlow(SS[k]); + // f->SetCurrentFlow(SS[k]); + + // cout << transitions[k-numberofcontandbatchplaces]->GetName() << " : " << SS[i] << endl; + + int col[numberofcontandbatchtransitions]; + double val[numberofcontandbatchtransitions]; + + /* + for (int i=1; i<=glp_get_num_rows(lp); i++){ + cout << glp_get_row_name(lp, i) << " : "; + for (int j=1; j<=glp_get_mat_row(lp, i, col, val); j++){ + cout << col[j] << "(" << val[j] << ") - "; + } + cout << glp_get_row_lb(lp, i) << " - " << glp_get_row_ub(lp, i) << endl; + } + */ + glp_delete_prob(lp); + return 0; +} + + +//============================================================================== +// Compute the steady state with assigned transfer speed +//============================================================================== +// To do list: +// 1. Set the result of marking and flow into steady marking and steady flow. +// 2. Give the computation of the steady state with variable transfer speed. +// 3. Consider the discrete nodes. +void BPN::ComputeSteadyState() +{ + + cout << "\nCompute Steadystate\n\n"; + + + double capacity; + double quantity_initial; + double maxflow; + Flow *f; + double z; + + + // contraints a + int beginofcbt = numberofbatchplaces+numberofcontinuousplaces+numberofdiscreteplaces+numberofdiscretetransitions; + int endofcbt = numberofbatchplaces+numberofcontinuousplaces+numberofdiscreteplaces+numberofdiscretetransitions + numberofcontinuoustransitions + numberofbatchtransitions; + int numberofcontandbatchtransitions = numberofcontinuoustransitions + numberofbatchtransitions; + + //constraints b and b' + int beginofbp = numberofdiscreteplaces + numberofcontinuousplaces; + int endofbp = numberofdiscreteplaces + numberofcontinuousplaces + numberofbatchplaces; +// int numberofbatchplaces; + + //constraints c + + //constraints d + int beginofcbp = numberofdiscreteplaces; + int endofcbp = numberofdiscreteplaces + numberofcontinuousplaces + numberofbatchplaces; + int numberofcontandbatchplaces = numberofcontinuousplaces + numberofbatchplaces; + + //constraints e + int beginofft = numberofcontandbatchplaces + numberofcontandbatchtransitions; + int endofft = numberofcontandbatchplaces + numberofcontandbatchtransitions + numberofcontandbatchtransitions; + + // set value to all places and transitions + // int numberofcontinuousplaces; + // int numberofcontinuoustransitions; + + // if (numberofcontandbatchtransitions == 0 || numberofcontandbatchplaces ==0) // no need to compute CFF + // return; + + + int nc = 0; // total of contraints + int r = 0; // current contraint + char rname[256]; // row name + + double V[NumberOfTransitions()]; // used to compute the incidence matrix, only continuous and batch positions are used + + + // variables to the linear program + glp_prob *lp; + double SS[numberofcontandbatchplaces+2*numberofcontandbatchtransitions+1]; // to store the result of the linear program + //double *SS; + + nc = numberofcontandbatchtransitions; // contraint a + nc+= numberofbatchplaces; // contraint b + nc+= numberofbatchplaces; // contraint b' + nc+= numberofbatchplaces; // contraint c + nc+= numberofcontandbatchplaces; // contraint d + nc+= numberofcontandbatchplaces; // contraint e + + + // contraints matrix + int ia[nc * (numberofcontandbatchplaces+2*numberofcontandbatchtransitions)]; + int ja[nc * (numberofcontandbatchplaces+2*numberofcontandbatchtransitions)]; + double ar[nc * (numberofcontandbatchplaces+2*numberofcontandbatchtransitions)]; + int arindex; + + // initialising linear program + lp = glp_create_prob(); + glp_set_prob_name(lp, "SS"); + glp_set_obj_dir(lp, GLP_MAX); + glp_add_cols(lp, (numberofcontandbatchplaces+2*numberofcontandbatchtransitions)); + glp_add_rows(lp, nc); + + + // initialising transitions bound + cout << "\nTransitions bound\n\n"; + + //wodes conflict example coefficient. + // glp_set_obj_coef(lp, 3, 1.0); + // glp_set_obj_coef(lp, 6, 10.0); + // glp_set_obj_coef(lp, 8, 20.0); + // glp_set_obj_coef(lp, 9, 1.0); + +//example1 one batch place + // glp_set_obj_coef(lp, 1, 1); + // glp_set_obj_coef(lp, 2, 10); + + // glp_set_obj_coef(lp, 3, 10.0); + // glp_set_obj_coef(lp, 4, 1.0); + + // glp_set_obj_coef(lp, 5, 1.0); + // glp_set_obj_coef(lp, 6, 10.0); + + // glp_set_obj_coef(lp, 11, 1.0); + + //example1 two batch place +// glp_set_obj_coef(lp, 1, 1.0); +// glp_set_obj_coef(lp, 3, 10.0); +// glp_set_obj_coef(lp, 2, 1.0); +// glp_set_obj_coef(lp, 4, 10.0); + +// glp_set_obj_coef(lp, 5, 10.0); +// glp_set_obj_coef(lp, 6, 1.0); +//glp_set_obj_coef(lp, 8, 1.0); +//glp_set_obj_coef(lp, 9, 10.0); + // glp_set_obj_coef(lp, 7, 1.0); + // glp_set_obj_coef(lp, 9, 1.0); +// glp_set_obj_coef(lp, 1, 1.0); +// glp_set_obj_coef(lp, 3, 10.0); +// glp_set_obj_coef(lp, 8, 1.0); +// glp_set_obj_coef(lp, 10, 3.0); + +//wodes+tz1+tz2 +//glp_set_obj_coef(lp, 10, 10.0); +//glp_set_obj_coef(lp, 11, 1.0); +//glp_set_obj_coef(lp, 4, 5.0); + + + + for (int k=beginofcbt; k<endofcbt; k++) { + glp_set_obj_coef(lp, k+1, 1.0); // set (change) objective coefficient or constant term + glp_set_col_name(lp, k+1, transitions[k-numberofcontandbatchplaces]->GetName()); // name of the transition + f = transitions[k-numberofcontandbatchplaces]->GetFlow(); + if (f->GetMaximumFlow() != 0.0) + glp_set_col_bnds(lp, k+1, GLP_DB, 0.0, f->GetMaximumFlow());//set (change) column bounds + else + glp_set_col_bnds(lp, k+1, GLP_FX, 0.0, 0.0); + + cout << transitions[k-numberofcontandbatchplaces]->GetName() << " : 0.0 - " << f->GetMaximumFlow() << endl; + } + + // initialising quantities bound + cout << "\nQuantities bound\n\n"; + for (int k=beginofcbp; k<endofcbp; k++) { + capacity = ((BatchPlace*)places[k])->GetDensity()*((BatchPlace*)places[k])->GetLength(); + // glp_set_obj_coef(lp, k+1, 0.0); // set (change) objective coefficient or constant term + glp_set_col_name(lp, k+1, places[k]->GetName()); // name of the transition + switch (places[k] ->IsA()){ + case Batch_pl: if (capacity != 0.0){ + glp_set_col_bnds(lp, k+1, GLP_DB, 0.0, capacity); + } + else{ + glp_set_col_bnds(lp, k+1, GLP_FX, 0.0, 0.0); + } + cout << places[k]->GetName() << " : 0.0 - " << capacity<<"\n"; + continue; + + break; + + case Continuous_pl: capacity = ((BatchPlace*)places[k+numberofcontinuousplaces])->GetDensity()*((BatchPlace*)places[k+numberofcontinuousplaces])->GetLength(); + glp_set_col_bnds(lp, k+1, GLP_DB, 0.0, capacity); //maybe revised! + cout << places[k]->GetName() << " : 0.0 - "<<capacity<<"\n"; + continue; + break; + } + } + + cout << "\nMinimal firing quantities bound\n\n"; + for (int k=beginofft; k<endofft; k++) { + // glp_set_obj_coef(lp, k+1, 1.0e-6); // set (change) objective coefficient or constant term + glp_set_col_name(lp, k+1, transitions[k-numberofcontandbatchplaces-numberofcontandbatchtransitions]->GetName()); // name of the transition + f = transitions[k-numberofcontandbatchplaces-numberofcontandbatchtransitions]->GetFlow(); + if (f->GetMaximumFlow() != 0.0) + glp_set_col_bnds(lp, k+1, GLP_LO, 0.0, 0.0);//set (change) column bounds + else + glp_set_col_bnds(lp, k+1, GLP_FX, 0.0, 0.0); + + cout << transitions[k-numberofcontandbatchplaces-numberofcontandbatchtransitions]->GetName() << " z: >= " << 0.0 << endl; + } + + r = 1; + arindex = 1; + + + cout << "\nStart contraints\n\n"; + // constraint a + cout << "Contraint a\n"; + for (int i=1, k=beginofcbt; k<endofcbt; k++, i++) { + sprintf(rname, "a.%d", i); + f = transitions[k-numberofcontandbatchplaces]->GetFlow(); + glp_set_row_name(lp, r, rname); + if (f->GetMaximumFlow() != 0.0) + glp_set_row_bnds(lp, r, GLP_DB, 0.0, f->GetMaximumFlow()); //compare with steadyflow + else + glp_set_row_bnds(lp, r, GLP_FX, 0.0, 0.0); + + ia[arindex] = r; + ja[arindex] = k+1; + ar[arindex] = 1.0; // weigth + arindex++; + r++; + cout << rname << " : " << "0.0 <= y <= " << f->GetMaximumFlow() << endl; + } + + // constraint b + cout << "Contraint b\n"; + for (int i=1, k=beginofbp; k<endofbp; k++, i++) { + sprintf(rname, "b.%d", i); + capacity= ((BatchPlace*)places[k])->GetDensity() * ((BatchPlace*)places[k])->GetLength(); + glp_set_row_name(lp, r, rname); + if (capacity != 0.0 ){ + glp_set_row_bnds(lp, r, GLP_DB, 0.0, capacity); + } + else{ + glp_set_row_bnds(lp, r, GLP_FX, 0.0, 0.0); + } + ia[arindex] = r; + ja[arindex] = k+1; + ar[arindex] = 1.0; // weigth + arindex++; + r++; + cout << rname << " : " << " 0.0 <= "<< " q" <<ja[arindex-1] << " <= "<<capacity << endl; + } + + // constraint b' + cout << "Contraint b\n"; + for (int i=1, k=beginofbp; k<endofbp; k++, i++) { + sprintf(rname, "b.%d", i); + glp_set_row_name(lp, r, rname); + glp_set_row_bnds(lp, r, GLP_LO, 0.0, 0.0); + + ia[arindex] = r; + ja[arindex] = k+1; + ar[arindex] = 1.0 ; + arindex++; + + for (int j=0; j<NumberOfTransitions(); j++) { + V[j] = 0.0; + } + for (int j=0; j<NumberOfTransitions(); j++){ + if (places[k]->GetWeightOfOutputArc(j) != 0.0 ){ + V[j] = places[k]->GetWeightOfOutputArc(j); + } + } + cout << rname << " : " << "q" <<k+1; + + + for (int j=0, l=beginofcbt; l<endofcbt; j++, l++) { + if (V[j] != 0.0){ + ia[arindex] = r; + ja[arindex] = l+1; + ar[arindex] = -V[j] * ((BatchPlace*)places[k])->GetLength() / ((BatchPlace*)places[k])->GetInstantaneousSpeed() ; + arindex++; + cout << ar[arindex-1]<<"y * " <<j+1; + } + } + cout << ">=0.0" <<endl; + r++; +} + + // Contraint c + cout << "Contraint c\n"; + for (int i=1, k=beginofbp; k<endofbp; k++, i++) { + maxflow = ((BatchPlace*)places[k])->GetInstantaneousSpeed() * ((BatchPlace*)places[k])->GetDensity(); + + sprintf(rname, "c.%d", i); + glp_set_row_name(lp, r, rname); + glp_set_row_bnds(lp, r, GLP_UP, 0.0, maxflow); + + for (int j=0; j<NumberOfTransitions(); j++) { + V[j] = 0.0; + } + for (int j=0; j<NumberOfTransitions(); j++){ + if (places[k]->GetWeightOfInputArc(j) != 0.0 ){ + V[j] = places[k]->GetWeightOfInputArc(j); + } + } + cout << rname << " : "; + for (int j=0, l=beginofcbt; l<endofcbt; j++, l++) { + if (V[j] != 0.0){ + ia[arindex] = r; + ja[arindex] = l+1; + ar[arindex] = V[j]; + arindex++; + cout << "y"<<j+1 << "(" << V[j] << ") + "; + } + } + cout << "<=" << maxflow << endl; + r++; + } + + // constraint d + + cout << "Contraint d\n"; + + for (int i=1, k=beginofcbp; k<endofcbp; k++, i++) { + + sprintf(rname, "d.%d", i); + glp_set_row_name(lp, r, rname); + glp_set_row_bnds(lp, r, GLP_FX, 0.0, 0.0); //look after + for (int j=0; j<NumberOfTransitions(); j++) { + V[j] = 0.0; + } + cout << rname<< ":"; + for (int j=0; j<NumberOfTransitions(); j++){ + if (places[k]->GetWeightOfOutputArc(j) != 0.0 ){ + V[j] = - places[k]->GetWeightOfOutputArc(j); + // cout << " - V [" << j << "] " ; + } + if (places[k]->GetWeightOfInputArc(j) != 0.0 ){ + // cout << " + V [" << j << "] " ; + V[j] += places[k]->GetWeightOfInputArc(j); + } + cout << "y"<<j+1 << "(" << V[j] << ") + "; + } + + for (int j=0, l=beginofcbt; l<endofcbt; j++, l++) { + if (V[j] != 0.0){ + ia[arindex] = r; + ja[arindex] = l+1; + ar[arindex] = V[j]; + arindex++; + + } + } + cout << " = 0.0" << endl; + r++; + } + + + //constraint e + cout << "Contraint e\n"; + for (int i=1, k=beginofcbp; k<endofcbp; k++, i++) { + switch (places[k] ->IsA()){ + case Continuous_pl: quantity_initial =((ContinuousPlace*)places[k])->GetMarks(); + break; + case Batch_pl:quantity_initial= ((BatchPlace*)places[k])->GetInitialQuantity(); + break; + } + sprintf(rname, "e.%d", i); + glp_set_row_name(lp, r, rname); + glp_set_row_bnds(lp, r, GLP_FX, quantity_initial, quantity_initial); + + ia[arindex] = r; + ja[arindex] = k+1; + ar[arindex] = 1.0; // weight + arindex++; + cout << rname<< " : "<<"q"<<k+1; + for (int j=0; j<NumberOfTransitions(); j++) { + V[j] = 0.0; + } + + for (int j=0; j<NumberOfTransitions(); j++){ + if (places[k]->GetWeightOfOutputArc(j) != 0.0 ){ + V[j] = - places[k]->GetWeightOfOutputArc(j); + // cout << " - V [" << j << "] " ; + } + if (places[k]->GetWeightOfInputArc(j) != 0.0 ){ + // cout << " + V [" << j << "] " ; + V[j] += places[k]->GetWeightOfInputArc(j); + } + cout << "+z"<<j+1 << "(" << V[j] << ") "; + } + + for (int j=0, l=beginofft; l<endofft; j++, l++) { + if (V[j] != 0.0){ + ia[arindex] = r; + ja[arindex] = l+1; + ar[arindex] = -V[j]; + arindex++; + // cout << j << "(" << V[j] << ") - "; + } + } + cout << "=" <<quantity_initial<< endl; + r++; + } + + + glp_term_out(GLP_OFF); + glp_load_matrix(lp, arindex-1, ia, ja, ar); + glp_simplex(lp, NULL); + + cout<<"\nThe steady state is : "<<endl; + z = glp_get_obj_val(lp); + + + + for (int i=1;i<(numberofcontandbatchplaces+2*numberofcontandbatchtransitions+1); i++){ + SS[i]=glp_get_col_prim(lp, i); + //SS = calloc(1+numberofcontandbatchplaces+2*numberofcontandbatchtransitions, sizeof(double)); + } + + for (int i=1;i<(numberofcontandbatchplaces+2*numberofcontandbatchtransitions+1); i++){ + printf("z=%lf,SS[i]=%lf\n",z,i, SS[i]); + // if (i< (numberofcontandbatchplaces+1)){ + +// if (i< (numberofcontandbatchplaces+numberofcontinuoustransitions+1 && i > numberofcontandbatchplaces)){ +// f = ((ContinuousTransition*)transitions[i+numberofcontandbatchplaces-1])->GetFlow(); +// f->SetTheoreticalFlow(SS[i+numberofcontandbatchplaces]); +// f->SetCurrentFlow(SS[i+numberofcontandbatchplaces]); +// } + } + + // f = ((ContinuousTransition*)transitions[k-numberofcontandbatchplaces])->GetFlow(); + // f->SetTheoreticalFlow(SS[k]); + // f->SetCurrentFlow(SS[k]); + + // cout << transitions[k-numberofcontandbatchplaces]->GetName() << " : " << SS[i] << endl; + + int col[numberofcontandbatchplaces+2*numberofcontandbatchtransitions]; + double val[numberofcontandbatchplaces+2*numberofcontandbatchtransitions]; + + /* + for (int i=1; i<=glp_get_num_rows(lp); i++){ + cout << glp_get_row_name(lp, i) << " : "; + for (int j=1; j<=glp_get_mat_row(lp, i, col, val); j++){ + cout << col[j] << "(" << val[j] << ") - "; + } + cout << glp_get_row_lb(lp, i) << " - " << glp_get_row_ub(lp, i) << endl; + } + */ + glp_delete_prob(lp); + return 0; + +}//======================== + + + +//============================================================================== +//Compute the periodic steady state with assigned transfer speed +//============================================================================== +//1) q_i \le pre(p_i, \cdot) y. +// input and output flow of a place is equal to steady flow. +//To do list +// 2) input and output flow is not equal? what happen + +void BPN::ComputePeriodicSteadyState() +{ + + cout << "\nCompute PeriodicSteadystate\n\n"; + + + double capacity; + double quantity_initial; + double maxflow; + Flow *f; + double z; + + + // contraints a + int beginofcbt = numberofbatchplaces+numberofcontinuousplaces+numberofdiscreteplaces+numberofdiscretetransitions; + int endofcbt = numberofbatchplaces+numberofcontinuousplaces+numberofdiscreteplaces+numberofdiscretetransitions + numberofcontinuoustransitions + numberofbatchtransitions; + int numberofcontandbatchtransitions = numberofcontinuoustransitions + numberofbatchtransitions; + + //constraints b and b' + int beginofbp = numberofdiscreteplaces + numberofcontinuousplaces; + int endofbp = numberofdiscreteplaces + numberofcontinuousplaces + numberofbatchplaces; +// int numberofbatchplaces; + + //constraints c + + //constraints d + int beginofcbp = numberofdiscreteplaces; + int endofcbp = numberofdiscreteplaces + numberofcontinuousplaces + numberofbatchplaces; + int numberofcontandbatchplaces = numberofcontinuousplaces + numberofbatchplaces; + + //constraints e + int beginofft = numberofcontandbatchplaces + numberofcontandbatchtransitions; + int endofft = numberofcontandbatchplaces + numberofcontandbatchtransitions + numberofcontandbatchtransitions; + + // set value to all places and transitions + // int numberofcontinuousplaces; + // int numberofcontinuoustransitions; + + // if (numberofcontandbatchtransitions == 0 || numberofcontandbatchplaces ==0) // no need to compute CFF + // return; + + + int nc = 0; // total of contraints + int r = 0; // current contraint + char rname[256]; // row name + + double V[NumberOfTransitions()]; // used to compute the incidence matrix, only continuous and batch positions are used + + + // variables to the linear program + glp_prob *lp; + double SS[numberofcontandbatchplaces+2*numberofcontandbatchtransitions+1]; // to store the result of the linear program + //double *SS; + + nc = numberofcontandbatchtransitions; // contraint a + nc+= numberofbatchplaces; // contraint b + nc+= numberofbatchplaces; // contraint b' + nc+= numberofbatchplaces; // contraint c + nc+= numberofcontandbatchplaces; // contraint d + nc+= numberofcontandbatchplaces; // contraint e + + + // contraints matrix + int ia[nc * (numberofcontandbatchplaces+2*numberofcontandbatchtransitions)]; + int ja[nc * (numberofcontandbatchplaces+2*numberofcontandbatchtransitions)]; + double ar[nc * (numberofcontandbatchplaces+2*numberofcontandbatchtransitions)]; + int arindex; + + // initialising linear program + lp = glp_create_prob(); + glp_set_prob_name(lp, "SS"); + glp_set_obj_dir(lp, GLP_MAX); + glp_add_cols(lp, (numberofcontandbatchplaces+2*numberofcontandbatchtransitions)); + glp_add_rows(lp, nc); + + + // initialising transitions bound + cout << "\nTransitions bound\n\n"; + + //wodes conflict example coefficient. + // glp_set_obj_coef(lp, 3, 1.0); + // glp_set_obj_coef(lp, 6, 10.0); + // glp_set_obj_coef(lp, 8, 20.0); + // glp_set_obj_coef(lp, 9, 1.0); + +//example1 one batch place + glp_set_obj_coef(lp, 1, 1); + glp_set_obj_coef(lp, 2, 1); + + glp_set_obj_coef(lp, 3, 10.0); + glp_set_obj_coef(lp, 4, 10.0); + + // glp_set_obj_coef(lp, 5, 1.0); + // glp_set_obj_coef(lp, 6, 10.0); + + // glp_set_obj_coef(lp, 11, 1.0); + + //example1 two batch place +// glp_set_obj_coef(lp, 1, 1.0); +// glp_set_obj_coef(lp, 3, 10.0); +// glp_set_obj_coef(lp, 2, 1.0); +// glp_set_obj_coef(lp, 4, 10.0); + +// glp_set_obj_coef(lp, 5, 10.0); +// glp_set_obj_coef(lp, 6, 1.0); + + // glp_set_obj_coef(lp, 7, 1.0); + // glp_set_obj_coef(lp, 9, 1.0); +// glp_set_obj_coef(lp, 1, 1.0); +// glp_set_obj_coef(lp, 3, 10.0); +// glp_set_obj_coef(lp, 8, 1.0); +// glp_set_obj_coef(lp, 10, 3.0); + +//wodes+tz1+tz2 +//glp_set_obj_coef(lp, 10, 10.0); +//glp_set_obj_coef(lp, 11, 1.0); +//glp_set_obj_coef(lp, 4, 5.0); + + + + for (int k=beginofcbt; k<endofcbt; k++) { + glp_set_obj_coef(lp, k+1, 1.0); // set (change) objective coefficient or constant term + glp_set_col_name(lp, k+1, transitions[k-numberofcontandbatchplaces]->GetName()); // name of the transition + f = transitions[k-numberofcontandbatchplaces]->GetFlow(); + if (f->GetMaximumFlow() != 0.0) + glp_set_col_bnds(lp, k+1, GLP_DB, 0.0, f->GetMaximumFlow());//set (change) column bounds + else + glp_set_col_bnds(lp, k+1, GLP_FX, 0.0, 0.0); + + cout << transitions[k-numberofcontandbatchplaces]->GetName() << " : 0.0 - " << f->GetMaximumFlow() << endl; + } + + // initialising quantities bound + cout << "\nQuantities bound\n\n"; + for (int k=beginofcbp; k<endofcbp; k++) { + capacity = ((BatchPlace*)places[k])->GetDensity()*((BatchPlace*)places[k])->GetLength(); + // glp_set_obj_coef(lp, k+1, 0.0); // set (change) objective coefficient or constant term + glp_set_col_name(lp, k+1, places[k]->GetName()); // name of the transition + switch (places[k] ->IsA()){ + case Batch_pl: if (capacity != 0.0){ + glp_set_col_bnds(lp, k+1, GLP_DB, 0.0, capacity); + } + else{ + glp_set_col_bnds(lp, k+1, GLP_FX, 0.0, 0.0); + } + cout << places[k]->GetName() << " : 0.0 - " << capacity<<"\n"; + continue; + + break; + + case Continuous_pl: capacity = ((BatchPlace*)places[k+numberofcontinuousplaces])->GetDensity()*((BatchPlace*)places[k+numberofcontinuousplaces])->GetLength(); + glp_set_col_bnds(lp, k+1, GLP_DB, 0.0, capacity); //maybe revised! + cout << places[k]->GetName() << " : 0.0 - "<<capacity<<"\n"; + continue; + break; + } + } + + cout << "\nMinimal firing quantities bound\n\n"; + for (int k=beginofft; k<endofft; k++) { + glp_set_obj_coef(lp, k+1, 1.0e-6); // set (change) objective coefficient or constant term + glp_set_col_name(lp, k+1, transitions[k-numberofcontandbatchplaces-numberofcontandbatchtransitions]->GetName()); // name of the transition + f = transitions[k-numberofcontandbatchplaces-numberofcontandbatchtransitions]->GetFlow(); + if (f->GetMaximumFlow() != 0.0) + glp_set_col_bnds(lp, k+1, GLP_LO, 0.0, 0.0);//set (change) column bounds + else + glp_set_col_bnds(lp, k+1, GLP_FX, 0.0, 0.0); + + cout << transitions[k-numberofcontandbatchplaces-numberofcontandbatchtransitions]->GetName() << " z: >= " << 0.0 << endl; + } + + r = 1; + arindex = 1; + + + cout << "\nStart contraints\n\n"; + // constraint a + cout << "Contraint a\n"; + for (int i=1, k=beginofcbt; k<endofcbt; k++, i++) { + sprintf(rname, "a.%d", i); + f = transitions[k-numberofcontandbatchplaces]->GetFlow(); + glp_set_row_name(lp, r, rname); + if (f->GetMaximumFlow() != 0.0) + glp_set_row_bnds(lp, r, GLP_DB, 0.0, f->GetMaximumFlow()); //compare with steadyflow + else + glp_set_row_bnds(lp, r, GLP_FX, 0.0, 0.0); + + ia[arindex] = r; + ja[arindex] = k+1; + ar[arindex] = 1.0; // weigth + arindex++; + r++; + cout << rname << " : " << "0.0 <= y <= " << f->GetMaximumFlow() << endl; + } + + // constraint b +// cout << "Contraint b\n"; +// for (int i=1, k=beginofbp; k<endofbp; k++, i++) { +// sprintf(rname, "b.%d", i); +// capacity= ((BatchPlace*)places[k])->GetDensity() * ((BatchPlace*)places[k])->GetLength(); +// glp_set_row_name(lp, r, rname); +// if (capacity != 0.0 ){ +// glp_set_row_bnds(lp, r, GLP_DB, 0.0, capacity); +// } +// else{ +// glp_set_row_bnds(lp, r, GLP_FX, 0.0, 0.0); +// } +// ia[arindex] = r; +// ja[arindex] = k+1; +// ar[arindex] = 1.0; // weigth +// arindex++; +// r++; +// cout << rname << " : " << " 0.0 <= "<< " q" <<ja[arindex-1] << " <= "<<capacity << endl; +// } + + // constraint b' // q_i + cout << "Contraint b\n"; + for (int i=1, k=beginofbp; k<endofbp; k++, i++) { + sprintf(rname, "b.%d", i); + glp_set_row_name(lp, r, rname); + glp_set_row_bnds(lp, r, GLP_UP, 0.0, 0.0); + + ia[arindex] = r; + ja[arindex] = k+1; + ar[arindex] = 1.0 ; + arindex++; + + for (int j=0; j<NumberOfTransitions(); j++) { + V[j] = 0.0; + } + for (int j=0; j<NumberOfTransitions(); j++){ + if (places[k]->GetWeightOfOutputArc(j) != 0.0 ){ + V[j] = places[k]->GetWeightOfOutputArc(j); + } + } + cout << rname << " : " << "q" <<k+1; + + + for (int j=0, l=beginofcbt; l<endofcbt; j++, l++) { + if (V[j] != 0.0){ + ia[arindex] = r; + ja[arindex] = l+1; + ar[arindex] = -V[j] * ((BatchPlace*)places[k])->GetLength() / ((BatchPlace*)places[k])->GetInstantaneousSpeed() ; + arindex++; + cout << ar[arindex-1]<<"y * " <<j+1; + } + } + cout << "<=0.0" <<endl; + r++; +} + + // Contraint c + cout << "Contraint c\n"; + for (int i=1, k=beginofbp; k<endofbp; k++, i++) { + maxflow = ((BatchPlace*)places[k])->GetInstantaneousSpeed() * ((BatchPlace*)places[k])->GetDensity(); + + sprintf(rname, "c.%d", i); + glp_set_row_name(lp, r, rname); + glp_set_row_bnds(lp, r, GLP_UP, 0.0, maxflow); + + for (int j=0; j<NumberOfTransitions(); j++) { + V[j] = 0.0; + } + for (int j=0; j<NumberOfTransitions(); j++){ + if (places[k]->GetWeightOfInputArc(j) != 0.0 ){ + V[j] = places[k]->GetWeightOfInputArc(j); + } + } + cout << rname << " : "; + for (int j=0, l=beginofcbt; l<endofcbt; j++, l++) { + if (V[j] != 0.0){ + ia[arindex] = r; + ja[arindex] = l+1; + ar[arindex] = V[j]; + arindex++; + cout << "y"<<j+1 << "(" << V[j] << ") + "; + } + } + cout << "<=" << maxflow << endl; + r++; + } + + // constraint d + + cout << "Contraint d\n"; + + for (int i=1, k=beginofcbp; k<endofcbp; k++, i++) { + + sprintf(rname, "d.%d", i); + glp_set_row_name(lp, r, rname); + glp_set_row_bnds(lp, r, GLP_FX, 0.0, 0.0); //look after + for (int j=0; j<NumberOfTransitions(); j++) { + V[j] = 0.0; + } + cout << rname<< ":"; + for (int j=0; j<NumberOfTransitions(); j++){ + if (places[k]->GetWeightOfOutputArc(j) != 0.0 ){ + V[j] = - places[k]->GetWeightOfOutputArc(j); + // cout << " - V [" << j << "] " ; + } + if (places[k]->GetWeightOfInputArc(j) != 0.0 ){ + // cout << " + V [" << j << "] " ; + V[j] += places[k]->GetWeightOfInputArc(j); + } + cout << "y"<<j+1 << "(" << V[j] << ") + "; + } + + for (int j=0, l=beginofcbt; l<endofcbt; j++, l++) { + if (V[j] != 0.0){ + ia[arindex] = r; + ja[arindex] = l+1; + ar[arindex] = V[j]; + arindex++; + + } + } + cout << " = 0.0" << endl; + r++; + } + + + //constraint e + cout << "Contraint e\n"; + for (int i=1, k=beginofcbp; k<endofcbp; k++, i++) { + switch (places[k] ->IsA()){ + case Continuous_pl: quantity_initial =((ContinuousPlace*)places[k])->GetMarks(); + break; + case Batch_pl:quantity_initial= ((BatchPlace*)places[k])->GetInitialQuantity(); + break; + } + sprintf(rname, "e.%d", i); + glp_set_row_name(lp, r, rname); + glp_set_row_bnds(lp, r, GLP_FX, quantity_initial, quantity_initial); + + ia[arindex] = r; + ja[arindex] = k+1; + ar[arindex] = 1.0; // weight + arindex++; + cout << rname<< " : "<<"q"<<k+1; + for (int j=0; j<NumberOfTransitions(); j++) { + V[j] = 0.0; + } + + for (int j=0; j<NumberOfTransitions(); j++){ + if (places[k]->GetWeightOfOutputArc(j) != 0.0 ){ + V[j] = - places[k]->GetWeightOfOutputArc(j); + // cout << " - V [" << j << "] " ; + } + if (places[k]->GetWeightOfInputArc(j) != 0.0 ){ + // cout << " + V [" << j << "] " ; + V[j] += places[k]->GetWeightOfInputArc(j); + } + cout << "+z"<<j+1 << "(" << V[j] << ") "; + } + + for (int j=0, l=beginofft; l<endofft; j++, l++) { + if (V[j] != 0.0){ + ia[arindex] = r; + ja[arindex] = l+1; + ar[arindex] = -V[j]; + arindex++; + // cout << j << "(" << V[j] << ") - "; + } + } + cout << "=" <<quantity_initial<< endl; + r++; + } + + + glp_term_out(GLP_OFF); + glp_load_matrix(lp, arindex-1, ia, ja, ar); + glp_simplex(lp, NULL); + + cout<<"\nThe steady state is : "<<endl; + z = glp_get_obj_val(lp); + + + + for (int i=1;i<(numberofcontandbatchplaces+2*numberofcontandbatchtransitions+1); i++){ + SS[i]=glp_get_col_prim(lp, i); + //SS = calloc(1+numberofcontandbatchplaces+2*numberofcontandbatchtransitions, sizeof(double)); + } + + for (int i=1;i<(numberofcontandbatchplaces+2*numberofcontandbatchtransitions+1); i++){ + printf("z=%lf,SS[i]=%lf\n",z,i, SS[i]); + // if (i< (numberofcontandbatchplaces+1)){ + +// if (i< (numberofcontandbatchplaces+numberofcontinuoustransitions+1 && i > numberofcontandbatchplaces)){ +// f = ((ContinuousTransition*)transitions[i+numberofcontandbatchplaces-1])->GetFlow(); +// f->SetTheoreticalFlow(SS[i+numberofcontandbatchplaces]); +// f->SetCurrentFlow(SS[i+numberofcontandbatchplaces]); +// } + } + + // f = ((ContinuousTransition*)transitions[k-numberofcontandbatchplaces])->GetFlow(); + // f->SetTheoreticalFlow(SS[k]); + // f->SetCurrentFlow(SS[k]); + + // cout << transitions[k-numberofcontandbatchplaces]->GetName() << " : " << SS[i] << endl; + + int col[numberofcontandbatchplaces+2*numberofcontandbatchtransitions]; + double val[numberofcontandbatchplaces+2*numberofcontandbatchtransitions]; + + /* + for (int i=1; i<=glp_get_num_rows(lp); i++){ + cout << glp_get_row_name(lp, i) << " : "; + for (int j=1; j<=glp_get_mat_row(lp, i, col, val); j++){ + cout << col[j] << "(" << val[j] << ") - "; + } + cout << glp_get_row_lb(lp, i) << " - " << glp_get_row_ub(lp, i) << endl; + } + */ + glp_delete_prob(lp); + return 0; + +}//======================== + + + + + +//==========================Maximal flow based On/OFF control================== +// Compute the controlled firing flow based on maximal flow (MCFF) +//============================================================================== +void BPN::ComputeMCFF() +{ + cout << "\nCompute MCFF\n\n"; + + Flow *u; + double steadyflow; + double maxflow; // maximal outflow of a batch place which depends on the density of output batch and the tranfer speed. + double maxinputflow; //maximal input flow of a batch place which is the product of density and maximal transfer speed. + + + // contraints a + int beginofcbt = numberofdiscretetransitions; + int endofcbt = numberofdiscretetransitions + numberofcontinuoustransitions + numberofbatchtransitions; + int numberofcontandbatchtransitions = numberofcontinuoustransitions + numberofbatchtransitions; + + //constraints b =====>T_z + int numberofcontandbatchtransitionsthatbelongstotz = 0; + for (int i = beginofcbt; i<endofcbt; i++){ + if (transitions[i]->IsFiringQuantityOnState() == 0){ + numberofcontandbatchtransitionsthatbelongstotz++; //T_z + } + } + + //Verifiy if all transitions belong to tz. +// if (numberofcontandbatchtransitionsthatbelongstotz == numberofcontandbatchtransitions ){ +// cout<< "T_z is full\n"; +// } + + if (numberofcontandbatchtransitions == 0) // no need to compute MCFF + return; + + //constraints c ==> constraints c are not enabled transition set and T_ZL. + // int numberofnotenabledcontandbatchtransitions = 0; + int numberofnotenabledorlesssteadyandbelongstofiringquantityofcontandbatchtransitions = 0; + for (int i=beginofcbt; i<endofcbt; i++){ + // if (transitions[i]->GetState() == 0.0 ){ + // numberofnotenabledcontandbatchtransitions++; + // } + if ((transitions[i]->GetState() == 0.0) || ((transitions[i]->IsFiringQuantityOnState() == 0) && (transitions[i]->IsOnState() == 0))){ + numberofnotenabledorlesssteadyandbelongstofiringquantityofcontandbatchtransitions++; //the cardinality of T_ZL + T_N + } + } + + + //constraints d ==> full batch place + int beginofbp = numberofdiscreteplaces + numberofcontinuousplaces; + int endofbp = numberofdiscreteplaces + numberofcontinuousplaces + numberofbatchplaces; + int numberofcontandbatchplaces = numberofcontinuousplaces + numberofbatchplaces; + int numberoffullbatchplaces = 0; + for (int i=beginofbp; i<endofbp; i++){ + if (((BatchPlace*)places[i])->IsFull() == 1){ + numberoffullbatchplaces++; + } + } + + //constraints e ==> empty continuous places + int beginofcp = numberofdiscreteplaces; + int endofcp = numberofdiscreteplaces + numberofcontinuousplaces; + int numberofemptycontinuousplaces = 0; + for (int i=beginofcp; i<endofcp; i++){ + if (((ContinuousPlace*)places[i])->GetMarks() == 0.0 ){ + numberofemptycontinuousplaces++; + } + } + + + + +//constraints f ==> continuous and batch place whose marking quantity is equal to steady marking quantity (S_E) + // and its input and output transition belongs to T_Z. + +// int beginofcbp = numberofdiscreteplaces; +// int endofcbp = numberofdiscreteplaces + numberofcontinuousplaces + numberofbatchplaces; +// int numberofequalcontandbatchplacesanditsinputoutputtransitionbelongstotz = 0; +// +// for (int i=beginofcbp; i<endofcbp; i++){ +// int numberofinputandoutputtransitions = 0; +// int numberofinputandoutputransitionsthatbelongstotz = 0; +// switch (places[i] ->IsA()){ +// case Continuous_pl: +// if (((ContinuousPlace*)places[i])->IsEqualSteadyQuantity() == 1){ +// for (int j=0; j<NumberOfTransitions(); j++) { +// V[j] = 0.0; +// } +// for (int j=0; j<NumberOfTransitions(); j++){ +// if (places[i]->GetWeightOfOutputArc(j) != 0.0 ){ +// V[j] = - places[i]->GetWeightOfOutputArc(j); +// } +// if (places[i]->GetWeightOfInputArc(j) != 0.0 ){ +// V[j] += places[i]->GetWeightOfInputArc(j); +// } +// if (V[j] !=0 ){ +// numberofinputandoutputtransitions++; // no self loop net +// } +// if (V[j] !=0 && transitions[j]->IsFiringQuantityOnState() == 0){ +// numberofinputandoutputransitionsthatbelongstotz++; +// } +// } +// if (numberofinputandoutputtransitions == numberofinputandoutputransitionsthatbelongstotz){ +// numberofequalcontandbatchplacesanditsinputoutputtransitionbelongstotz++; +// } +// } +// break; +// case Batch_pl: +// if (((BatchPlace*)places[i])->IsEqualSteadyQuantity() == 1){ +// for (int j=0; j<NumberOfTransitions(); j++) { +// V[j] = 0.0; +// } +// for (int j=0; j<NumberOfTransitions(); j++){ +// if (places[i]->GetWeightOfOutputArc(j) != 0.0 ){ +// V[j] = - places[i]->GetWeightOfOutputArc(j); +// } +// if (places[i]->GetWeightOfInputArc(j) != 0.0 ){ +// V[j] += places[i]->GetWeightOfInputArc(j); +// } +// if (V[j] !=0 ){ +// numberofinputandoutputtransitions++; // no self loop net +// } +// if (V[j] !=0 && transitions[j]->IsFiringQuantityOnState() == 0){ +// numberofinputandoutputransitionsthatbelongstotz++; +// } +// } +// if (numberofinputandoutputtransitions == numberofinputandoutputransitionsthatbelongstotz){ +// numberofequalcontandbatchplacesanditsinputoutputtransitionbelongstotz++; +// } +// } +// break; +// } +// } + + +//constraint f + int beginofcbp = numberofdiscreteplaces; + int endofcbp = numberofdiscreteplaces + numberofcontinuousplaces + numberofbatchplaces; + int numberofequalcontandbatchplacesanditsinputoutputtransitionbelongstotz = 0; + + for (int i=beginofcbp; i<endofcbp; i++){ + switch (places[i] ->IsA()){ + case Continuous_pl: + if (((ContinuousPlace*)places[i])->IsSteadyMarkingReachedandInputOutputTransitionBelongTz() == 1){ + numberofequalcontandbatchplacesanditsinputoutputtransitionbelongstotz++; + } + break; + case Batch_pl: + if (((BatchPlace*)places[i])->IsSteadyMarkingQuantityReachedandInputOutputTransitionBelongTz() == 1){ + numberofequalcontandbatchplacesanditsinputoutputtransitionbelongstotz++; + } + break; + } + } + + //constraints g and h. + + + + int nc = 0; // total of contraints + int r = 0; // current contraint + char rname[256]; // row name + + double V[NumberOfTransitions()]; // used to compute the incidence matrix, only continuous and batch positions are used + + + // variables to the linear program + glp_prob *lp; + double MCFF[numberofcontandbatchtransitions]; // to store the result of the linear program + + nc = numberofcontandbatchtransitions; // contraint a + nc+= numberofcontandbatchtransitionsthatbelongstotz; //constraint b + nc+= numberofnotenabledorlesssteadyandbelongstofiringquantityofcontandbatchtransitions; //constraint c + nc+= numberoffullbatchplaces;//constraint d + nc+= numberofemptycontinuousplaces; // constraint e + nc+= numberofequalcontandbatchplacesanditsinputoutputtransitionbelongstotz; //constaint f + nc+= numberofbatchplaces; //constaint g + nc+= numberofbatchplaces; //constaint h + + + // contraints matrix + int ia[nc * numberofcontandbatchtransitions]; + int ja[nc * numberofcontandbatchtransitions]; + double ar[nc * numberofcontandbatchtransitions]; + int arindex; + + + // initialising linear program + lp = glp_create_prob(); + glp_set_prob_name(lp, "MCFF"); + glp_set_obj_dir(lp, GLP_MAX); + glp_add_cols(lp, numberofcontandbatchtransitions); + glp_add_rows(lp, nc); + + // initialising transitions bound + cout << "\nTransitions bound\n\n"; + for (int i=1, k=beginofcbt; k<endofcbt; k++, i++) { + glp_set_obj_coef(lp, i, 1.0); // set (change) objective coefficient or constant term + glp_set_col_name(lp, i, transitions[k]->GetName()); // name of the transition + u = transitions[k]->GetFlow(); + if (u->GetMaximumFlow() != 0.0) + glp_set_col_bnds(lp, i, GLP_DB, 0.0, u->GetMaximumFlow());//set (change) column bounds + else + glp_set_col_bnds(lp, i, GLP_FX, 0.0, 0.0); + + cout << transitions[k]->GetName() << " : 0.0 - " << u->GetMaximumFlow() << endl; + } + + + r = 1; + arindex = 1; + + cout << "\nStart contraints\n\n"; + + // constraint a + cout << "Contraint a\n"; + for (int i=1, k=beginofcbt; k<endofcbt; k++, i++) { + sprintf(rname, "a.%d", i); + u = transitions[k]->GetFlow(); + glp_set_row_name(lp, r, rname); + if (u->GetMaximumFlow() != 0.0) + glp_set_row_bnds(lp, r, GLP_DB, 0.0, u->GetMaximumFlow()); //compare with steadyflow + else + glp_set_row_bnds(lp, r, GLP_FX, 0.0, 0.0); + + ia[arindex] = r; + ja[arindex] = i; + ar[arindex] = 1.0; // weight + arindex++; + r++; + cout << rname << " : " << "0.0 <= x <= " << u->GetMaximumFlow() << endl; + } + + + // constraint b T_Z + cout << "Contraint b\n"; + for (int i=1, k=beginofcbt; k<endofcbt; k++, i++) { + if (transitions[k]->IsFiringQuantityOnState() == 0){ + sprintf(rname, "b.%d", i); + u = transitions[k]->GetFlow(); + glp_set_row_name(lp, r, rname); + + if (u->GetSteadyFlow() != 0.0) + glp_set_row_bnds(lp, r, GLP_DB, 0.0, u->GetSteadyFlow()); //compare with steadyflow + else + glp_set_row_bnds(lp, r, GLP_FX, 0.0, 0.0); + + + ia[arindex] = r; + ja[arindex] = i; + ar[arindex] = 1.0; // weigth + arindex++; + r++; + + cout << rname << " : " << "0.0 <= x <= " << u->GetSteadyFlow() << endl; + } + } + + //constraint c not enabled and T_ZL set into zero. + cout << "Contraint c\n"; + for (int i=1, k=beginofcbt; k<endofcbt; k++, i++){ + if (transitions[k]->GetState() == 0.0 || + ((transitions[k]->IsFiringQuantityOnState() == 0 ) && + (transitions[k]->IsOnState() ==0))){ + sprintf(rname, "c.%d", i); + glp_set_row_name(lp, r, rname); + glp_set_row_bnds(lp, r, GLP_FX, 0.0, 0.0); + + ia[arindex] = r; + ja[arindex] = i; + ar[arindex] = 1.0; // weight + arindex++; + r++; + cout << rname << " : " << ja[arindex-1] << ": 0.0 = x = 0.0 " << endl; + } + } + + // constraint d Full batch places + cout << "Contraint d\n"; + for (int i=1, k=beginofbp; k<endofbp; k++, i++) { + if (((BatchPlace*)places[k])->IsFull() == 1){ + sprintf(rname, "d.%d", i); + glp_set_row_name(lp, r, rname); + glp_set_row_bnds(lp, r, GLP_UP, 0.0, 0.0); //check after + for (int j=0; j<NumberOfTransitions(); j++) { + V[j] = 0.0; + } + + for (int j=0; j<NumberOfTransitions(); j++){ + if (places[k]->GetWeightOfOutputArc(j) != 0.0 ){ + V[j] = - places[k]->GetWeightOfOutputArc(j); + cout << " - V [" << j << "] " ; + } + if (places[k]->GetWeightOfInputArc(j) != 0.0 ){ + cout << " + V [" << j << "] " ; + V[j] += places[k]->GetWeightOfInputArc(j); + } + } + cout << endl; + cout << rname << " : "; + for (int j=1, l=beginofcbt; l<endofcbt; j++, l++) { + if (V[l] != 0.0){ + ia[arindex] = r; + ja[arindex] = j; + ar[arindex] = V[l]; + arindex++; + cout << j << "(" << V[l] << ") - "; + } + } + cout << " <= 0.0" << endl; + r++; + } + } + + // constraint e Empty continuous place + cout << "Contraint e\n"; + for (int i=1, k=beginofcp; k<endofcp; k++, i++) { + if (((ContinuousPlace*)places[k])->GetMarks() == 0.0){ + sprintf(rname, "d.%d", i); + glp_set_row_name(lp, r, rname); + glp_set_row_bnds(lp, r, GLP_LO, 0.0, 0.0); //check after + for (int j=0; j<NumberOfTransitions(); j++) { + V[j] = 0.0; + } + + for (int j=0; j<NumberOfTransitions(); j++){ + if (places[k]->GetWeightOfOutputArc(j) != 0.0 ){ + V[j] = - places[k]->GetWeightOfOutputArc(j); + cout << " - V [" << j << "] " ; + } + if (places[k]->GetWeightOfInputArc(j) != 0.0 ){ + cout << " + V [" << j << "] " ; + V[j] += places[k]->GetWeightOfInputArc(j); + } + } + cout << endl; + cout << rname << " : "; + for (int j=1, l=beginofcbt; l<endofcbt; j++, l++) { + if (V[l] != 0.0){ + ia[arindex] = r; + ja[arindex] = j; + ar[arindex] = V[l]; + arindex++; + cout << j << "(" << V[l] << ") - "; + } + } + cout << " >= 0.0" << endl; + r++; + } + } + + + //constraint f + cout << "Contraint f\n"; + + for (int i=1, k=beginofcbp; k<endofcbp; k++, i++){ + switch (places[k] ->IsA()){ + case Continuous_pl: + if (((ContinuousPlace*)places[k])->IsSteadyMarkingReachedandInputOutputTransitionBelongTz() == 0) + continue; + break; + case Batch_pl: + if (((BatchPlace*)places[k])->IsSteadyMarkingQuantityReachedandInputOutputTransitionBelongTz() == 0) + continue; + break; + } + +//--------------------------------------------------------------------------- +// for (int i=1, k=beginofcbp; k<endofcbp; k++, i++){ +// int numberofinputandoutputtransitions=0; +// int numberofinputandoutputransitionsthatbelongstotz = 0; +// switch (places[k] ->IsA()){ +// case Continuous_pl: +// if (((ContinuousPlace*)places[k])->IsEqualSteadyQuantity() == 1){ +// for (int j=0; j<NumberOfTransitions(); j++) { +// V[j] = 0.0; +// } +// for (int j=0; j<NumberOfTransitions(); j++){ +// if (places[k]->GetWeightOfOutputArc(j) != 0.0 ){ +// V[j] = - places[k]->GetWeightOfOutputArc(j); +// } +// if (places[k]->GetWeightOfInputArc(j) != 0.0 ){ +// V[j] += places[k]->GetWeightOfInputArc(j); +// } +// if (V[j] !=0 ){ +// numberofinputandoutputtransitions++; // no self loop net +// } +// if (V[j] !=0 && transitions[j]->IsFiringQuantityOnState() == 0){ +// numberofinputandoutputransitionsthatbelongstotz++; +// } +// } +// if (numberofinputandoutputtransitions == numberofinputandoutputransitionsthatbelongstotz){ +// continue; +// } +// } +// break; +// +// case Batch_pl: +// if (((BatchPlace*)places[k])->IsEqualSteadyQuantity() == 1){ +// for (int j=0; j<NumberOfTransitions(); j++) { +// V[j] = 0.0; +// } +// for (int j=0; j<NumberOfTransitions(); j++){ +// if (places[i]->GetWeightOfOutputArc(j) != 0.0 ){ +// V[j] = - places[k]->GetWeightOfOutputArc(j); +// } +// if (places[i]->GetWeightOfInputArc(j) != 0.0 ){ +// V[j] += places[k]->GetWeightOfInputArc(j); +// } +// if (V[j] !=0 ){ +// numberofinputandoutputtransitions++; // no self loop net +// } +// if (V[j] !=0 && transitions[j]->IsFiringQuantityOnState() == 0){ +// numberofinputandoutputransitionsthatbelongstotz++; +// } +// } +// if (numberofinputandoutputtransitions == numberofinputandoutputransitionsthatbelongstotz) +// continue; +// } +// break; +// } +//------------------------------------------------------------------------------- + sprintf(rname, "f.%d", i); + glp_set_row_name(lp, r, rname); + glp_set_row_bnds(lp, r, GLP_FX, 0.0, 0.0); + for (int j=0; j<NumberOfTransitions(); j++) { + V[j] = 0.0; + } + + for (int j=0; j<NumberOfTransitions(); j++){ + if (places[k]->GetWeightOfOutputArc(j) != 0.0 ){ + V[j] = - places[k]->GetWeightOfOutputArc(j); + cout << " - V [" << j << "] " ; + } + if (places[k]->GetWeightOfInputArc(j) != 0.0 ){ + cout << " + V [" << j << "] " ; + V[j] += places[k]->GetWeightOfInputArc(j); + } + } + cout << endl; + cout << rname << " : "; + for (int j=1, l=beginofcbt; l<endofcbt; j++, l++) { + if (V[l] != 0.0){ + ia[arindex] = r; + ja[arindex] = j; + ar[arindex] = V[l]; + arindex++; + cout << j << "(" << V[l] << ") - "; + } + } + cout << " = 0.0" << endl; + r++; + } + + //constraint g + cout << "Contraint g\n"; + for (int i=1, k=beginofbp; k<endofbp; k++, i++){ + maxinputflow = ((BatchPlace*)places[k])->GetMaxSpeed() * ((BatchPlace*)places[k])->GetDensity(); + sprintf(rname, "g.%d", i); + glp_set_row_name(lp, r, rname); + glp_set_row_bnds(lp, r, GLP_UP, 0.0, maxinputflow); + + for (int j=0; j<NumberOfTransitions(); j++) { + V[j] = 0.0; + } + for (int j=0; j<NumberOfTransitions(); j++){ + if (places[k]->GetWeightOfInputArc(j) != 0.0 ){ + V[j] = places[k]->GetWeightOfInputArc(j); + } + } + cout << rname << " : "; + for (int j=1, l=beginofcbt; l<endofcbt; j++, l++) { + if (V[l] != 0.0){ + ia[arindex] = r; + ja[arindex] = j; + ar[arindex] = V[l]; + arindex++; + cout << j << "(" << V[l] << ") - "; + } + } + cout << "0.0 <= x <= " << maxinputflow << endl; + r++; + } + + // constraint h + cout << "Contraint h\n"; + + for (int i=1, k=beginofbp; k<endofbp; k++, i++) { + maxflow = ((BatchPlace*)places[k])->GetMaxSpeed() * ((BatchPlace*)places[k])->GetDensityOutputBatch(); + sprintf(rname, "h.%d", i); + glp_set_row_name(lp, r, rname); + if (maxflow != 0.0) + glp_set_row_bnds(lp, r, GLP_UP, 0.0, maxflow); + else + glp_set_row_bnds(lp, r, GLP_FX, 0.0, 0.0); + + for (int j=0; j<NumberOfTransitions(); j++) { + V[j] = 0.0; + } + for (int j=0; j<NumberOfTransitions(); j++){ + if (places[k]->GetWeightOfOutputArc(j) != 0.0 ){ + V[j] = places[k]->GetWeightOfOutputArc(j); + } + } + cout << rname << " : "; + for (int j=1, l=beginofcbt; l<endofcbt; j++, l++) { + if (V[l] != 0.0){ + ia[arindex] = r; + ja[arindex] = j; + ar[arindex] = V[l]; + arindex++; + cout << j << "(" << V[l] << ") - "; + } + } + cout << "0.0 <= x <= " << maxflow << endl; + r++; +} + + glp_term_out(GLP_OFF); + glp_load_matrix(lp, arindex-1, ia, ja, ar); + glp_simplex(lp, NULL); + + for (int i=0, k=beginofcbt; k<endofcbt; k++, i++) { + MCFF[i] = glp_get_col_prim(lp, (i+1)); + u = transitions[k]->GetFlow(); //???continuous transition class? + u->SetTheoreticalFlow(MCFF[i]); + u->SetCurrentFlow(MCFF[i]); + + // cout << transitions[k]->GetName() << " : " << MCFF[i] << endl; + } + + int col[numberofcontandbatchtransitions]; + double val[numberofcontandbatchtransitions]; + +// for (int i=1; i<=glp_get_num_rows(lp); i++){ +// cout << glp_get_row_name(lp, i) << " : "; +// for (int j=1; j<=glp_get_mat_row(lp, i, col, val); j++){ +// cout << col[j] << "(" << val[j] << ") - "; +// } +// cout << glp_get_row_lb(lp, i) << " - " << glp_get_row_ub(lp, i) << endl; +// } + + glp_delete_prob(lp); +////======================================================================= +} + + + +void BPN::ComputeMSCFF() +{ + cout << "\nCompute MCFF\n\n"; + + Flow *u; + double steadyflow; + double maxflow; // maximal outflow of a batch place which depends on the density of output batch and the tranfer speed. + double maxinputflow; //maximal input flow of a batch place which is the product of density and maximal transfer speed. + + + // contraints a + int beginofcbt = numberofdiscretetransitions; + int endofcbt = numberofdiscretetransitions + numberofcontinuoustransitions + numberofbatchtransitions; + int numberofcontandbatchtransitions = numberofcontinuoustransitions + numberofbatchtransitions; + + //constraints b =====>T_z + int numberofcontandbatchtransitionsthatbelongstotz = 0; + for (int i = beginofcbt; i<endofcbt; i++){ + if (transitions[i]->IsFiringQuantityOnState() == 0){ + numberofcontandbatchtransitionsthatbelongstotz++; //T_z + } + } + + if (numberofcontandbatchtransitions == 0) // no need to compute MCFF + return; + + //constraints c ==> constraints c are not enabled transition set and T_ZL. +// int numberofnotenabledcontandbatchtransitions = 0; + int numberofnotenabledorlesssteadyandbelongstofiringquantityofcontandbatchtransitions = 0; + for (int i=beginofcbt; i<endofcbt; i++){ + // if (transitions[i]->GetState() == 0.0 ){ + // numberofnotenabledcontandbatchtransitions++; + // } + if ((transitions[i]->GetState() == 0.0) || ((transitions[i]->IsFiringQuantityOnState() == 0) && (transitions[i]->IsOnState() == 0))){ + numberofnotenabledorlesssteadyandbelongstofiringquantityofcontandbatchtransitions++; //the cardinality of T_ZL + T_N + } + } + + + //constraints d ==> full batch place + int beginofbp = numberofdiscreteplaces + numberofcontinuousplaces; + int endofbp = numberofdiscreteplaces + numberofcontinuousplaces + numberofbatchplaces; + int numberofcontandbatchplaces = numberofcontinuousplaces + numberofbatchplaces; + int numberoffullbatchplaces = 0; + for (int i=beginofbp; i<endofbp; i++){ + if (((BatchPlace*)places[i])->IsFull() == 1){ + numberoffullbatchplaces++; + } + } + + //constraints e ==> empty continuous places + int beginofcp = numberofdiscreteplaces; + int endofcp = numberofdiscreteplaces + numberofcontinuousplaces; + int numberofemptycontinuousplaces = 0; + for (int i=beginofcp; i<endofcp; i++){ + if (((ContinuousPlace*)places[i])->GetMarks() == 0.0 ){ + numberofemptycontinuousplaces++; + } + } + + + + +//constraints f ==> continuous and batch place whose marking quantity is equal to steady marking quantity (S_E) + // and its input and output transition belongs to T_Z. + + +//constraints f //// 09/04 last version +// int beginofcbp = numberofdiscreteplaces; +// int endofcbp = numberofdiscreteplaces + numberofcontinuousplaces + numberofbatchplaces; +// int numberofequalcontandbatchplacesanditsinputoutputtransitionbelongstotz = 0; +// +// for (int i=beginofcbp; i<endofcbp; i++){ +// int numberofinputandoutputtransitions = 0; +// int numberofinputandoutputransitionsthatbelongstotz = 0; +// switch (places[i] ->IsA()){ +// case Continuous_pl: +// if (((ContinuousPlace*)places[i])->IsEqualSteadyQuantity() == 1){ +// for (int j=0; j<NumberOfTransitions(); j++) { +// V[j] = 0.0; +// } +// for (int j=0; j<NumberOfTransitions(); j++){ +// if (places[i]->GetWeightOfOutputArc(j) != 0.0 ){ +// V[j] = - places[i]->GetWeightOfOutputArc(j); +// } +// if (places[i]->GetWeightOfInputArc(j) != 0.0 ){ +// V[j] += places[i]->GetWeightOfInputArc(j); +// } +// if (V[j] !=0 ){ +// numberofinputandoutputtransitions++; // no self loop net +// } +// if (V[j] !=0 && transitions[j]->IsFiringQuantityOnState() == 0){ +// numberofinputandoutputransitionsthatbelongstotz++; +// } +// } +// if (numberofinputandoutputtransitions == numberofinputandoutputransitionsthatbelongstotz){ +// numberofequalcontandbatchplacesanditsinputoutputtransitionbelongstotz++; +// } +// } +// break; +// case Batch_pl: +// if (((BatchPlace*)places[i])->IsEqualSteadyQuantity() == 1){ +// for (int j=0; j<NumberOfTransitions(); j++) { +// V[j] = 0.0; +// } +// for (int j=0; j<NumberOfTransitions(); j++){ +// if (places[i]->GetWeightOfOutputArc(j) != 0.0 ){ +// V[j] = - places[i]->GetWeightOfOutputArc(j); +// } +// if (places[i]->GetWeightOfInputArc(j) != 0.0 ){ +// V[j] += places[i]->GetWeightOfInputArc(j); +// } +// if (V[j] !=0 ){ +// numberofinputandoutputtransitions++; // no self loop net +// } +// if (V[j] !=0 && transitions[j]->IsFiringQuantityOnState() == 0){ +// numberofinputandoutputransitionsthatbelongstotz++; +// } +// } +// if (numberofinputandoutputtransitions == numberofinputandoutputransitionsthatbelongstotz){ +// numberofequalcontandbatchplacesanditsinputoutputtransitionbelongstotz++; +// } +// } +// break; +// } +// } + + +//constraint f + int beginofcbp = numberofdiscreteplaces; + int endofcbp = numberofdiscreteplaces + numberofcontinuousplaces + numberofbatchplaces; + int numberofequalcontandbatchplacesanditsinputoutputtransitionbelongstotz = 0; + + for (int i=beginofcbp; i<endofcbp; i++){ + switch (places[i] ->IsA()){ + case Continuous_pl: + if (((ContinuousPlace*)places[i])->IsSteadyMarkingReachedandInputOutputTransitionBelongTz() == 1){ + numberofequalcontandbatchplacesanditsinputoutputtransitionbelongstotz++; + } + break; + case Batch_pl: + if (((BatchPlace*)places[i])->IsSteadyMarkingQuantityReachedandInputOutputTransitionBelongTz() == 1){ + numberofequalcontandbatchplacesanditsinputoutputtransitionbelongstotz++; + } + break; + } + } + + + + + + + + //constraints g and h. + + + + int nc = 0; // total of contraints + int r = 0; // current contraint + char rname[256]; // row name + + double V[NumberOfTransitions()]; // used to compute the incidence matrix, only continuous and batch positions are used + + + // variables to the linear program + glp_prob *lp; + double MSCFF[numberofcontandbatchtransitions]; // to store the result of the linear program + + nc = numberofcontandbatchtransitions; // contraint a + nc+= numberofcontandbatchtransitionsthatbelongstotz; //constraint b + nc+= numberofnotenabledorlesssteadyandbelongstofiringquantityofcontandbatchtransitions; //constraint c + nc+= numberoffullbatchplaces;//constraint d + nc+= numberofemptycontinuousplaces; // constraint e + nc+= numberofequalcontandbatchplacesanditsinputoutputtransitionbelongstotz; //constaint f + nc+= numberofbatchplaces; //constaint g + nc+= numberofbatchplaces; //constaint h + + + // contraints matrix + int ia[nc * numberofcontandbatchtransitions]; + int ja[nc * numberofcontandbatchtransitions]; + double ar[nc * numberofcontandbatchtransitions]; + int arindex; + + + // initialising linear program + lp = glp_create_prob(); + glp_set_prob_name(lp, "MSCFF"); + glp_set_obj_dir(lp, GLP_MAX); + glp_add_cols(lp, numberofcontandbatchtransitions); + glp_add_rows(lp, nc); + + // initialising transitions bound + cout << "\nTransitions bound\n\n"; + for (int i=1, k=beginofcbt; k<endofcbt; k++, i++) { + glp_set_obj_coef(lp, i, 1.0); // set (change) objective coefficient or constant term + glp_set_col_name(lp, i, transitions[k]->GetName()); // name of the transition + u = transitions[k]->GetFlow(); + if (u->GetMaximumFlow() != 0.0) + glp_set_col_bnds(lp, i, GLP_DB, 0.0, u->GetMaximumFlow());//set (change) column bounds + else + glp_set_col_bnds(lp, i, GLP_FX, 0.0, 0.0); + + cout << transitions[k]->GetName() << " : 0.0 - " << u->GetMaximumFlow() << endl; + } + + + r = 1; + arindex = 1; + + cout << "\nStart contraints\n\n"; + + // constraint a + cout << "Contraint a\n"; + for (int i=1, k=beginofcbt; k<endofcbt; k++, i++) { + sprintf(rname, "a.%d", i); + u = transitions[k]->GetFlow(); + glp_set_row_name(lp, r, rname); + if (u->GetMaximumFlow() != 0.0) + glp_set_row_bnds(lp, r, GLP_DB, 0.0, u->GetMaximumFlow()); //compare with steadyflow + else + glp_set_row_bnds(lp, r, GLP_FX, 0.0, 0.0); + + ia[arindex] = r; + ja[arindex] = i; + ar[arindex] = 1.0; // weight + arindex++; + r++; + cout << rname << " : " << "0.0 <= x <= " << u->GetMaximumFlow() << endl; + } + + + // constraint b T_Z + cout << "Contraint b\n"; + for (int i=1, k=beginofcbt; k<endofcbt; k++, i++) { + if (transitions[k]->IsFiringQuantityOnState() == 0){ + sprintf(rname, "b.%d", i); + u = transitions[k]->GetFlow(); + glp_set_row_name(lp, r, rname); + + if (u->GetSteadyFlow() != 0.0) + glp_set_row_bnds(lp, r, GLP_DB, 0.0, u->GetSteadyFlow()); //compare with steadyflow + else + glp_set_row_bnds(lp, r, GLP_FX, 0.0, 0.0); + + + ia[arindex] = r; + ja[arindex] = i; + ar[arindex] = 1.0; // weigth + arindex++; + r++; + + cout << rname << " : " << "0.0 <= x <= " << u->GetSteadyFlow() << endl; + } + } + + //constraint c + cout << "Contraint c\n"; + for (int i=1, k=beginofcbt; k<endofcbt; k++, i++){ + if (transitions[k]->GetState() == 0.0 || + ((transitions[k]->IsFiringQuantityOnState() == 0 ) && + (transitions[k]->IsOnState() ==0))){ + sprintf(rname, "c.%d", i); + glp_set_row_name(lp, r, rname); + glp_set_row_bnds(lp, r, GLP_FX, 0.0, 0.0); + + ia[arindex] = r; + ja[arindex] = i; + ar[arindex] = 1.0; // weight + arindex++; + r++; + cout << rname << " : " << ja[arindex-1] << ": 0.0 = x = 0.0 " << endl; + } + } + + // constraint d + cout << "Contraint d\n"; + for (int i=1, k=beginofbp; k<endofbp; k++, i++) { + if (((BatchPlace*)places[k])->IsFull() == 1){ + sprintf(rname, "d.%d", i); + glp_set_row_name(lp, r, rname); + glp_set_row_bnds(lp, r, GLP_UP, 0.0, 0.0); //check after + for (int j=0; j<NumberOfTransitions(); j++) { + V[j] = 0.0; + } + + for (int j=0; j<NumberOfTransitions(); j++){ + if (places[k]->GetWeightOfOutputArc(j) != 0.0 ){ + V[j] = - places[k]->GetWeightOfOutputArc(j); + cout << " - V [" << j << "] " ; + } + if (places[k]->GetWeightOfInputArc(j) != 0.0 ){ + cout << " + V [" << j << "] " ; + V[j] += places[k]->GetWeightOfInputArc(j); + } + } + cout << endl; + cout << rname << " : "; + for (int j=1, l=beginofcbt; l<endofcbt; j++, l++) { + if (V[l] != 0.0){ + ia[arindex] = r; + ja[arindex] = j; + ar[arindex] = V[l]; + arindex++; + cout << j << "(" << V[l] << ") - "; + } + } + cout << " <= 0.0" << endl; + r++; + } + } + + + + // constraint e + cout << "Contraint e\n"; + for (int i=1, k=beginofcp; k<endofcp; k++, i++) { + if (((ContinuousPlace*)places[k])->GetMarks() == 0.0){ + sprintf(rname, "d.%d", i); + glp_set_row_name(lp, r, rname); + glp_set_row_bnds(lp, r, GLP_LO, 0.0, 0.0); //check after + for (int j=0; j<NumberOfTransitions(); j++) { + V[j] = 0.0; + } + + for (int j=0; j<NumberOfTransitions(); j++){ + if (places[k]->GetWeightOfOutputArc(j) != 0.0 ){ + V[j] = - places[k]->GetWeightOfOutputArc(j); + cout << " - V [" << j << "] " ; + } + if (places[k]->GetWeightOfInputArc(j) != 0.0 ){ + cout << " + V [" << j << "] " ; + V[j] += places[k]->GetWeightOfInputArc(j); + } + } + cout << endl; + cout << rname << " : "; + for (int j=1, l=beginofcbt; l<endofcbt; j++, l++) { + if (V[l] != 0.0){ + ia[arindex] = r; + ja[arindex] = j; + ar[arindex] = V[l]; + arindex++; + cout << j << "(" << V[l] << ") - "; + } + } + cout << " >= 0.0" << endl; + r++; + } + } + + + + //constraint f + cout << "Contraint f\n"; + + for (int i=1, k=beginofcbp; k<endofcbp; k++, i++){ + switch (places[k] ->IsA()){ + case Continuous_pl: + if (((ContinuousPlace*)places[k])->IsSteadyMarkingReachedandInputOutputTransitionBelongTz() == 0) + continue; + break; + case Batch_pl: + if (((BatchPlace*)places[k])->IsSteadyMarkingQuantityReachedandInputOutputTransitionBelongTz() == 0) + continue; + break; + } + +//--------------------------------------------------------------------------- +// for (int i=1, k=beginofcbp; k<endofcbp; k++, i++){ +// int numberofinputandoutputtransitions=0; +// int numberofinputandoutputransitionsthatbelongstotz = 0; +// switch (places[k] ->IsA()){ +// case Continuous_pl: +// if (((ContinuousPlace*)places[k])->IsEqualSteadyQuantity() == 1){ +// for (int j=0; j<NumberOfTransitions(); j++) { +// V[j] = 0.0; +// } +// for (int j=0; j<NumberOfTransitions(); j++){ +// if (places[k]->GetWeightOfOutputArc(j) != 0.0 ){ +// V[j] = - places[k]->GetWeightOfOutputArc(j); +// } +// if (places[k]->GetWeightOfInputArc(j) != 0.0 ){ +// V[j] += places[k]->GetWeightOfInputArc(j); +// } +// if (V[j] !=0 ){ +// numberofinputandoutputtransitions++; // no self loop net +// } +// if (V[j] !=0 && transitions[j]->IsFiringQuantityOnState() == 0){ +// numberofinputandoutputransitionsthatbelongstotz++; +// } +// } +// if (numberofinputandoutputtransitions == numberofinputandoutputransitionsthatbelongstotz){ +// continue; +// } +// } +// break; +// +// case Batch_pl: +// if (((BatchPlace*)places[k])->IsEqualSteadyQuantity() == 1){ +// for (int j=0; j<NumberOfTransitions(); j++) { +// V[j] = 0.0; +// } +// for (int j=0; j<NumberOfTransitions(); j++){ +// if (places[i]->GetWeightOfOutputArc(j) != 0.0 ){ +// V[j] = - places[k]->GetWeightOfOutputArc(j); +// } +// if (places[i]->GetWeightOfInputArc(j) != 0.0 ){ +// V[j] += places[k]->GetWeightOfInputArc(j); +// } +// if (V[j] !=0 ){ +// numberofinputandoutputtransitions++; // no self loop net +// } +// if (V[j] !=0 && transitions[j]->IsFiringQuantityOnState() == 0){ +// numberofinputandoutputransitionsthatbelongstotz++; +// } +// } +// if (numberofinputandoutputtransitions == numberofinputandoutputransitionsthatbelongstotz) +// continue; +// } +// break; +// } +//------------------------------------------------------------------------------- + sprintf(rname, "f.%d", i); + glp_set_row_name(lp, r, rname); + glp_set_row_bnds(lp, r, GLP_FX, 0.0, 0.0); + for (int j=0; j<NumberOfTransitions(); j++) { + V[j] = 0.0; + } + + for (int j=0; j<NumberOfTransitions(); j++){ + if (places[k]->GetWeightOfOutputArc(j) != 0.0 ){ + V[j] = - places[k]->GetWeightOfOutputArc(j); + cout << " - V [" << j << "] " ; + } + if (places[k]->GetWeightOfInputArc(j) != 0.0 ){ + cout << " + V [" << j << "] " ; + V[j] += places[k]->GetWeightOfInputArc(j); + } + } + cout << endl; + cout << rname << " : "; + for (int j=1, l=beginofcbt; l<endofcbt; j++, l++) { + if (V[l] != 0.0){ + ia[arindex] = r; + ja[arindex] = j; + ar[arindex] = V[l]; + arindex++; + cout << j << "(" << V[l] << ") - "; + } + } + cout << " = 0.0" << endl; + r++; + } + + //constraint g + cout << "Contraint g\n"; + for (int i=1, k=beginofbp; k<endofbp; k++, i++){ + maxinputflow = ((BatchPlace*)places[k])->GetMaxSpeed() * ((BatchPlace*)places[k])->GetDensity(); + sprintf(rname, "g.%d", i); + glp_set_row_name(lp, r, rname); + glp_set_row_bnds(lp, r, GLP_UP, 0.0, maxinputflow); + + for (int j=0; j<NumberOfTransitions(); j++) { + V[j] = 0.0; + } + for (int j=0; j<NumberOfTransitions(); j++){ + if (places[k]->GetWeightOfInputArc(j) != 0.0 ){ + V[j] = places[k]->GetWeightOfInputArc(j); + } + } + cout << rname << " : "; + for (int j=1, l=beginofcbt; l<endofcbt; j++, l++) { + if (V[l] != 0.0){ + ia[arindex] = r; + ja[arindex] = j; + ar[arindex] = V[l]; + arindex++; + cout << j << "(" << V[l] << ") - "; + } + } + cout << "0.0 <= x <= " << maxinputflow << endl; + r++; + } + + + + // constraint h + cout << "Contraint h\n"; + + for (int i=1, k=beginofbp; k<endofbp; k++, i++) { + maxflow = ((BatchPlace*)places[k])->GetMaxSpeed() * ((BatchPlace*)places[k])->GetDensityOutputBatch(); + sprintf(rname, "h.%d", i); + glp_set_row_name(lp, r, rname); + if (maxflow != 0.0) + glp_set_row_bnds(lp, r, GLP_UP, 0.0, maxflow); + else + glp_set_row_bnds(lp, r, GLP_FX, 0.0, 0.0); + + for (int j=0; j<NumberOfTransitions(); j++) { + V[j] = 0.0; + } + for (int j=0; j<NumberOfTransitions(); j++){ + if (places[k]->GetWeightOfOutputArc(j) != 0.0 ){ + V[j] = places[k]->GetWeightOfOutputArc(j); + } + } + cout << rname << " : "; + for (int j=1, l=beginofcbt; l<endofcbt; j++, l++) { + if (V[l] != 0.0){ + ia[arindex] = r; + ja[arindex] = j; + ar[arindex] = V[l]; + arindex++; + cout << j << "(" << V[l] << ") - "; + } + } + cout << "0.0 <= x <= " << maxflow << endl; + r++; +} + + glp_term_out(GLP_OFF); + glp_load_matrix(lp, arindex-1, ia, ja, ar); + glp_simplex(lp, NULL); + + for (int i=0, k=beginofcbt; k<endofcbt; k++, i++) { + MSCFF[i] = glp_get_col_prim(lp, (i+1)); + u = transitions[k]->GetFlow(); //???continuous transition class? + u->SetTheoreticalFlow(MSCFF[i]); + u->SetCurrentFlow(MSCFF[i]); + + // cout << transitions[k]->GetName() << " : " << MCFF[i] << endl; + } + + int col[numberofcontandbatchtransitions]; + double val[numberofcontandbatchtransitions]; + +// for (int i=1; i<=glp_get_num_rows(lp); i++){ +// cout << glp_get_row_name(lp, i) << " : "; +// for (int j=1; j<=glp_get_mat_row(lp, i, col, val); j++){ +// cout << col[j] << "(" << val[j] << ") - "; +// } +// cout << glp_get_row_lb(lp, i) << " - " << glp_get_row_ub(lp, i) << endl; +// } + + glp_delete_prob(lp); +////======================================================================= +} diff --git a/src/bpn/bpn.h b/src/bpn/bpn.h new file mode 100644 index 0000000000000000000000000000000000000000..d51822c1414512398f919af7172307ecf8465e11 --- /dev/null +++ b/src/bpn/bpn.h @@ -0,0 +1,144 @@ +//====================================================================================// +// // +// Batch Petri Nets main class // +// // +//====================================================================================// +// This File: bpn.h Language: C++ (xlC and CC) // +// Software: SIMULEAU // +//====================================================================================// +// Creation: 21/apr/16 by: Leonardo.Brenner@lsis.org // +// Last Change: 21/apr/16 by: Leonardo.Brenner@lsis.org // +//====================================================================================// +#ifndef BPN_H +#define BPN_H + +class BPN +{ + public: + BPN(); + BPN(const int _numberofplaces, const int _numberoftransitions); + virtual ~BPN(); + + void Copy(const BPN *_bpn); + + + void AllocArcs(); + void AddNodeLinks(); + + //input functions + void PutName(simuleau_name _name); // put a name on the bpn + // place functions + void NumberOfDiscretePlaces(const int n); // set the number of discrete places + void NumberOfContinuousPlaces(const int n); // set the number of continuous places + void NumberOfBatchPlaces(const int n); // set the number of batch places + void NumberOfTriangularBatchPlaces(const int n); // set the number of triangular batch places + int AddPlace(int pos, Place *p); // add a place to the bpn in the position pos + void SetInitialMarking(int pos, int m); // set the initial marking of a discrete place + void SetSteadyMarking(int pos, int m); // set the steady marking of a discrete place + void SetInitialMarking(int pos, double m); // set the initial marking of a conitnuous place + void SetSteadyMarking(int pos, double m); // set the steady marking of a conitnuous place + void AddBatchToInitialMarking(int pos, Batch &b); // set the initial marking of a batch place + void AddBatchToSteadyMarking(int pos, Batch &b); // set the steady marking of a batch place + void AddTriangularToInitialMarking(int pos, ControllableBatch &b); + // set the initial marking of a controllable batch place + void AddTriangularToSteadyMarking(int pos, ControllableBatch &b); + // set the steady marking of a controllable batch place + int AddPlaceOutputArc(int _place, int _transition, double _weight); + // Add an output arc from place to transition + // transition functions + void NumberOfDiscreteTransitions(const int n); // set the number of discrete transitions + void NumberOfContinuousTransitions(const int n); // set the number of continuous transitions + void NumberOfBatchTransitions(const int n); // set the number of batch transitions + int AddTransition(int pos, Transition *t); // add a transition to the bpn in the position pos + int AddTransitionOutputArc(int _transition, int _place, double _weight); + // Add an output arc from transition to place + //output functions + int VerifyName(simuleau_name _name); // verify if _name is already defined in the model + char* GetName(); // get the bpn model name + Node* GetNode(simuleau_name _name); // return the addresse of the node _name; + // place functions + int NumberOfDiscretePlaces(); // return the number of discrete places + int NumberOfContinuousPlaces(); // return the number of continuous places + int NumberOfBatchPlaces(); // return the number of batch places + int NumberOfTriangularBatchPlaces(); // return the number of triangular batch places + int NumberOfPlaces(); // return the number of all places + int GetPlacePosition(simuleau_name _name); // return the position of the place _name + char* GetPlaceName(place_id _place); // return the place name of a place position + Place* GetPlace(place_id _place); // return the place pointer of a place position + place_type GetPlaceType(simuleau_name _name); // return the place type of the place _name + + // transition functions + int NumberOfDiscreteTransitions(); // return the number of discrete transitions + int NumberOfContinuousTransitions(); // return the number of continuous transitions + int NumberOfBatchTransitions(); // return the number of batch transitions + int NumberOfTransitions(); // return the number of all transitions + int GetTransitionPosition(simuleau_name _name); // return the position of the transitions _name + char* GetTransitionName(trans_id _trans); // return the transition name of a transition position + Transition *GetTransition(trans_id _trans); // return the transition pointer of a transition position + trans_type GetTransitionType(simuleau_name _name); // return the transition type of the transition _name + + // print functions + void Print(ostream &fout); + void WritePlaces(ostream &fout); + void WriteFlows(ostream &fout); + + // simulation functions + void ComputeNewMarks(double duration); + void ReserveMarks(); + void CreateBatches(); + void DestructBatches(); + void MergeBatches(); + int ComputeTransitionsStates(); + int StateStability(double *p, double *t); + void ComputeBatchesBehaviours(); + void SetBehaviourFunctions(); + void ComputeIFF(); + void ComputeCFF(); // on/off control method + void ComputeMCFF(); // maximal on/off control method + void ComputeMSCFF(); // near-optimal on/off control method + void ComputeSteadyState(); //Computation of a steady state + void ComputePeriodicSteadyState(); //Computation of a periodic steady state + void ResearchStructuralConflict(); + int VerifyConflict(); + int IsSteadyStateReached(); + void ComputeCurrentFiringQuantity(double steptime); //maximal on/off control method + void ComputeSteadyFiringQuantity(); + + //process event functions + void ComputeNextEventDTF(list<Event> * _dtf); + void ComputeNextEventCPE(list<Event> * _cpe); + void ComputeNextEventDTE(list<Event> * _dte); + void ComputeNextEventBOB(list<Event> * _bob); + void ComputeNextEventDOB(list<Event> * _dob); + void ComputeNextEventBBD(list<Event> * _bbd); + void ComputeNextEventTBM(list<Event> * _tbm); + void ComputeNextEventBMOB(list<Event> * _bmob); + void ComputeNextEventOBD(list<Event> * _obd); + void ComputeNextEventBD(list<Event> * _bd); + void ComputeNextEventBBF(list<Event> * _bbf); + void ComputeNextEventPSQ(list<Event> * _psq); //on off method + void ComputeNextEventRBF(list<Event> * _rbf); //maximal flow based on off method + + + protected: +// int numberofplaces; // number of all places in this model + int numberofdiscreteplaces; // number of discrete places + int numberofcontinuousplaces; // number of continuous places + int numberofbatchplaces; // number of batch places + int numberoftriangularplaces; // number of triangular batch places + +// int numberoftransitions; // number of all transitions in this model + int numberofdiscretetransitions; // number of discrete transitions + int numberofcontinuoustransitions; // number of continuous transitions + int numberofbatchtransitions; // number of batch transitions + + Place **places; // ensemble de places + Transition **transitions; // ensemble de transitions + // double currentfiringquantity; + + private: + simuleau_name bpnname; // BPN model name + +}; + +#endif // BPN_H diff --git a/src/bpn/continuousplace.cpp b/src/bpn/continuousplace.cpp new file mode 100644 index 0000000000000000000000000000000000000000..61fb12dee51ebb6cdb42d9fcb7e61af60e85ac27 --- /dev/null +++ b/src/bpn/continuousplace.cpp @@ -0,0 +1,825 @@ +//====================================================================================// +// // +// Continuous place classes inherit of place class // +// // +//====================================================================================// +// This File: continuousplace.cpp Language: C++ (xlC and CC) // +// Software: SIMULEAU // +//====================================================================================// +// Creation: 22/apr/16 by: Leonardo.Brenner@lsis.org // +// Last Change: 22/apr/16 by: Leonardo.Brenner@lsis.org // +//====================================================================================// +#include "simuleau.h" + +//------------------------------------------------------------------------------ +//------------------------------------------------------------------------------ +// Methods of the Continuous Place class +//------------------------------------------------------------------------------ +//------------------------------------------------------------------------------ + +//------------------------------------------------------------------------------ +// Constructor +//------------------------------------------------------------------------------ +ContinuousPlace::ContinuousPlace() +{ + +} + +//------------------------------------------------------------------------------ +// Named Constructor +//------------------------------------------------------------------------------ +ContinuousPlace::ContinuousPlace(simuleau_name _name):Place(_name) +{ + +} + +//------------------------------------------------------------------------------ +// Destructor +//------------------------------------------------------------------------------ +ContinuousPlace::~ContinuousPlace() +{ + +} + + +//------------------------------------------------------------------------------ +// Copy +//------------------------------------------------------------------------------ +void ContinuousPlace::Copy(const ContinuousPlace * _place) +{ + TransferNode(_place); + + marks = _place->marks; + initialmarks = _place->initialmarks; + steadymarks = _place->steadymarks; + reservedmarks = _place->reservedmarks; + nonreservedmarks = _place->nonreservedmarks; + + conflict = _place->conflict; + structuralconflict = _place->structuralconflict; + +} + +//------------------------------------------------------------------------------ +// It set the initial marking of the place +//------------------------------------------------------------------------------ +void ContinuousPlace::SetInitialMarking(double m) +{ + marks = initialmarks = nonreservedmarks = m; + reservedmarks = 0; +} + + +//----------------------------------------------------------------------------- +//It returns the initial marking of a place +//---------------------------------------------------------------------------- +double ContinuousPlace::GetInitialMarks() +{ + return(initialmarks); +} + + +//------------------------------------------------------------------------------ +// It set the steady marking of the place +//------------------------------------------------------------------------------ +void ContinuousPlace::SetSteadyMarking(double m) +{ + steadymarks = m; +} + +//------------------------------------------------------------------------------ + +// It returns the steady marking of the place +//---------------------------------------------------------------------- +double ContinuousPlace::GetSteadyMarks() +{ + return (steadymarks); +} + +//------------------------------------------------------------------------------ +// It returns the place marks +//------------------------------------------------------------------------------ +double ContinuousPlace::GetMarks() +{ + return (marks); +} + +//------------------------------------------------------------------------------ +// It changes the place marks +//------------------------------------------------------------------------------ +void ContinuousPlace::ChangeMarks(double m) +{ + marks = nonreservedmarks = m; + if (abs(m) < PRF::prf.Min_Err()){ + marks = nonreservedmarks = 0.0; + } +} + + +//------------------------------------------------------------------------------ +// It reduces the place marks +//------------------------------------------------------------------------------ +void ContinuousPlace::ReduceMarks(double m) +{ + nonreservedmarks -= m; + marks = nonreservedmarks + reservedmarks; + if (abs(marks) < PRF::prf.Min_Err()){ + marks = nonreservedmarks = reservedmarks = 0.0; + } +} + +//------------------------------------------------------------------------------ +// It reserve the place marks +//------------------------------------------------------------------------------ +void ContinuousPlace::ReserveMarks(double m) +{ + reservedmarks += m; + nonreservedmarks = marks - reservedmarks; +} + +//------------------------------------------------------------------------------ +// It remove the reserved marks in the place +//------------------------------------------------------------------------------ +void ContinuousPlace::RemoveReservedMarks(double m) +{ + reservedmarks -= m; + marks = nonreservedmarks + reservedmarks; + if (abs(marks) < PRF::prf.Min_Err()){ + marks = nonreservedmarks = reservedmarks = 0.0; + } +} + +//------------------------------------------------------------------------------ +// It adds the marks to the place +//------------------------------------------------------------------------------ +void ContinuousPlace::AddMarks(double m) +{ + marks += m; + nonreservedmarks = marks -reservedmarks; + + /*if (nonreservedmarks < 0.0){ + nonreservedmarks = 0.0; + marks = nonreservedmarks + reservedmarks; + } + if (marks < 0.0){ + marks = 0.0; + nonreservedmarks = 0.0; + reservedmarks = 0.0; + }*/ +} + +//------------------------------------------------------------------------------ +// It compute the continuous place state +// TODO verfiy method and definition 9 in Demongodin thesis +//------------------------------------------------------------------------------ +void ContinuousPlace::ComputeState() +{ + int counter = 0; + Transition *t; + + if (GetNumberOfOutputArcs() == 0){ + state = 0.0; + } + else{ + for (int i=0; i<numberofarcs; i++){ + if (outputarcs[i] != 0.0){ +// t = simulation->sbpn->GetTransition(i); + t = outputnodes[i]; + } + } + + switch (t->IsA()){ + case Continuous_tr: + case Batch_tr: if (nonreservedmarks > 0.0){ + state = 1.0; // continuous place not empty + } + else{ + state = PlaceIsFed(); // in case of an empty place + } + break; + case Discrete_tr: if (reservedmarks != 0.0){ + state = 0.5; + } + else{ // there is no reserved marks + for (int i=0; i<numberofarcs; i++){ + if ((outputarcs[i] != 0.0 ) && (nonreservedmarks < (outputarcs[i] - PRF::prf.Min_Err()))){ + counter++; + } + } + if (counter == 0){ + state = 1.0; + } + else{ + state = 0.0; + } + } + break; + } + } + + //cout << "\nstate of a continuous place : " << state << endl; +} + + +//------------------------------------------------------------------------------ +// It evolves the marks in the place +//------------------------------------------------------------------------------ +void ContinuousPlace::EvolveMarks(double _date) +{ + VerifyMarks(); +} + +//------------------------------------------------------------------------------ +// It evolves the marks in the place +//------------------------------------------------------------------------------ +void ContinuousPlace::VerifyMarks() +{ + if ((nonreservedmarks < 0.0) || ((nonreservedmarks < PRF::prf.Min_Err()) && (nonreservedmarks > - PRF::prf.Min_Err()))){ + nonreservedmarks = 0.0; + marks = nonreservedmarks + reservedmarks; + } + if (((marks < PRF::prf.Min_Err()) && (marks > - PRF::prf.Min_Err())) || (marks < 0.0)){ + marks = 0.0; + nonreservedmarks = 0.0; + reservedmarks = 0.0; + } +} + + + + +//------------------------------------------------------------------------------ +// It verifies effectif conflits +//------------------------------------------------------------------------------ +int ContinuousPlace::VerifyConflict() +{ + int necessarymarks = 0; + int numberoftransitionsinconflict = 0; + double currentflow = 0.0; + + Transition *t; + Flow *f; + + conflict = 0; + + if (structuralconflict){ + if (GetNumberOfOutputArcs() == 0){ //why the output arcs are zero when it has a strucral conflict ----29/01/2020 + for (int i=0; i<numberofarcs; i++){ + if (outputarcs[i] != 0){ +// t = simulation->sbpn->GetTransition(i); + t = outputnodes[i]; + if ((t->GetState()!=1)) { + f = t->GetFlow(); + if (f->GetCurrentFlow()){ + numberoftransitionsinconflict++; + } + } + } + } + + if (numberoftransitionsinconflict > 1){ + conflict = 2; + return (2); + } + } + } + return (0); +} + + +//------------------------------------------------------------------------------ +// It computes if the place is fed (has an input flow) +//------------------------------------------------------------------------------ +double ContinuousPlace::PlaceIsFed() +{ + double pre = 0.0; + double transitionstate; + + Transition *t; + + if (GetNumberOfInputArcs() == 0){ + return (Not_fed); + } + for (int i=0; i<numberofarcs; i++){ + if (inputarcs[i] != 0.0){ +// t = simulation->sbpn->GetTransition(i); + t = inputnodes[i]; + switch (t->IsA()){ + case Continuous_tr: + case Batch_tr: transitionstate = t->GetState(); + pre = max(pre, transitionstate); + break; + } + } + } + if (pre == 0.0){ + return (Not_fed); + } + else{ + return (Fed); + } +} + +//==========================WOdes================================================ +//------------------------------------------------------------------------------ +// It returns true if the continuous place reaches steady marking quantity +//------------------------------------------------------------------------------ +int ContinuousPlace::IsEqualSteadyQuantity() +{ + if (abs(steadymarks - marks) < PRF::prf.Min_Err()) + return 1; + return 0; + } + +//------------------------------------------------------------------------------ +// It returns true if the marking quantity of continuous place is greater than steady marking quantity +//------------------------------------------------------------------------------ +int ContinuousPlace::IsGreaterThanSteadyQuantity() +{ + if ((marks - steadymarks) > PRF::prf.Min_Err()) + return 1; + return 0; +} + +//------------------------------------------------------------------------------ +// It returns true if the marking quantity of continuous place is less than steady marking quantity +//------------------------------------------------------------------------------ +int ContinuousPlace::IsLessThanSteadyQuantity() +{ + if ((abs(marks - steadymarks) > PRF::prf.Min_Err()) && ((marks - steadymarks) < 0.0)) + return 1; + return 0; + +} + +//------------------------------------------------------------------------------ +// It returns true if the marking of continuous place is equal than steady marking +//------------------------------------------------------------------------------ +int ContinuousPlace::IsSteadyMarkingReached() +{ + if (abs(steadymarks - marks) < PRF::prf.Min_Err()) + return 1; + return 0; + +} +//============================================================================= + +//===================Vecos================================================== +// It returns ture if the marking of continuous place is equal to steady marking +// and all of its input and output transition belongs to T_Z. +//========================================================================== +int ContinuousPlace::IsSteadyMarkingReachedandInputOutputTransitionBelongTz() +{ + Transition *t; + double weight; + int placestate =0; + int counter = 0; + int countertz=0; + + + if (abs(steadymarks - marks) < PRF::prf.Min_Err()){ + if (GetNumberOfOutputArcs() == 0){ + return 1; // the conservative net and consistent net + } + else{ + for (int i=0; i<numberofarcs; i++){ + if (outputarcs[i] != 0.0){ +// t = simulation->sbpn->GetTransition(i); + t=outputnodes[i]; + counter++; + } + if (outputarcs[i] != 0.0 && t->IsFiringQuantityOnState()==0) + countertz++; + + } + } + + if (GetNumberOfInputArcs() == 0){ + return 1; // the conservative net and consistent net + } + else{ + for (int i=0; i<numberofarcs; i++){ + if (inputarcs[i] != 0.0){ +// t = simulation->sbpn->GetTransition(i); + t=inputnodes[i]; + counter++; + } + if (inputarcs[i] != 0.0 && t->IsFiringQuantityOnState()==0) + countertz++; + + } + } + if (counter == countertz) + return 1; + return placestate; + } + return placestate; +} + +//------------------------------------------------------------------------------ +// It computes the input flow of a fed place +//------------------------------------------------------------------------------ +double ContinuousPlace::ComputeFlowFedPlace(ContinuousTransition *ct) +{ + Transition *t; + Flow *f = ct->GetFlow(); + double fedplaceflow = f->GetTheoreticalFlow(); + double transitionflow; + double preflow = 0.0; + double postflow = 0.0; + + + if (fedplaceflow < 0.0){ // infinite flow + return (fedplaceflow); + } + + if (GetNumberOfInputArcs() == 0){ + preflow = 0.0 ; + } + else{ + for (int i=0; i<numberofarcs; i++){ + if (inputarcs[i] != 0.0){ +// t = simulation->sbpn->GetTransition(i); + t = inputnodes[i]; + switch(t->IsA()){ + case Continuous_tr: + case Batch_tr: f = t->GetFlow(); + transitionflow = f->GetTheoreticalFlow(); + if (transitionflow < 0.0){ // infinite flow + postflow = -1.0; + i = numberofarcs; + } + else{ + postflow += (inputarcs[i] * transitionflow); + } + break; + } + } + } + } + + // if the input flow isn't infinite, compute the output flow + if (postflow < 0.0){ + return (postflow); + } + else{ + if (GetNumberOfOutputArcs() != 0){ + for (int i=0; i<numberofarcs; i++){ + if (outputarcs[i] != 0.0){ +// t = simulation->sbpn->GetTransition(i); + t = outputnodes[i]; + switch(t->IsA()){ + case Continuous_tr: + case Batch_tr: f = t->GetFlow(); + transitionflow = f->GetTheoreticalFlow(); + if (transitionflow < 0.0){ // infinite flow + preflow = -1.0; + i = numberofarcs; + } + else{ + preflow += (outputarcs[i] * transitionflow); + } + break; + } + } + } + } + } + + if (preflow < 0.0){ // infinite flow + return (-1.0); + } + else{ + fedplaceflow = fedplaceflow - preflow + postflow; + return (fedplaceflow); + } +} + + + +//------------------------------------------------------------------------------ +// It computes the date of the next event to Continuous Place becomes Enabled type +// return -1 for no event and event date otherwise +//------------------------------------------------------------------------------ +double ContinuousPlace::GetCPEEvent() +{ + Transition *t; + Flow *f; + double transitionflow = 0.0; + double weightflow = 0.0; + double eventdate = -2.0; + + if (GetNumberOfOutputArcs()){ + for (int i=0; i<numberofarcs; i++){ + if (outputarcs[i] != 0.0){ +// t = simulation->sbpn->GetTransition(i); + t = outputnodes[i]; + switch (t->IsA()){ + case Continuous_tr: + case Batch_tr: f = t->GetFlow(); + transitionflow = f->GetCurrentFlow(); + if (transitionflow <= 0.0) { // infinit flow + eventdate = -1.0; + i = numberofarcs; // stop loop for + } + else{ + weightflow -= (outputarcs[i] * transitionflow); + } + break; + } + } + } + } + + if (eventdate == -1.0){ + return (eventdate); + } + else{ + if (GetNumberOfInputArcs()){ + for (int i=0; i<numberofarcs; i++){ + if (inputarcs[i] != 0){ +// t = simulation->sbpn->GetTransition(i); + t = inputnodes[i]; + switch (t->IsA()){ + case Continuous_tr: + case Batch_tr: f = t->GetFlow(); + transitionflow = f->GetCurrentFlow(); + if (transitionflow > 0.0) { // non infinit flow + weightflow += (inputarcs[i] * transitionflow); + } + break; + } + } + } + } + } + if ((weightflow != 0.0)){ + eventdate = simulation->stime->GetCurrentDate() - (nonreservedmarks/weightflow); + } + return (eventdate); +} + + +//------------------------------------------------------------------------------ +// It computes the date of the next event to Discrete Transistion becomes Enabled type +//------------------------------------------------------------------------------ +double ContinuousPlace::GetDTEEvent() +{ + Transition *t; + double eventdate = -1.0; + double result; + + if (GetNumberOfOutputArcs()){ + for (int i=0; i<numberofarcs; i++){ + if (outputarcs[i] != 0){ +// t = simulation->sbpn->GetTransition(i); + t = outputnodes[i]; + switch (t->IsA()){ + // cas où la transition aval est une transition discrete ----- + // ATTENTION !!!!!! + // SUPPOSE QUE TOUTE PLACE CONTINUE A + // UNE ET UNE SEULE TRANISTION DISCRETE AVAL + case Discrete_tr: result = ComputeDateDTEEvent(t, outputarcs[i]); + if ((result <= 0.0) && (result != simulation->stime->GetCurrentDate())){ // infinit flow + eventdate = -1.0; + i = numberofarcs; + } + else{ + eventdate = result; + } + break; + } + } + } + } + return (eventdate); +} + + +//-----------------On off Code------------------------------------------------- +// It computes the date of the next event to marking quantity of a batch place +// reaches its steady marking quantity (Place reaches Steady marking Quantity). +//------------------------------------------------------------------------------ +/*double ContinuousPlace::GetPSQEvent() +{ + double steadymarks; // we need input this value before the simulation. !!! + double marks; + double date; + double outputtransitionflow = 0; + Transition *t; + Flow *u; + InFlow *I; + + if (abs(marks - steadymarks) < PRF::prf.Min_Err()){ + return (date); + } + else{ + for (int i=0; i<numberofarcs; int j=0; j<numberofarcs; i++,j++){ + if (outputarcs[i] != 0.0 || inputarcs[j] != 0.0){ + t = outputnodes[i]; + m = inputnodes[j]; + switch (t->IsA()){ + case Batch_tr: u = t->GetFlow(); + I = m->GetFlow(); + inputtransitionflow = m->GetFlow(); + outputtransitionflow = u->GetCurrentFlow(); + date = (ContinuousPlace::GetMarks()-steadymarks) / (ContinuousPlace::GetOutflow - inputtransitionflow); + date += simulation->stime->GetCurrentDate(); + break; + case Continuous_tr: u = t->GetFlow(); + I = m->GetFlow(); + inputtransitionflow = m->GetCurrentFlow(); + outputtransitionflow = u->GetCurrentFlow(); + date = (ContinuousPlace::GetMarks()-steadymarks) / (outputtransitionflow - inputtransitionflow); + date += simulation->stime->GetCurrentDate(); + break; + } +} + return (date); +} +} +}*/ + +//============================PSQ event===================== +// +//=========================================================== + +double ContinuousPlace::GetPSQEvent() +{ + double steadymarks=0.0; + double marks=0.0; + double transitionflow = 0.0; + double weightflow = 0.0; + double eventdate = -2.0; + Transition *t; + Flow *f; + + if (abs(GetMarks() - GetSteadyMarks()) < PRF::prf.Min_Err()){ + eventdate= simulation->stime->GetCurrentDate(); + } + else{ + if (GetNumberOfOutputArcs()){ + for (int i=0; i<numberofarcs; i++){ + if (outputarcs[i] != 0.0){ +// t = simulation->sbpn->GetTransition(i); + t = outputnodes[i]; + switch (t->IsA()){ + case Continuous_tr: + case Batch_tr: f = t->GetFlow(); + transitionflow = f->GetCurrentFlow(); + weightflow -= (outputarcs[i] * transitionflow); + break; + } + } + } + } + + if (GetNumberOfInputArcs()){ + for (int i=0; i<numberofarcs; i++){ + if (inputarcs[i] != 0){ +// t = simulation->sbpn->GetTransition(i); + t = inputnodes[i]; + switch (t->IsA()){ + case Continuous_tr: + case Batch_tr: f = t->GetFlow(); + transitionflow = f->GetCurrentFlow(); + + weightflow += (inputarcs[i] * transitionflow); + + break; + } + } + } + } + if ((weightflow != 0.0)){ + eventdate = simulation->stime->GetCurrentDate() - ((GetMarks()-GetSteadyMarks())/weightflow); + } + return (eventdate); +} +} + + +//------------------------------------------------------------------------------ +// Print +//------------------------------------------------------------------------------ +void ContinuousPlace::Print(ostream &fout) +{ + fout << "Name: " << name << endl; + fout << " Type: " << "Continuous" << endl; + fout << " Marks: " << marks << endl; + fout << " Initial Marks: " << initialmarks << endl; + if (steadymarks!=-1.0) + fout << " Steady Marks: " << steadymarks << endl; + fout << " Reserved Marks: " << reservedmarks << endl; + fout << " Non Reserved Marks: " << nonreservedmarks << endl; + fout << " Arcs: " << endl; + PrintArcs(fout); +} + +//------------------------------------------------------------------------------ +// Write +//------------------------------------------------------------------------------ +void ContinuousPlace::Write(ostream &fout) +{ + fout << "Name: " << name << endl; + fout << " Type: " << "Continuous" << endl; + fout << " Marks: " << marks << endl; + if (steadymarks!=-1.0){ + fout << " Steady Marks: " << steadymarks; + if (IsSteadyMarkingReached()) + fout << " (steady marking reached)"; + fout << endl; + } + fout << " Reserved Marks: " << reservedmarks << endl; +} + + +//------------------------------------------------------------------------------ +// It computes the date of the next event DTE for a specific transition +// It return -1.0 if transtion if already enabled and eventdate otherwise +//------------------------------------------------------------------------------ +double ContinuousPlace::ComputeDateDTEEvent(DiscreteTransition *t, double weight) +{ + double inputflow; + double m; + double eventdate; + + if (t->GetState() != 0.0){ // transition is already enabled + return (-1.0); + } + else{ // compute the next validation + inputflow = ComputeInputFlow(); + if (inputflow != 0.0){ + m = weight - nonreservedmarks; + eventdate = m / inputflow; + eventdate += simulation->stime->GetCurrentDate(); + return (eventdate); + } + else{ + return (-1.0); + } + } +} + +//------------------------------------------------------------------------------ +// It computes the input flow for the continuous place +//------------------------------------------------------------------------------ +double ContinuousPlace::ComputeInputFlow() +{ + double inputflow = 0.0; + double transitionflow; + Flow *f; + Transition *t; + + if (GetNumberOfInputArcs()){ + for (int i=0; i<numberofarcs; i++){ + if (inputarcs[i] != 0){ +// t = simulation->sbpn->GetTransition(i); + t = inputnodes[i]; + switch (t->IsA()){ + case Continuous_tr: + case Batch_tr: if (t->GetState() != 0.0){ // test if the transition (continuous or batch) was validated + f = t->GetFlow(); + transitionflow = f->GetCurrentFlow(); + inputflow += (inputarcs[i] * transitionflow); + } + break; + } + } + } + } + return (inputflow); +} + +//=============================Outputflowof continuous place======= +// +//================================================================= + +/*double ContinuousPlace::ComputeOutputFlow() +{ + double outputflow = 0.0; + double transitionflow; + Flow *f; + Transition *t; + + if (GetNumberOfOutputArcs()){ + for (int i=0; i<numberofarcs; i++){ + if (outputarcs[i] != 0){ +// t = simulation->sbpn->GetTransition(i); + t = outputnodes[i]; + switch (t->IsA()){ + case Continuous_tr: + case Batch_tr: if (t->GetState() != 0.0){ // test if the transition (continuous or batch) was validated + f = t->GetFlow(); + transitionflow = f->GetCurrentFlow(); + outputflow += (outputarcs[i] * transitionflow); + } + break; + } + } + } + } + return (outputflow); +} + +*/ diff --git a/src/bpn/continuoustransition.cpp b/src/bpn/continuoustransition.cpp new file mode 100644 index 0000000000000000000000000000000000000000..d0d9772303a53dd1be84c25b9b6cde5868d88d5e --- /dev/null +++ b/src/bpn/continuoustransition.cpp @@ -0,0 +1,315 @@ +//====================================================================================// +// // +// Continuous transition classes inherit of transition class // +// // +//====================================================================================// +// This File: continuoustransition.cpp Language: C++ (xlC and CC) // +// Software: SIMULEAU // +//====================================================================================// +// Creation: 22/apr/16 by: Leonardo.Brenner@lsis.org // +// Last Change: 22/apr/16 by: Leonardo.Brenner@lsis.org // +//====================================================================================// +#include "simuleau.h" + + + +//------------------------------------------------------------------------------ +//------------------------------------------------------------------------------ +// Methods of the Continuous Transition class +//------------------------------------------------------------------------------ +//------------------------------------------------------------------------------ + +//------------------------------------------------------------------------------ +// Constructor +//------------------------------------------------------------------------------ +ContinuousTransition::ContinuousTransition() +{ + +} + +//------------------------------------------------------------------------------ +// Named Constructor +//------------------------------------------------------------------------------ +ContinuousTransition::ContinuousTransition(simuleau_name _name, double _flow, double _steadyflow):Transition(_name) +{ + flow = new Flow; + flow->SetAllFlows(_flow); + flow->SetSteadyFlow(_steadyflow); + +} + +//------------------------------------------------------------------------------ +// Destructor +//------------------------------------------------------------------------------ +ContinuousTransition::~ContinuousTransition() +{ + if (flow) + delete flow; +} + +//------------------------------------------------------------------------------ +// Copy +//------------------------------------------------------------------------------ +void ContinuousTransition::Copy(const ContinuousTransition *_transition) +{ + TransferNode(_transition); + flow = new Flow; + flow->Copy(_transition->flow); // transition flows + firingquantity = new FiringQuantity; + firingquantity->Copy(_transition->firingquantity); +} + + +//------------------------------------------------------------------------------ +// Returns flows +//------------------------------------------------------------------------------ +Flow* ContinuousTransition::GetFlow() +{ + return (flow); +} + +//------------------------------------------------------------------------------ +// set the initial flow +//------------------------------------------------------------------------------ +void ContinuousTransition::SetInitialFlow(double _flow) +{ + flow->SetInitialFlow(_flow); +} + +//------------------------------------------------------------------------------ +// set the initial flow +//------------------------------------------------------------------------------ +void ContinuousTransition::SetTheoreticalFlow(double _flow) +{ + flow->SetTheoreticalFlow(_flow); +} + +//------------------------------------------------------------------------------ +// It returns true if the current flow is equal to the steady flow +//------------------------------------------------------------------------------ +int ContinuousTransition::IsSteadyFlowReached() +{ + if (abs(flow->GetCurrentFlow() - flow->GetSteadyFlow()) < PRF::prf.Min_Err()) + return 1; + return 0; +} + +//------------------------------------------------------------------------------ +// Compute minimum positive flow +//------------------------------------------------------------------------------ +double ContinuousTransition::ComputeMinimumFlow(double f1, double f2) +{ + double minimum; + + if ((f1 >= 0.0) && (f2 >= 0.0)){ + minimum = min(f1,f2); + } + else { + if ((f1 < 0.0) && (f2 < 0.0)){ + minimum = f2; + } + if (f1 < 0.0){ + minimum = f2; + } + if (f2 < 0.0) { + minimum = f1; + } + } + return (minimum); +} + +//------------------------------------------------------------------------------ +// It computes the theoretical flow +//------------------------------------------------------------------------------ +void ContinuousTransition::ComputeTheoreticalFlow() +{ + double flowvalue; + + + if (state == 0.0){ // not enable transition + flowvalue = 0.0; // null flow + } + else{ + if (state == 1.0){ // transition is strongly validated + flowvalue = flow->GetMaximumFlow(); + } + else{ + flowvalue = ComputeMinimumFlow(flow->GetMaximumFlow(), ComputeTheoreticalFlowOfPlace()); + } + flow->SetTheoreticalFlow(flowvalue); + } +} + +//------------------------------------------------------------------------------ +// Fire transition +//------------------------------------------------------------------------------ +void ContinuousTransition::WalkThrough(double duration) +{ + if (duration > 0.0) + FireContinuousTransition(duration); +} + +//------------------------------------------------------------------------------ +// Fire continuous transition +//------------------------------------------------------------------------------ +void ContinuousTransition::FireContinuousTransition(double duration) +{ + double quantity; + double curflow; + double weight; + Place *p; + + curflow = flow->GetCurrentFlow(); + + // not fireable transition + if ((curflow == 0.0) || (duration == 0.0)) + return; + + quantity = curflow * duration; + + // remove marks of the input places + for (int i=0; i<numberofarcs; i++){ + if (inputarcs[i] != 0){ + weight = inputarcs[i]; +// p = simulation->sbpn->GetPlace(i); + p = inputnodes[i]; + + switch (p->IsA()){ + case Continuous_pl : ((ContinuousPlace*)p)->ReduceMarks(weight * quantity); +// cout << "reducing from :" << i << " val: " << weight * quantity << endl; + break; + } + } + } + + // add marks of the output places + for (int i=0; i<numberofarcs; i++){ + if (outputarcs[i] != 0){ + weight = outputarcs[i]; +// p = simulation->sbpn->GetPlace(i); + p = outputnodes[i]; + + switch (p->IsA()){ + case Continuous_pl : ((ContinuousPlace*)p)->AddMarks(weight * quantity); +// cout << "adding to :" << i << " val: " << weight * quantity << endl; + break; + } + } + } +} + +//------------------------------------------------------------------------------ +// Print +//------------------------------------------------------------------------------ +void ContinuousTransition::Print(ostream &fout) +{ + fout << "Name: " << name << endl; + fout << " Type: " << "Continuous" << endl; + fout << " Flow: " << endl; + flow->Print(fout); + fout << " Arcs: " << endl; + PrintArcs(fout); +} + +//------------------------------------------------------------------------------ +// It writes the transition flows +//------------------------------------------------------------------------------ +void ContinuousTransition::Write(ostream &fout) +{ + fout << "Name: " << name << endl; + fout << " Type: " << "Continuous" << endl; + fout << " State: " << state << endl; + fout << " Current Flow: " << flow->GetCurrentFlow() << endl; + if (flow->GetSteadyFlow() != -1.0) + fout << " Steady Flow: " << flow->GetSteadyFlow() << endl; + +} + + +//------------------------------------------------------------------------------ +// It computes the theoretical flow taking into account the input places +// TODO verify flow when non place is fed +//------------------------------------------------------------------------------ +double ContinuousTransition::ComputeTheoreticalFlowOfPlace() +{ + double placeflow, f; + double placestate; + + Place *p; + + if (GetNumberOfInputArcs() == 0){ + return (flow->GetMaximumFlow()); + } + + placeflow = flow->GetMaximumFlow(); + + for (int i=0; i<numberofarcs; i++){ + if (inputarcs[i] != 0){ +// p = simulation->sbpn->GetPlace(i); + p = inputnodes[i]; + + switch (p->IsA()){ + case Continuous_pl : placestate = p->GetState(); + if (placestate == 0.5){ // place is fed + f = ((ContinuousPlace*)p)->ComputeFlowFedPlace(this); + placeflow = ComputeMinimumFlow(placeflow, f); + } + break; + } + } + } + return (placeflow); +} + +//========================RBF========Event================================= +// It returns the rbf event for each continuous transition: +//=========================================================================== +double ContinuousTransition::GetRBFEvent() +{ + double date; + double min_date = -1.0; + double weight; + double transitionflow; + Place *p; +// Transition *t; +// FiringQuantity *q; + double Zs; + double z; + + // q=t->GetFiringQuantity(); + Zs=firingquantity->GetSteadyFiringQuantity(); + z =firingquantity->GetCurrentFiringQuantity(); + + if (GetNumberOfOutputArcs() == 0){ + return (-1.0); + } + else if(z >= Zs){ + return (-1.0); + } + else{ + for (int i=0; i<numberofarcs; i++){ + if (outputarcs[i] != 0){ +// p = simulation->sbpn->GetPlace(i); + p = (Place*)outputnodes[i]; + + weight = outputarcs[i]; + // f=t->GetFlow(); + transitionflow=flow->GetCurrentFlow(); + switch (p->IsA()){ + case Continuous_pl : + date = (Zs-z) / transitionflow; // FreeSteadyMarkingQuantity= 0 in P^C + date += simulation->stime->GetCurrentDate(); + break; + case Batch_pl : + break; + } + } + if (date < min_date || min_date==-1.0){ + min_date= date; + } + } + return (min_date); + } + return (-1.0); +} +//----------------------------------------------------------------------------------- diff --git a/src/bpn/controllablebatch.cpp b/src/bpn/controllablebatch.cpp new file mode 100644 index 0000000000000000000000000000000000000000..470b17de68503e2e7e70a0a413348f124b8eb47a --- /dev/null +++ b/src/bpn/controllablebatch.cpp @@ -0,0 +1,404 @@ +//====================================================================================// +// // +// Controllable Batch class // +// // +//====================================================================================// +// This File: controllablebatch.cpp Language: C++ (xlC and CC) // +// Software: SIMULEAU // +//====================================================================================// +// Creation: 28/apr/16 by: Leonardo.Brenner@lsis.org // +// Last Change: 28/apr/16 by: Leonardo.Brenner@lsis.org // +//====================================================================================// +#include "simuleau.h" + +//------------------------------------------------------------------------------ +//------------------------------------------------------------------------------ +// Methods of the Triangular Batch class +//------------------------------------------------------------------------------ +//------------------------------------------------------------------------------ + +//------------------------------------------------------------------------------ +// Constructor +//------------------------------------------------------------------------------ +ControllableBatch::ControllableBatch():Batch() +{ + speed = 0.0; + state = Free_st; + behaviour = Free_behaviour; + evolvefunction = NULL; +} + +//------------------------------------------------------------------------------ +// Constructor +//------------------------------------------------------------------------------ +ControllableBatch::ControllableBatch(char *_name):Batch(_name) +{ + speed = 0.0; + state = Free_st; + behaviour = Free_behaviour; + evolvefunction = NULL; +} + +//------------------------------------------------------------------------------ +// Initialized constructor +//------------------------------------------------------------------------------ +ControllableBatch::ControllableBatch(double _length, double _density, double _position, double _speed):Batch(_length, _density, _position) +{ + speed = _speed; + state = Free_st; + behaviour = Free_behaviour; + evolvefunction = NULL; +} + +//------------------------------------------------------------------------------ +// Initialized constructor +//------------------------------------------------------------------------------ +ControllableBatch::ControllableBatch(double _inputflow, double _speed):Batch(_inputflow, _speed) +{ + speed = _speed; + state = Free_st; + behaviour = Free_behaviour; + evolvefunction = NULL; +} + +//------------------------------------------------------------------------------ +// Destructor +//------------------------------------------------------------------------------ +ControllableBatch::~ControllableBatch() +{ + +} + +//------------------------------------------------------------------------------ +// Copy +//------------------------------------------------------------------------------ +void ControllableBatch::Copy(const ControllableBatch &_controllablebatch) +{ + strcpy(name, _controllablebatch.name); + length = _controllablebatch.length; + density = _controllablebatch.density; + position = _controllablebatch.position; + outputflow = _controllablebatch.outputflow; + + speed = _controllablebatch.speed; + state = _controllablebatch.state; + behaviour = _controllablebatch.behaviour; + evolvefunction = _controllablebatch.evolvefunction; +} + +//------------------------------------------------------------------------------ +// IsEqual +//------------------------------------------------------------------------------ +int ControllableBatch::IsEqual(const ControllableBatch &_controllablebatch) +{ + if (length != _controllablebatch.length) + return 0; + if (density != _controllablebatch.density) + return 0; + if (position != _controllablebatch.position) + return 0; + if (speed != _controllablebatch.speed) + return 0; + return 1; +} + +//------------------------------------------------------------------------------ +// It sets a new speed +//------------------------------------------------------------------------------ +void ControllableBatch::SetSpeed(double _speed) +{ + speed = _speed; +} + +//------------------------------------------------------------------------------ +// It sets a new state +//------------------------------------------------------------------------------ +void ControllableBatch::SetState(ctrl_batch_state _state) +{ + state = _state; +} + +//------------------------------------------------------------------------------ +// It sets a new behaviour +//------------------------------------------------------------------------------ +void ControllableBatch::SetBehaviour(ctrl_batch_behaviour _behaviour) +{ + behaviour = _behaviour; +} + +//------------------------------------------------------------------------------ +// It returns the speed +//------------------------------------------------------------------------------ +double ControllableBatch::GetSpeed() +{ + return (speed); +} + +//------------------------------------------------------------------------------ +// It returns the batch flow +//------------------------------------------------------------------------------ +double ControllableBatch::GetFlow() +{ + return (speed * density); +} + +//------------------------------------------------------------------------------ +// It returns the state +//------------------------------------------------------------------------------ +ctrl_batch_state ControllableBatch::GetState() +{ + return (state); +} + +//------------------------------------------------------------------------------ +// It returns the state +//------------------------------------------------------------------------------ +ctrl_batch_state ControllableBatch::GetState(TriangularBatchPlace *tbp) +{ + double ratio = tbp->GetMaxFlow() / tbp->GetInstantaneousSpeed(); + + if ((density - ratio) < PRF::prf.Min_Err()) + state = Free_st; + else + state = Congested_st; + + return (state); +} + +//------------------------------------------------------------------------------ +// It returns the state name +//------------------------------------------------------------------------------ +char* ControllableBatch::GetStateName() +{ + switch (state) { + case No_st : return ("None"); + case Free_st : return ("Free"); + case Congested_st : return ("Congested"); + default : return ("None"); + } + +} + +//------------------------------------------------------------------------------ +// It returns the behaviour +//------------------------------------------------------------------------------ +ctrl_batch_behaviour ControllableBatch::GetBehaviour() +{ + return (behaviour); +} + +//------------------------------------------------------------------------------ +// It returns the behaviour name +//------------------------------------------------------------------------------ +char* ControllableBatch::GetBehaviourName() +{ + switch (behaviour) { + case No_behaviour : return ("None"); + case Free_behaviour : return ("Free"); + case Congesting_behaviour : return ("Congesting"); + case Uncongesting_behaviour : return ("Uncongesting"); + default : return ("None"); + } +} + +//------------------------------------------------------------------------------ +// It returns the behaviour +//------------------------------------------------------------------------------ +int ControllableBatch::IsOutputControllableBatch(BatchPlace *bp) +{ + if ((bp->GetLength() - position) < PRF::prf.Min_Err()) + return (1); + else + return (0); +} + +//------------------------------------------------------------------------------ +// It returns true if this batch is in contact with another batch by the front +//------------------------------------------------------------------------------ +int ControllableBatch::IsInContactWithByFront(ControllableBatch &cb) +{ + if (((cb.GetPosition() - cb.GetLength()) - GetPosition()) < PRF::prf.Min_Err()) + return (1); + else + return (0); +} + +//------------------------------------------------------------------------------ +// It returns true if this batch is in contact with another batch by the rear +//------------------------------------------------------------------------------ +int ControllableBatch::IsInContactWithByRear(ControllableBatch &cb) +{ + if (((GetPosition() - GetLength()) - cb.GetPosition()) < PRF::prf.Min_Err()) + return (1); + else + return (0); +} + +//------------------------------------------------------------------------------ +// It sets the function to be applied in the evolution +//------------------------------------------------------------------------------ +void ControllableBatch::SetEvolveFunction(EvolveFunction _func) +{ + evolvefunction = _func; +} + +//------------------------------------------------------------------------------ +// It calls the evolution function of the controllable batch +//------------------------------------------------------------------------------ +void ControllableBatch::Evolve(Simtime *_stime, TriangularBatchPlace *tbp, ControllableBatch *pcb, ControllableBatch *ncb) +{ + if(evolvefunction == NULL) + return; + + (this->*evolvefunction)(_stime, tbp, pcb, ncb); + evolvefunction = NULL; +} + +//------------------------------------------------------------------------------ +// It applies the free behaviour at this controllable batch +//------------------------------------------------------------------------------ +void ControllableBatch::EvolveInFreeBehaviour(Simtime *_stime, TriangularBatchPlace *tbp, ControllableBatch *pcb, ControllableBatch *ncb) +{ + double move = (speed * _stime->StepTime()); + + if ((position == 0.0) && (length == 0.0)){ //new batch, input in free behaviour + length = move; + position = move; + } + else{ + if ((tbp->GetLength() - position) < PRF::prf.Min_Err()){ + length = length - move; + position = tbp->GetLength(); + } + else{ + position = position + move; + } + } +} + +//------------------------------------------------------------------------------ +// It applies the output in congestion behaviour at this controllable batch +//------------------------------------------------------------------------------ +void ControllableBatch::EvolveInCongestingOutputBehaviour(Simtime *_stime, TriangularBatchPlace *tbp, ControllableBatch *pcb, ControllableBatch *ncb) +{ + double downflow = tbp->GetOutputTransitonsFlow(); + double congestiondensity = tbp->GetCongestionDensity(); + + length = length - ((downflow/density) * _stime->StepTime()); +} + + +//------------------------------------------------------------------------------ +// It applies the free to congestion behaviour (congestion batch case) at this controllable batch +//------------------------------------------------------------------------------ +void ControllableBatch::EvolveInFreeToCongestingBehaviourCongBatch(Simtime *_stime, TriangularBatchPlace *tbp, ControllableBatch *pcb, ControllableBatch *ncb) +{ + double vr = ncb->GetSpeed(); + double dr = ncb->GetDensity(); + double downflow = tbp->GetOutputTransitonsFlow(); + double drp = density; + + length = (((vr * dr) - downflow) / (drp - dr)) *_stime->StepTime(); +} + +//------------------------------------------------------------------------------ +// It applies the free to congestion behaviour (free batch case) at this controllable batch +//------------------------------------------------------------------------------ +void ControllableBatch::EvolveInFreeToCongestingBehaviourFreeBatch(Simtime *_stime, TriangularBatchPlace *tbp, ControllableBatch *pcb, ControllableBatch *ncb) +{ + double vr = speed; + double dr = density; + double downflow = tbp->GetOutputTransitonsFlow(); + double drp = pcb->GetDensity(); + + position = position + ((downflow - vr * dr) / (drp - dr)) *_stime->StepTime(); + + length = length + ((downflow - vr * drp) / (drp - dr)) *_stime->StepTime(); +} + +//------------------------------------------------------------------------------ +// It applies the free to congestion behaviour to this batch in the middle of the place with +// contact with another batch (congestion batch case) +//------------------------------------------------------------------------------ +void ControllableBatch::EvolveInFreeToCongestingBehaviourMiddlePlaceWithContactCongBatch(Simtime *_stime, TriangularBatchPlace *tbp, ControllableBatch *pcb, ControllableBatch *ncb) +{ + double vrp = speed; + double vr = ncb->GetSpeed(); + double drp = density; + double dr = ncb->GetDensity(); + + position = position + vrp *_stime->StepTime(); + + length = (dr / (dr - drp)) * (vrp - vr) *_stime->StepTime(); +} + +//------------------------------------------------------------------------------ +// It applies the free to congestion behaviour to this batch in the middle of the place with +// contact with another batch (free batch case) +//------------------------------------------------------------------------------ +void ControllableBatch::EvolveInFreeToCongestingBehaviourMiddlePlaceWithContactFreeBatch(Simtime *_stime, TriangularBatchPlace *tbp, ControllableBatch *pcb, ControllableBatch *ncb) +{ + double vrp = pcb->GetSpeed(); + double vr = speed; + double drp = pcb->GetDensity(); + double dr = density; + + position = position + ((vrp*drp - vr*dr) / (drp - dr)) * _stime->StepTime(); + +// length = length - (drp / (dr - drp)) * (vrp - vr) * _stime->StepTime(); + length = length + (((vrp*drp) - vr * drp) / (drp - dr)) *_stime->StepTime(); +} + +//------------------------------------------------------------------------------ +// It applies the uncongestion behaviour to an output batch +//------------------------------------------------------------------------------ +void ControllableBatch::EvolveInUncongestingOutputBehaviour(Simtime *_stime, TriangularBatchPlace *tbp, ControllableBatch *pcb, ControllableBatch *ncb) +{ + double Vi = tbp->GetInstantaneousSpeed(); + + length = length - Vi * _stime->StepTime(); +} + +//------------------------------------------------------------------------------ +// It applies the uncongestion to free behaviour to this batch in the middle of the place (congestion batch case) +//------------------------------------------------------------------------------ +void ControllableBatch::EvolveInUncongestingToFreeBehaviourCongBatch(Simtime *_stime, TriangularBatchPlace *tbp, ControllableBatch *pcb, ControllableBatch *ncb) +{ + double Vi = tbp->GetInstantaneousSpeed(); + double d_cri = tbp->GetCriticalDensity(); + double vr = speed; + double dr = density; + + position = position + ((Vi*d_cri) - (vr*dr)) / (d_cri-dr) * _stime->StepTime(); + length = length - ((Vi - vr) * d_cri / (dr - d_cri)) * _stime->StepTime(); +} + +//------------------------------------------------------------------------------ +// It applies the uncongestion to free behaviour to this batch in the middle of the place (Free batch case) +//------------------------------------------------------------------------------ +void ControllableBatch::EvolveInUncongestingToFreeBehaviourFreeBatch(Simtime *_stime, TriangularBatchPlace *tbp, ControllableBatch *pcb, ControllableBatch *ncb) +{ + double Vi = tbp->GetInstantaneousSpeed(); + double d_cri = tbp->GetCriticalDensity(); + double vr = ncb->GetSpeed(); + double dr = ncb->GetDensity(); + + position = position + Vi * _stime->StepTime(); + length = ((Vi - vr) * dr / (dr - d_cri)) * _stime->StepTime(); +} + +//------------------------------------------------------------------------------ +// Print +//------------------------------------------------------------------------------ +void ControllableBatch::Print(ostream &fout) +{ + fout << " (" << length << ", " << density << ", " << position << ", " << speed << ") - State: " << GetStateName() << " - Behaviour: " << GetBehaviourName() << endl; +} + +//------------------------------------------------------------------------------ +// Write +//------------------------------------------------------------------------------ +void ControllableBatch::Write(ostream &fout) +{ + fout << " (" << length << ", " << density << ", " << position << ", " << speed << ") - State: " << GetStateName() << " - Behaviour: " << GetBehaviourName() << endl; +} diff --git a/src/bpn/discreteplace.cpp b/src/bpn/discreteplace.cpp new file mode 100644 index 0000000000000000000000000000000000000000..89d8990799f93893e6f21eb3ad7c0f95454c567c --- /dev/null +++ b/src/bpn/discreteplace.cpp @@ -0,0 +1,233 @@ +//====================================================================================// +// // +// Discrete place classes inherit of place class // +// // +//====================================================================================// +// This File: discreteplace.cpp Language: C++ (xlC and CC) // +// Software: SIMULEAU // +//====================================================================================// +// Creation: 22/apr/16 by: Leonardo.Brenner@lsis.org // +// Last Change: 22/apr/16 by: Leonardo.Brenner@lsis.org // +//====================================================================================// +#include "simuleau.h" + + +//------------------------------------------------------------------------------ +//------------------------------------------------------------------------------ +// Methods of the Discrete Place class +//------------------------------------------------------------------------------ +//------------------------------------------------------------------------------ + +//------------------------------------------------------------------------------ +// Constructor +//------------------------------------------------------------------------------ +DiscretePlace::DiscretePlace():Place() +{ + reservedmarks = 0; + nonreservedmarks = 0; +} + +//------------------------------------------------------------------------------ +// Named Constructor +//------------------------------------------------------------------------------ +DiscretePlace::DiscretePlace(simuleau_name _name):Place(_name) +{ + reservedmarks = 0; + nonreservedmarks = 0; +} + + +//------------------------------------------------------------------------------ +// Destructor +//------------------------------------------------------------------------------ +DiscretePlace::~DiscretePlace() +{ + +} + + +//------------------------------------------------------------------------------ +// Copy +//------------------------------------------------------------------------------ +void DiscretePlace::Copy(const DiscretePlace * _place) +{ + TransferNode(_place); + + marks = _place->marks; + initialmarks = _place->initialmarks; + steadymarks = _place->steadymarks; + reservedmarks = _place->reservedmarks; + nonreservedmarks = _place->nonreservedmarks; + + conflict = _place->conflict; + structuralconflict = _place->structuralconflict; + +} + +//------------------------------------------------------------------------------ +// It set the initial marking of the place +//------------------------------------------------------------------------------ +void DiscretePlace::SetInitialMarking(int m) +{ + marks = initialmarks = m; + reservedmarks = 0; + nonreservedmarks = m; +} + +//------------------------------------------------------------------------------ +// It set the steady marking of the place +//------------------------------------------------------------------------------ +void DiscretePlace::SetSteadyMarking(int m) +{ + steadymarks = m; +} + +//------------------------------------------------------------------------------ +// It changes the place marks +//------------------------------------------------------------------------------ +void DiscretePlace::ChangeMarks(int m) +{ + marks = nonreservedmarks = m; + if (abs(m) < PRF::prf.Min_Err()){ + marks = nonreservedmarks = 0; + } +} + + +//------------------------------------------------------------------------------ +// It reserves the place marks +//------------------------------------------------------------------------------ +void DiscretePlace::ReserveMarks(int m) +{ + reservedmarks+=m; + nonreservedmarks = marks - reservedmarks; +} + + +//------------------------------------------------------------------------------ +// It removes the reserved marks in the place +//------------------------------------------------------------------------------ +void DiscretePlace::RemoveReservedMarks(int m) +{ + reservedmarks-=m; + marks = nonreservedmarks + reservedmarks; +} + +//------------------------------------------------------------------------------ +// It adds the marks to the place +//------------------------------------------------------------------------------ +void DiscretePlace::AddMarks(int m) +{ + nonreservedmarks += m; + marks += m; +} + +//------------------------------------------------------------------------------ +// Compute the state of the discrete place +//------------------------------------------------------------------------------ +void DiscretePlace::ComputeState() +{ + int j = 0; + + if (reservedmarks != 0){ + state = 0.5; + } + else{ + if (GetNumberOfOutputArcs() == 0){ + state = 1.0; + } + else{ + for (int i=0; i<numberofarcs; i++){ + if (outputarcs[i] != 0.0){ + if (nonreservedmarks < outputarcs[i]){ +// cout << "nonreservedmarks: " << nonreservedmarks << " outputarcs: " << outputarcs[i] << endl; + j++; + } + } + } + if (j == 0) + state = 1.0; + else + state = 0.0; + } + } +} + +//------------------------------------------------------------------------------ +// It verifies effectif conflits +//------------------------------------------------------------------------------ +int DiscretePlace::VerifyConflict() +{ + int necessarymarks = 0; + int numberoftransitionsinconflict = 0; + Transition *t; + + conflict = 0; + + if (structuralconflict){ + if (GetNumberOfOutputArcs() != 0){ + for (int i=0; i<numberofarcs; i++){ + if (outputarcs[i] != 0){ + t = outputnodes[i]; + //t = simulation->sbpn->GetTransition(i); + if ((t->GetState()==1) && (t->IsA() == Discrete_tr)) { + necessarymarks+= outputarcs[i]; + numberoftransitionsinconflict++; + } + } + } + +/* Ancienne version a conserver + represente le vrai conflit effectif + c-a-d au moins 2 trans aval validees + avec marquage de la place necessaire pour les franchissements + mais actuellement le simulateur ne peut traiter ce cas !!!! + if (marqueNecessaire <= marqueNonReservee) + conflitEffec =0; + else + conflitEffec =1; + */ + + if (numberoftransitionsinconflict > 1){ + if (necessarymarks <= nonreservedmarks) + conflict = 0; + else + conflict = 1; + + return (conflict); + } + } + } + return (0); +} + + +//------------------------------------------------------------------------------ +// Print +//------------------------------------------------------------------------------ +void DiscretePlace::Print(ostream &fout) +{ + fout << "Name: " << name << endl; + fout << " Type: " << "Discrete" << endl; + fout << " Marks: " << marks << endl; + fout << " Initial Marks: " << initialmarks << endl; + if (steadymarks != 0) + fout << " Steady Marks: " << steadymarks << endl; + fout << " Reserved Marks: " << reservedmarks << endl; + fout << " Non Reserved Marks: " << nonreservedmarks << endl; + fout << " Arcs: " << endl; + PrintArcs(fout); +} + +//------------------------------------------------------------------------------ +// Write +//------------------------------------------------------------------------------ +void DiscretePlace::Write(ostream &fout) +{ + fout << "Name: " << name << endl; + fout << " Type: " << "Discrete" << endl; + fout << " Marks: " << marks << endl; + fout << " Reserved Marks: " << reservedmarks << endl; +// if (steadymarks != 0) +// fout << " Steady Marks: " << steadymarks << endl; +} diff --git a/src/bpn/discretetransition.cpp b/src/bpn/discretetransition.cpp new file mode 100644 index 0000000000000000000000000000000000000000..8143ed1f97164072b3599e097ce0613030ba1cc5 --- /dev/null +++ b/src/bpn/discretetransition.cpp @@ -0,0 +1,225 @@ +//====================================================================================// +// // +// Discrete transition classes inherit of transition class // +// // +//====================================================================================// +// This File: discretetransition.cpp Language: C++ (xlC and CC) // +// Software: SIMULEAU // +//====================================================================================// +// Creation: 22/apr/16 by: Leonardo.Brenner@lsis.org // +// Last Change: 22/apr/16 by: Leonardo.Brenner@lsis.org // +//====================================================================================// +#include "simuleau.h" + +//------------------------------------------------------------------------------ +//------------------------------------------------------------------------------ +// Methods of the Discrete Transition class +//------------------------------------------------------------------------------ +//------------------------------------------------------------------------------ + +//------------------------------------------------------------------------------ +// Constructor +//------------------------------------------------------------------------------ +DiscreteTransition::DiscreteTransition() +{ + +} + +//------------------------------------------------------------------------------ +// Initialized Constructor +//------------------------------------------------------------------------------ +DiscreteTransition::DiscreteTransition(simuleau_name _name, double _time, double _steadytime):Transition(_name) +{ + time = _time; + steadytime = _steadytime; + enableddate = -_time; + +} + +//------------------------------------------------------------------------------ +// Destructor +//------------------------------------------------------------------------------ +DiscreteTransition::~DiscreteTransition() +{ + +} + +//------------------------------------------------------------------------------ +// Copy +//------------------------------------------------------------------------------ +void DiscreteTransition::Copy(const DiscreteTransition *_transition) +{ + TransferNode(_transition); + time = _transition->time; // transition time + steadytime = _transition->steadytime; // transition steady time + enableddate = _transition->enableddate; // enabled date + firingquantity = new FiringQuantity; + firingquantity->Copy(_transition->firingquantity); +} + +//------------------------------------------------------------------------------ +// Initializes enabled date +//------------------------------------------------------------------------------ +void DiscreteTransition::InitEnabledDate() +{ + enableddate = -1.0; +} + + +//------------------------------------------------------------------------------ +// Set enabled date +//------------------------------------------------------------------------------ +void DiscreteTransition::SetEnabledDate(double _date) +{ + enableddate = _date; +} + +//------------------------------------------------------------------------------ +// Reserve marks in input places of the transition +//------------------------------------------------------------------------------ +void DiscreteTransition::ReserveMarksInputPlaces() +{ + double weight; + Place *p; + + for (int i=0; i<numberofarcs; i++){ + if (inputarcs[i] != 0){ + weight = inputarcs[i]; +// p = simulation->sbpn->GetPlace(i); + p = inputnodes[i]; + + switch (p->IsA()){ + case Discrete_pl : ((DiscretePlace*)p)->ReserveMarks((int)weight); +// cout << "\n\n\n discrete \n\n\n"; + break; + case Continuous_pl : ((ContinuousPlace*)p)->ReserveMarks(weight); +// cout << "\n\n\n continuous \n\n\n"; + + break; + } + } + } +} + + +//------------------------------------------------------------------------------ +// Get time +//------------------------------------------------------------------------------ +double DiscreteTransition::GetTime() +{ + return (time); +} + +//------------------------------------------------------------------------------ +// Get enabled date +//------------------------------------------------------------------------------ +double DiscreteTransition::GetEnabledDate() +{ + return (enableddate); +} + + +//------------------------------------------------------------------------------ +// Compute states +//------------------------------------------------------------------------------ +void DiscreteTransition::ComputeState() +{ + double transstate = 1.0; // enabled + double placestate; + Place *p; + + if (GetNumberOfInputArcs() == 0){ + if ((enableddate + time) > simulation->stime->GetCurrentDate()){ + state = 0.5; // enable transition but not fired + } + else { + state = 1.0; // transition not enable + } + } + else{ + for (int i=0; i<numberofarcs; i++){ + if (inputarcs[i] != 0){ +// p = simulation->sbpn->GetPlace(i); + p = inputnodes[i]; + placestate = p->GetState(); +// cout << "\n==========================\nplace: " << placestate << "\n==========================\n"; + transstate = min(transstate, placestate); + } + } + state = transstate; + } +// cout << "\n==========================\nState: " << state << "\n==========================\n"; +} + +//------------------------------------------------------------------------------ +// Fire transition +//------------------------------------------------------------------------------ +void DiscreteTransition::WalkThrough(double duration) +{ + if (duration < 0.0) + FireDiscreteTransition(); +} + +//------------------------------------------------------------------------------ +// Fire discrete transition +//------------------------------------------------------------------------------ +void DiscreteTransition::FireDiscreteTransition() +{ + double weight; + Place *p; + + // remove marks of the input places + for (int i=0; i<numberofarcs; i++){ + if (inputarcs[i] != 0){ + weight = inputarcs[i]; +// p = simulation->sbpn->GetPlace(i); + p = inputnodes[i]; + + switch (p->IsA()){ + case Discrete_pl : ((DiscretePlace*)p)->RemoveReservedMarks((int)weight); +// cout << "\n\n\n discrete \n\n\n"; + break; + case Continuous_pl : ((ContinuousPlace*)p)->RemoveReservedMarks(weight); +// cout << "\n\n\n continuous \n\n\n"; + + break; + } + } + } + + // add marks of the output places + for (int i=0; i<numberofarcs; i++){ + if (outputarcs[i] != 0){ + weight = outputarcs[i]; +// p = simulation->sbpn->GetPlace(i); + p = outputnodes[i]; + + switch (p->IsA()){ + case Discrete_pl : ((DiscretePlace*)p)->AddMarks((int)weight); +// cout << "\n\n\n discrete \n\n\n"; + break; + case Continuous_pl : ((ContinuousPlace*)p)->AddMarks(weight); +// cout << "\n\n\n continuous \n\n\n"; + + break; + } + } + } + InitEnabledDate(); +} + +//------------------------------------------------------------------------------ +// Print +//------------------------------------------------------------------------------ +void DiscreteTransition::Print(ostream &fout) +{ + fout << "Name: " << name << endl; + fout << " Type: " << "Discrete" << endl; + fout << " Time: " << time << endl; + if (steadytime!=0.0) + fout << " Steady Time: " << time << endl; + + fout << " Arcs: " << endl; + PrintArcs(fout); +} + diff --git a/src/bpn/firingquantity.cpp b/src/bpn/firingquantity.cpp new file mode 100644 index 0000000000000000000000000000000000000000..f76723ade5c1814e104b9540d74f97e853ed1c5b --- /dev/null +++ b/src/bpn/firingquantity.cpp @@ -0,0 +1,98 @@ +//====================================================================================// +// // +// FiringQuantity class // +// // +//====================================================================================// +// This File: flow.cpp Language: C++ (xlC and CC) // +// Software: SIMULEAU // +//====================================================================================// +// Creation: 29/apr/16 by: Leonardo.Brenner@lsis.org // +// Last Change: 29/apr/16 by: Leonardo.Brenner@lsis.org // +//====================================================================================// +#include "simuleau.h" + +//------------------------------------------------------------------------------ +// Constructor +//------------------------------------------------------------------------------ +FiringQuantity::FiringQuantity() +{ + firingquantity=steadyfiringquantity=currentfiringquantity = 0.0; +} + +//------------------------------------------------------------------------------ +// Destructor +//------------------------------------------------------------------------------ +FiringQuantity::~FiringQuantity() +{ + //dtor +} + +//------------------------------------------------------------------------------ +// Copy +//------------------------------------------------------------------------------ +void FiringQuantity::Copy(const FiringQuantity *_firingquantity) +{ + steadyfiringquantity = _firingquantity->steadyfiringquantity; + currentfiringquantity = _firingquantity->currentfiringquantity; +} + +//------------------------------------------------------------------------------ +// Set up all firingquanties +//------------------------------------------------------------------------------ +void FiringQuantity::SetAllFiringQuantities(double _firingquantity) +{ + steadyfiringquantity=currentfiringquantity = _firingquantity; +} + +//------------------------------------------------------------------------------ +// Set up the intial flow +//------------------------------------------------------------------------------ +//void Flow::SetInitialFlow(double _flow) +//{ +// initialflow = _flow; +//} + +//------------------------------------------------------------------------------ +// Set up the current firingquantity +//------------------------------------------------------------------------------ +void FiringQuantity::SetCurrentFiringQuantity(double _firingquantity) +{ + currentfiringquantity= _firingquantity; +} + + +//------------------------------------------------------------------------------ +// Set up the steady firingquantity +//------------------------------------------------------------------------------ +void FiringQuantity::SetSteadyFiringQuantity(double _firingquantity) +{ + steadyfiringquantity= _firingquantity; +} + +//------------------------------------------------------------------------------ +// Return the current firing quantity +//------------------------------------------------------------------------------ +double FiringQuantity::GetCurrentFiringQuantity() +{ + return (currentfiringquantity); +} + +//------------------------------------------------------------------------------ +// Return the steady firing quantity +//------------------------------------------------------------------------------ +double FiringQuantity::GetSteadyFiringQuantity() +{ + return (steadyfiringquantity); +} + +//------------------------------------------------------------------------------ +// Print +//------------------------------------------------------------------------------ +void FiringQuantity::Print(ostream &fout) +{ + fout << " Current : " << currentfiringquantity << endl; + // fout << " Initial : " << initialflow << endl; + if (steadyfiringquantity!=-1.0) + fout << " Steady : " << steadyfiringquantity << endl << endl; + +} diff --git a/src/bpn/firingquantity.h b/src/bpn/firingquantity.h new file mode 100644 index 0000000000000000000000000000000000000000..a614427c601fc47d37f43f62ca918302882e80e3 --- /dev/null +++ b/src/bpn/firingquantity.h @@ -0,0 +1,45 @@ +//====================================================================================// +// // +// Firingquantity class // +// // +//====================================================================================// +// This File: firingquantity.h Language: C++ (xlC and CC) // +// Software: SIMULEAU // +//====================================================================================// +// Creation: 29/apr/16 by: Leonardo.Brenner@lsis.org // +// Last Change: 29/apr/16 by: Leonardo.Brenner@lsis.org // +//====================================================================================// +#ifndef FIRINGQUANTITY_H +#define FIRINGQUANTITY_H + +class FiringQuantity +{ + public: + FiringQuantity(); + virtual ~FiringQuantity(); + + void Copy(const FiringQuantity *_firingquantity); + + // input functions + void SetAllFiringQuantities(double _firingquantity); + void SetCurrentFiringQuantity(double _firingquantity); + void SetSteadyFiringQuantity(double _firingquantity); + + + // output functions + double GetCurrentFiringQuantity(); + double GetSteadyFiringQuantity(); + + + //print + void Print(ostream &fout); + + protected: + double firingquantity; + double currentfiringquantity; + double steadyfiringquantity; + + private: +}; + +#endif // FIRINGQUANTITY_H diff --git a/src/bpn/flow.cpp b/src/bpn/flow.cpp new file mode 100644 index 0000000000000000000000000000000000000000..399d308f8aba8737c1799663c0ad62ccfb53918d --- /dev/null +++ b/src/bpn/flow.cpp @@ -0,0 +1,136 @@ +//====================================================================================// +// // +// Flow class // +// // +//====================================================================================// +// This File: flow.cpp Language: C++ (xlC and CC) // +// Software: SIMULEAU // +//====================================================================================// +// Creation: 29/apr/16 by: Leonardo.Brenner@lsis.org // +// Last Change: 29/apr/16 by: Leonardo.Brenner@lsis.org // +//====================================================================================// +#include "simuleau.h" + +//------------------------------------------------------------------------------ +// Constructor +//------------------------------------------------------------------------------ +Flow::Flow() +{ + maximumflow = theoreticalflow = currentflow = initialflow = steadyflow = -1.0; +} + +//------------------------------------------------------------------------------ +// Destructor +//------------------------------------------------------------------------------ +Flow::~Flow() +{ + //dtor +} + + +//------------------------------------------------------------------------------ +// Copy +//------------------------------------------------------------------------------ +void Flow::Copy(const Flow *_flow) +{ + maximumflow = _flow->maximumflow; + theoreticalflow = _flow->theoreticalflow; + currentflow = _flow->currentflow; + initialflow = _flow->initialflow; + steadyflow = _flow->steadyflow; + +} + +//------------------------------------------------------------------------------ +// Set up all flows +//------------------------------------------------------------------------------ +void Flow::SetAllFlows(double _flow) +{ + maximumflow = theoreticalflow = currentflow = initialflow = steadyflow = _flow; +} + +//------------------------------------------------------------------------------ +// Set up the intial flow +//------------------------------------------------------------------------------ +void Flow::SetInitialFlow(double _flow) +{ + initialflow = _flow; +} + +//------------------------------------------------------------------------------ +// Set up the current flow +//------------------------------------------------------------------------------ +void Flow::SetCurrentFlow(double _flow) +{ + currentflow = _flow; +} + +//------------------------------------------------------------------------------ +// Set up the theoretical flow +//------------------------------------------------------------------------------ +void Flow::SetTheoreticalFlow(double _flow) +{ + theoreticalflow = _flow; +} + +//------------------------------------------------------------------------------ +// Set up the theoretical flow +//------------------------------------------------------------------------------ +void Flow::SetMaximumFlow(double _flow) +{ + maximumflow = _flow; +} + +//------------------------------------------------------------------------------ +// Set up the steady flow +//------------------------------------------------------------------------------ +void Flow::SetSteadyFlow(double _flow) +{ + steadyflow = _flow; +} + +//------------------------------------------------------------------------------ +// Return the current flow +//------------------------------------------------------------------------------ +double Flow::GetCurrentFlow() +{ + return (currentflow); +} + +//------------------------------------------------------------------------------ +// Return the theoretical flow +//------------------------------------------------------------------------------ +double Flow::GetTheoreticalFlow() +{ + return (theoreticalflow); +} + +//------------------------------------------------------------------------------ +// Return the maximum flow +//------------------------------------------------------------------------------ +double Flow::GetMaximumFlow() +{ + return (maximumflow); +} + +//------------------------------------------------------------------------------ +// Return the steady flow +//------------------------------------------------------------------------------ +double Flow::GetSteadyFlow() +{ + return (steadyflow); +} + +//------------------------------------------------------------------------------ +// Print +//------------------------------------------------------------------------------ +void Flow::Print(ostream &fout) +{ + fout << " Maximum : " << maximumflow << endl; + fout << " Theoretical : " << theoreticalflow << endl; + fout << " Current : " << currentflow << endl; + fout << " Initial : " << initialflow << endl; + if (steadyflow!=-1.0) + fout << " Steady : " << steadyflow << endl << endl; + +} diff --git a/src/bpn/flow.h b/src/bpn/flow.h new file mode 100644 index 0000000000000000000000000000000000000000..a86a2b22c2c80bf46b0927455f5e9a74dc5d5f9f --- /dev/null +++ b/src/bpn/flow.h @@ -0,0 +1,52 @@ +//====================================================================================// +// // +// Flow class // +// // +//====================================================================================// +// This File: flow.h Language: C++ (xlC and CC) // +// Software: SIMULEAU // +//====================================================================================// +// Creation: 29/apr/16 by: Leonardo.Brenner@lsis.org // +// Last Change: 29/apr/16 by: Leonardo.Brenner@lsis.org // +//====================================================================================// +#ifndef FLOW_H +#define FLOW_H + +class Flow +{ + public: + Flow(); + virtual ~Flow(); + + void Copy(const Flow *_flow); + + // input functions + void SetAllFlows(double _flow); + void SetInitialFlow(double _flow); + void SetCurrentFlow(double _flow); + void SetTheoreticalFlow(double _flow); + void SetMaximumFlow(double _flow); + void SetSteadyFlow(double _flow); + + + // output functions + double GetCurrentFlow(); + double GetTheoreticalFlow(); + double GetMaximumFlow(); + double GetSteadyFlow(); + + + //print + void Print(ostream &fout); + + protected: + double maximumflow; + double theoreticalflow; + double currentflow; + double initialflow; + double steadyflow; + + private: +}; + +#endif // FLOW_H diff --git a/src/bpn/node.cpp b/src/bpn/node.cpp new file mode 100644 index 0000000000000000000000000000000000000000..305ea8cccf17c5515c19cb22097e2ecf61f8d129 --- /dev/null +++ b/src/bpn/node.cpp @@ -0,0 +1,274 @@ +//====================================================================================// +// // +// Node class // +// // +//====================================================================================// +// This File: node.cpp Language: C++ (xlC and CC) // +// Software: SIMULEAU // +//====================================================================================// +// Creation: 21/apr/16 by: Leonardo.Brenner@lsis.org // +// Last Change: 21/apr/16 by: Leonardo.Brenner@lsis.org // +//====================================================================================// +#include "simuleau.h" + +//------------------------------------------------------------------------------ +// Constructor +//------------------------------------------------------------------------------ +Node::Node() +{ + numberofarcs = 0; // number of input arcs to this node + inputarcs = NULL; // array of input arcs + inputnodes = NULL; // array of input nodes + outputarcs = NULL; // array of output arcs + outputnodes = NULL; // array of output nodes + + strcpy(name,""); // node name + state = No_state; // node state + +} + +//------------------------------------------------------------------------------ +// Named constructor +//------------------------------------------------------------------------------ +Node::Node(simuleau_name _name) +{ + numberofarcs = 0; // number of output arcs from this node + inputarcs = NULL; // array of input arcs + inputnodes = NULL; // array of input nodes + outputarcs = NULL; // array of output arcs + outputnodes = NULL; // array of output nodes + + strcpy(name,_name); // node name + state = 0.0; // node state +} + + +//------------------------------------------------------------------------------ +// Destructor +//------------------------------------------------------------------------------ +Node::~Node() +{ + if (inputarcs) + delete [] inputarcs; + if (inputnodes) + delete [] inputnodes; + if (outputarcs) + delete [] outputarcs; + if (outputnodes) + delete [] outputnodes; +} + +//------------------------------------------------------------------------------ +// Copy +//------------------------------------------------------------------------------ +void Node::Copy(const Node *_node) +{ + strcpy(name,_node->name); // node name + state = _node->state; // node state + numberofarcs = _node->numberofarcs; // number of arcs (places or transitions) + + if (numberofarcs > 0){ + inputarcs = new double [numberofarcs]; + inputnodes = new Node* [numberofarcs]; + for (int i=0; i<numberofarcs; i++){ + inputarcs[i] = _node->inputarcs[i]; // 0 means this arc is not used + inputnodes[i] = _node->inputnodes[i]; + } + + outputarcs = new double [numberofarcs]; + outputnodes = new Node* [numberofarcs]; + for (int i=0; i<numberofarcs; i++){ + outputarcs[i] = _node->outputarcs[i]; // 0 means this arc is not used + outputnodes[i] = _node->outputnodes[i]; + } + } +} + + +//------------------------------------------------------------------------------ +// It alloc the array of input/output arcs +//------------------------------------------------------------------------------ +int Node::AllocArcs(int n) +{ + numberofarcs = n; + inputarcs = new double [n]; + inputnodes = new Node* [n]; + for (int i=0; i<n; i++){ + inputarcs[i] = 0; // 0 means this arc is not used + inputnodes[i] = NULL; + } + + outputarcs = new double [n]; + outputnodes = new Node* [n]; + for (int i=0; i<n; i++){ + outputarcs[i] = 0; // 0 means this arc is not used + outputnodes[i] = 0; + } +} + +//------------------------------------------------------------------------------ +// It adds an input arc in the positin pos with weight +//------------------------------------------------------------------------------ +int Node::AddInputArc(int pos, double weight) +{ + inputarcs[pos] = weight; +} + +//------------------------------------------------------------------------------ +// It adds an output arc in the positin pos with weight +//------------------------------------------------------------------------------ +int Node::AddOutputArc(int pos, double weight) +{ + outputarcs[pos] = weight; +} + +//------------------------------------------------------------------------------ +// set input node pointes +//------------------------------------------------------------------------------ +int Node::AddInputNodes(Node **nodes) +{ + for (int i=0; i<numberofarcs; i++){ + if (inputarcs[i] != 0.0) + inputnodes[i] = nodes[i]; + else + inputnodes[i] = NULL; + } +} + + + +//------------------------------------------------------------------------------ +// set output node pointes +//------------------------------------------------------------------------------ +int Node::AddOutputNodes(Node **nodes) +{ + for (int i=0; i<numberofarcs; i++){ + if (outputarcs[i] != 0.0) + outputnodes[i] = nodes[i]; + else + outputnodes[i] = NULL; + } +} + +//------------------------------------------------------------------------------ +// set node state +//------------------------------------------------------------------------------ +void Node::SetState(double _state) +{ + state = _state; +} + + +//------------------------------------------------------------------------------ +// It get the node name +//------------------------------------------------------------------------------ +char* Node::GetName() +{ + return (name); +} + +//------------------------------------------------------------------------------ +// It get the current node state +//------------------------------------------------------------------------------ +double Node::GetState() +{ + return (state); +} + +//------------------------------------------------------------------------------ +// get the number of input arc different of 0 +//------------------------------------------------------------------------------ +int Node::GetNumberOfInputArcs() +{ + int n = 0; + + for (int i=0; i<numberofarcs; i++){ + if (inputarcs[i] != 0) + n++; + } + return (n); +} + +//------------------------------------------------------------------------------ +// get the number of Output arc different of 0 +//------------------------------------------------------------------------------ +int Node::GetNumberOfOutputArcs() +{ + int n = 0; + + for (int i=0; i<numberofarcs; i++){ + if (outputarcs[i] != 0) + n++; + } + return (n); +} + +//------------------------------------------------------------------------------ +// get the weight of an input arc +//------------------------------------------------------------------------------ +double Node::GetWeightOfInputArc(int _arc) +{ + return (inputarcs[_arc]); +} + +//------------------------------------------------------------------------------ +// get the weight of an output arc +//------------------------------------------------------------------------------ +double Node::GetWeightOfOutputArc(int _arc) +{ + return (outputarcs[_arc]); +} + +//------------------------------------------------------------------------------ +// Print +//------------------------------------------------------------------------------ +void Node::Print(ostream &fout) +{ + fout << "Name: " << name << endl; + PrintArcs(fout); +} + + +//------------------------------------------------------------------------------ +// Print arcs +//------------------------------------------------------------------------------ +void Node::PrintArcs(ostream &fout) +{ + for (int i=0; i<numberofarcs; i++){ + if (outputarcs[i]){ + fout << " to " << outputnodes[i]->GetName() << " : " << outputarcs[i] << endl; + } + } + + for (int i=0; i<numberofarcs; i++){ + if (inputarcs[i]) + fout << " from " << inputnodes[i]->GetName() << " : " << inputarcs[i] << endl; + } + fout << endl; +} + +//------------------------------------------------------------------------------ +// Transfer node informations +//------------------------------------------------------------------------------ +void Node::TransferNode(const Node *_node) +{ + strcpy(name,_node->name); // node name + state = _node->state; // node state + numberofarcs = _node->numberofarcs; // number of arcs (places or transitions) + + if (numberofarcs > 0){ + inputarcs = new double [numberofarcs]; + inputnodes = new Node* [numberofarcs]; + for (int i=0; i<numberofarcs; i++){ + inputarcs[i] = _node->inputarcs[i]; // 0 means this arc is not used + inputnodes[i] = _node->inputnodes[i]; + } + + outputarcs = new double [numberofarcs]; + outputnodes = new Node* [numberofarcs]; + for (int i=0; i<numberofarcs; i++){ + outputarcs[i] = _node->outputarcs[i]; // 0 means this arc is not used + outputnodes[i] = _node->outputnodes[i]; + } + } +} diff --git a/src/bpn/node.h b/src/bpn/node.h new file mode 100644 index 0000000000000000000000000000000000000000..ac89f2cfeffce9b967eac0be3fb801d2d5e4996a --- /dev/null +++ b/src/bpn/node.h @@ -0,0 +1,61 @@ +//====================================================================================// +// // +// Node class // +// // +//====================================================================================// +// This File: node.h Language: C++ (xlC and CC) // +// Software: SIMULEAU // +//====================================================================================// +// Creation: 21/apr/16 by: Leonardo.Brenner@lsis.org // +// Last Change: 21/apr/16 by: Leonardo.Brenner@lsis.org // +//====================================================================================// +#ifndef NODE_H +#define NODE_H + +class Node +{ + public: + Node(); + Node(simuleau_name _name); + virtual ~Node(); + + void Copy(const Node *_node); + + // input functions + int AllocArcs(int n); // number of input/output arcs and nodes + int AddInputArc(int pos, double weight); // add input arc in the position pos + int AddOutputArc(int pos, double weight); // add output arc in the position pos + int AddInputNodes(Node **nodes); // add input node pointers + int AddOutputNodes(Node **nodes); // add output node pointers + + void SetState(double _state); + + // output functions + char * GetName(); // get the node name + double GetState(); // get the current node state + int GetNumberOfInputArcs(); // get the number of input arc different of 0 + int GetNumberOfOutputArcs(); // get the number of output arc different of 0 + double GetWeightOfInputArc(int _arc); // Get the weight of an input arc + double GetWeightOfOutputArc(int _arc); // Get the weight of an output arc + + // print functions + virtual void Print(ostream &fout); // print node informations + void PrintArcs(ostream &fout); // print arcs + + protected: + int numberofarcs; // number of arcs to this node +// int numberofoutputarcs; // number of output arcs from this node + double *inputarcs; // array of input arcs + double *outputarcs; // array of output arcs + Node **inputnodes; // pointers to input nodes + Node **outputnodes; // pointers to output nodes + + simuleau_name name; // node name + double state; // node state + + void TransferNode(const Node *_node); + + private: +}; + +#endif // NODE_H diff --git a/src/bpn/place.cpp b/src/bpn/place.cpp new file mode 100644 index 0000000000000000000000000000000000000000..375ce0da635b37292e284247f558955188ce9632 --- /dev/null +++ b/src/bpn/place.cpp @@ -0,0 +1,146 @@ +//====================================================================================// +// // +// Place classes inherit of node class // +// // +//====================================================================================// +// This File: place.cpp Language: C++ (xlC and CC) // +// Software: SIMULEAU // +//====================================================================================// +// Creation: 22/apr/16 by: Leonardo.Brenner@lsis.org // +// Last Change: 22/apr/16 by: Leonardo.Brenner@lsis.org // +//====================================================================================// +#include "simuleau.h" + +//------------------------------------------------------------------------------ +//------------------------------------------------------------------------------ +// Methods of the Place class +//------------------------------------------------------------------------------ +//------------------------------------------------------------------------------ + +//------------------------------------------------------------------------------ +// Constructor +//------------------------------------------------------------------------------ +Place::Place() +{ + marks = 0; + initialmarks = 0; + steadymarks = -1; + + conflict = 0; + structuralconflict = 0; +} + +//------------------------------------------------------------------------------ +// Named Constructor +//------------------------------------------------------------------------------ +Place::Place(simuleau_name _name):Node(_name) +{ + marks = 0; + initialmarks = 0; + steadymarks = -1; + + conflict = 0; + structuralconflict = 0; +} + + +//------------------------------------------------------------------------------ +// Destructor +//------------------------------------------------------------------------------ +Place::~Place() +{ + //dtor +} + +//------------------------------------------------------------------------------ +// Copy +//------------------------------------------------------------------------------ +void Place::Copy(const Place * _place) +{ + TransferNode(_place); + + marks = _place->marks; + initialmarks = _place->initialmarks; + steadymarks = _place->steadymarks; + + conflict = _place->conflict; + structuralconflict = _place->structuralconflict; +} + +//------------------------------------------------------------------------------ +// It set the initial marking of the place +//------------------------------------------------------------------------------ +void Place::SetInitialMarking(int m) +{ + marks = initialmarks = m; +} + +//------------------------------------------------------------------------------ +// It set the steady marking of the place +//------------------------------------------------------------------------------ +void Place::SetSteadyMarking(int m) +{ + steadymarks = m; +} + + +//------------------------------------------------------------------------------ +// It returns the current marks +//------------------------------------------------------------------------------ +int Place::GetMarks() +{ + return (marks); +} + +//------------------------------------------------------------------------------ +// It researches structural conflits +//------------------------------------------------------------------------------ +void Place::ResearchStructuralConflict() +{ + int numberofoutputarcs = GetNumberOfOutputArcs(); + + if(numberofoutputarcs <= 1) + structuralconflict = 0; + else + structuralconflict = numberofoutputarcs; +} + +//------------------------------------------------------------------------------ +// It returns structural conflits +//------------------------------------------------------------------------------ +int Place::GetStructuralConflict() +{ + return (structuralconflict); +} + +//------------------------------------------------------------------------------ +// It verifies effectif conflits +// returns 0 by default - Batch places don't have conflits +//------------------------------------------------------------------------------ +int Place::VerifyConflict() +{ + return (0); +} + + + +//------------------------------------------------------------------------------ +// Print +//------------------------------------------------------------------------------ +void Place::Print(ostream &fout) +{ + fout << "Name: " << name << endl; + fout << " Arcs: " << endl; + PrintArcs(fout); +} + +//------------------------------------------------------------------------------ +// Write +//------------------------------------------------------------------------------ +void Place::Write(ostream &fout) +{ + fout << "Name: " << name << endl; + fout << " Marks: " << marks << endl; +// if (steadymarks != 0) +// fout << " Steady Marks: " << steadymarks << endl; +} diff --git a/src/bpn/place.h b/src/bpn/place.h new file mode 100644 index 0000000000000000000000000000000000000000..74dfc355103ae39b388fcb194ecc24948810c9db --- /dev/null +++ b/src/bpn/place.h @@ -0,0 +1,367 @@ +//====================================================================================// +// // +// Place classes inherit of node class // +// // +//====================================================================================// +// This File: place.h Language: C++ (xlC and CC) // +// Software: SIMULEAU // +//====================================================================================// +// Creation: 22/apr/16 by: Leonardo.Brenner@lsis.org // +// Last Change: 22/apr/16 by: Leonardo.Brenner@lsis.org // +//====================================================================================// +#ifndef PLACE_H +#define PLACE_H +#include <simuleau.h> + +//====================================================================================// +// Generic place class // +//====================================================================================// +// Place class implements a generic place that will be used to implement all other // +// place classes (discrete, continuous, batch and triangular batch) that can compose // +// a Batch Petri Net. // +//====================================================================================// +class Place : public Node +{ + public: + Place(); + Place(simuleau_name _name); + virtual ~Place(); + + void Copy (const Place * _place); + virtual place_type IsA() {}; + + // input functions + virtual void SetInitialMarking(int m); + virtual void SetSteadyMarking(int m); + virtual void SetInitialMarking(double m){}; + virtual void SetSteadyMarking(double m){}; + virtual void AddBatchToInitialMarking(Batch &b){}; + virtual void AddBatchToSteadyMarking(Batch &b){}; + virtual void AddBatchToInitialMarking(ControllableBatch &b){}; + virtual void AddBatchToSteadyMarking(ControllableBatch &b){}; + + //simulation functions + virtual void ComputeState(){}; + int GetMarks(); + virtual void EvolveMarks(double _date){}; + virtual void ResearchStructuralConflict(); + virtual int GetStructuralConflict(); + virtual int VerifyConflict(); + + // print functions + virtual void Print(ostream &fout); + virtual void Write(ostream &fout); + + protected: + int marks; + int initialmarks; + int steadymarks; + int structuralconflict; + int conflict; + + private: +}; + + +//====================================================================================// +// Discrete place class // +//====================================================================================// +// Discrete place class is generally used to model control in BPN. // +// These place have a integer number of tokens. // +//====================================================================================// +class DiscretePlace : public Place +{ + public: + DiscretePlace(); + DiscretePlace(simuleau_name _name); + virtual ~DiscretePlace(); + + void Copy (const DiscretePlace * _place); + place_type IsA() {return Discrete_pl;}; + + + // input functions + void SetInitialMarking(int m); + void SetSteadyMarking(int m); + + //simulation functions + void ChangeMarks(int m); + void ReserveMarks(int m); + void RemoveReservedMarks(int m); + void AddMarks(int m); + + void ComputeState(); + + int VerifyConflict(); + + + // print functions + void Print(ostream &fout); + void Write(ostream &fout); + + protected: + int reservedmarks; + int nonreservedmarks; + + + private: +}; + + +//====================================================================================// +// Continuous place class // +//====================================================================================// +// These place have a real number of tokens. // +//====================================================================================// +class ContinuousPlace : public Place +{ + public: + ContinuousPlace(); + ContinuousPlace(simuleau_name _name); + virtual ~ContinuousPlace(); + + void Copy (const ContinuousPlace * _place); + virtual place_type IsA() {return Continuous_pl;}; + + // input functions + void SetInitialMarking(double m); + void SetSteadyMarking(double m); + + //output functions + //double GetOutputTransitonsFlow(); + + //simulation function + double GetMarks(); + double GetInitialMarks(); + double GetSteadyMarks(); + void ChangeMarks(double m); + void ReduceMarks(double m); + void ReserveMarks(double m); + void RemoveReservedMarks(double m); + void AddMarks(double m); + void ComputeState(); + void EvolveMarks(double _date); + void VerifyMarks(); + + int VerifyConflict(); + + double PlaceIsFed(); + virtual int IsEqualSteadyQuantity(); + virtual int IsGreaterThanSteadyQuantity(); + virtual int IsLessThanSteadyQuantity(); + virtual int IsSteadyMarkingReached(); + virtual int IsSteadyMarkingReachedandInputOutputTransitionBelongTz(); + double ComputeFlowFedPlace(ContinuousTransition *ct); + double GetCPEEvent(); + double GetDTEEvent(); + double GetPSQEvent(); + + // print functions + void Print(ostream &fout); + void Write(ostream &fout); + + + protected: + double marks; + double initialmarks; + double steadymarks; + double reservedmarks; + double nonreservedmarks; + + + double ComputeDateDTEEvent(DiscreteTransition *t, double weight); + double ComputeInputFlow(); + + private: +}; + +//====================================================================================// +// Batch place class // +//====================================================================================// +// Batch places model a transfer of batch entities over a space/temporal place // +// These place have batches. // +//====================================================================================// +class BatchPlace : public Place +{ + public: + BatchPlace(); + BatchPlace(simuleau_name _name, double _speed, double _density, double _length); + virtual ~BatchPlace(); + + void Copy (const BatchPlace * _place); + virtual place_type IsA() {return Batch_pl;}; + + // input functions + void AddBatchToInitialMarking(Batch &b); + void AddBatchToSteadyMarking(Batch &b); + void AddBatchToMarking(Batch &b); + void ChangeMarks(list<Batch> *lb); + void SetSpeed(double _speed); + void SetMaxSpeed(double _maxspeed); + void SetDensity(double _density); + void SetLength(double _length); + + // output functions + double GetSpeed(); + double GetMaxSpeed(); + double GetInstantaneousSpeed(); + double GetDensity(); + double GetLength(); + double GetOutputFlow(); + double GetInitialQuantity(); + double GetFreeSteadyQuantity(); // q_i^{f,s} + double GetSteadyQuantity(); + list<Batch>* GetInitialMarking(); + list<Batch>* GetSteadyMarking(); + list<Batch>* GetMarking(); + int GetBehaviour(); + double GetFlowOfOutputTransition(); + double GetInputTransitonsFlow(); + double GetOutputTransitonsFlow(); + double GetSteadyPlaceFlow(); // \phi_i^s The steady flow in a batch place. + double GetSteadyDensity(); // d_i^s the steady density of a batch place. + + + virtual int HasOutputBatch(); + Batch * GetOutputBatch(); + virtual double GetDensityOutputBatch(); + + virtual int IsFull(); + virtual int IsEqualSteadyQuantity(); + virtual int IsGreaterThanSteadyQuantity(); + virtual int IsLessThanSteadyQuantity(); + virtual int IsSteadyMarkingReached(); + virtual int IsSteadyMarkingQuantityReachedandInputOutputTransitionBelongTz(); + virtual int IsHoldSteadyPlaceFlowUntilSteadyState(); + + + //simulation functions + virtual void ComputeState(); + + virtual int CreateBatches(); + virtual void MergeBatches(); + virtual void DestructBatches(); + virtual void ComputeQuantities(); +// virtual void ComputeTwoTypesSteadyQuantities(); // the steady marking quantity in a free part and accumulated part. + + virtual void ComputeBehaviour(); + virtual void EvolveMarks(double _date); + + virtual double GetBOBEvent(); + virtual double GetDOBEvent(); + virtual double GetBBDEvent(); + virtual double GetTBMEvent(); + virtual double GetPSQEvent(); + + + // print functions + virtual void Print(ostream &fout); + virtual void Write(ostream &fout); + + protected: + int behaviour; + int formalisation; + list<Batch> *marks; + list<Batch> *initialmarks; + list<Batch> *steadymarks; + double density; + double maxspeed; + double speed; + double instantaneousspeed; + double length; + double quantity; + double steadyquantity; + + void EvolveInFreeBehaviour(Simtime *st); // RL + void EvolveInAccumulatedOutputBehaviour(Simtime *st); // SA + void EvolveInPartiallyAccumulatedBehaviour(Simtime *st); //RAP + void EvolveInFreeToAccumulatedBehaviour(Simtime *st);// RLA + + private: +}; + +//====================================================================================// +// Triangular Batch place class // +//====================================================================================// +// Triangular batch places are a special kind of batch places dedicated to model // +// trafic route systems. The batches in batch place must follow a triangular fundamen-// +// tal diagram issue of the trafic route model. // +// These place have triangular batches. // +//====================================================================================// +class TriangularBatchPlace : public BatchPlace +{ + public: + TriangularBatchPlace(); + TriangularBatchPlace(simuleau_name _name, double _speed, double _density, double _length, double _flow); + virtual ~TriangularBatchPlace(); + + void Copy (const TriangularBatchPlace * _place); + place_type IsA() {return Triangular_pl;}; + + + // input functions + void AddBatchToInitialMarking(ControllableBatch &b); + void AddBatchToSteadyMarking(ControllableBatch &b); + void AddBatchToMarking(ControllableBatch &b); + void SetFlow(double _flow); + void SetMaxFlow(double _flow); + + // output functions + double GetFlow(); + double GetMaxFlow(); + + int IsFull(); + int HasOutputBatch(); + ControllableBatch* GetOutputControllableBatch(); + + double GetCriticalDensity(); + double GetDensityOutputBatch(); + double GetSpeedOutputBatch(); + double GetFlowOutputBatch(); + double GetCongestionDensity(); + double GetPropagationSpeed(); + + + //simulation functions + void ComputeState(); + + int CreateBatches(); + void MergeBatches(); + void DestructBatches(); + + void ComputeBehaviour(); + void SetAndRecomputeSpeed(double newspeed); + void SetBehaviourFunctions(); //precomputebehaviour + void SetFunctionFreeBatch(list<ControllableBatch>::iterator cbi, int i); + void SetFunctionCongestedBatch(list<ControllableBatch>::iterator cbi, int i); + void SetFunctionUncongestingBatch(list<ControllableBatch>::iterator cbi, int i); + void EvolveMarks(double _date); + void EvolveControllableBatch(list<ControllableBatch>::iterator cbi, double _date); + + double GetBOBEvent(); + double GetDOBEvent(); + double GetBBDEvent(); + double GetTBMEvent(); + double GetBMOBEvent(); + double GetOBDEvent(); + double GetBDEvent(); + double GetBBFEvent(); + + + + // print functions + void Print(ostream &fout); + void Write(ostream &fout); + + protected: + list<ControllableBatch> *marks; + list<ControllableBatch> *initialmarks; + list<ControllableBatch> *steadymarks; + double maxflow; + double flow; + + private: +}; + + +#endif // PLACE_H diff --git a/src/bpn/transition.cpp b/src/bpn/transition.cpp new file mode 100644 index 0000000000000000000000000000000000000000..77424bedf048f4c1b965520391a63cf540f49417 --- /dev/null +++ b/src/bpn/transition.cpp @@ -0,0 +1,358 @@ +//====================================================================================// +// // +// Transition classes inherit of node class // +// // +//====================================================================================// +// This File: transition.cpp Language: C++ (xlC and CC) // +// Software: SIMULEAU // +//====================================================================================// +// Creation: 22/apr/16 by: Leonardo.Brenner@lsis.org // +// Last Change: 24/jan/20 by: Leonardo.Brenner@lsis.org // +//====================================================================================// +#include "simuleau.h" + +//------------------------------------------------------------------------------ +//------------------------------------------------------------------------------ +// Methods of the Transition class +//------------------------------------------------------------------------------ +//------------------------------------------------------------------------------ + +//------------------------------------------------------------------------------ +// Constructor +//------------------------------------------------------------------------------ +Transition::Transition() +{ + //ctor +} + +//------------------------------------------------------------------------------ +// Named Constructor +//------------------------------------------------------------------------------ +Transition::Transition(simuleau_name _name):Node(_name) +{ + previousstate = state; + firingquantity = new FiringQuantity; +} + +//------------------------------------------------------------------------------ +// Destructor +//------------------------------------------------------------------------------ +Transition::~Transition() +{ + if (firingquantity) + delete firingquantity;//dtor +} + + +//------------------------------------------------------------------------------ +// Copy +//------------------------------------------------------------------------------ +void Transition::Copy(const Transition *_transition) +{ + TransferNode(_transition); + firingquantity = new FiringQuantity; + firingquantity->Copy(_transition->firingquantity); +} + +//------------------------------------------------------------------------------ +// Set the previous state +//------------------------------------------------------------------------------ +void Transition::SetPreviousState(double _state) +{ + previousstate = _state; +} + + +//------------------------------------------------------------------------------ +// Compute states +//------------------------------------------------------------------------------ +void Transition::ComputeState() +{ + double transstate = 1.0; // enabled + double placestate; + Place *p; + + if (GetNumberOfInputArcs() == 0){ + state = 1.0; // enabled sink transition + } + else{ + for (int i=0; i<numberofarcs; i++){ + if (inputarcs[i] != 0){ +// p = simulation->sbpn->GetPlace(i); + p = inputnodes[i]; + placestate = p->GetState(); +// cout << "State of the place: " << placestate << endl; + transstate = min(transstate, placestate); + } + } + state = transstate; +// cout << "State of the transition: " << state << endl; + + } +} + +//========================Wodes20===========(modified version)==================================== +//------------------------------------------------------------------------------ +// Compute input place's marking quantity less than steady marking quantity states +//------------------------------------------------------------------------------ +int Transition::IsOnState() +{ + int transstate = 1; // enabled + Place *p; + double weight; + + if (GetNumberOfInputArcs() == 0){ + return 1; // enabled :source transition + } + else{ + for (int i=0; i<numberofarcs; i++){ + if (inputarcs[i] != 0){ +// p = simulation->sbpn->GetPlace(i); + p = inputnodes[i]; + weight = -inputarcs[i]; + if (outputarcs[i] != 0 & inputarcs[i] != 0){ +// p = simulation->sbpn->GetPlace(i); + // for (int j=0; j<NumberOfTransitions(); j++) { + // V[j] = 0.0; + weight += outputarcs[i]; + } + + +// +// if (places[k]->GetWeightOfOutputArc(j) != 0.0 ){ +// V[j] = - places[k]->GetWeightOfOutputArc(j); +// // cout << " - V [" << j << "] " ; +// } +// if (places[k]->GetWeightOfInputArc(j) != 0.0 ){ +// // cout << " + V [" << j << "] " ; +// V[j] += places[k]->GetWeightOfInputArc(j); +// } +// +// +// if (outputarcs[i] != 0){ +//// p = simulation->sbpn->GetPlace(i); +// p = (Place*)outputnodes[i]; +// +// // for (int j=0; j<NumberOfTransitions(); j++) { +// // V[j] = 0.0; +// weight = outputarcs[i]; +// + switch (p->IsA()){ + case Continuous_pl : if (((ContinuousPlace*)p)->IsLessThanSteadyQuantity()& weight<0) + return 0; + break; + case Batch_pl : if (((BatchPlace*)p)->IsLessThanSteadyQuantity()& weight < 0) + return 0; + break; + } + } + } + } + return transstate; +} + +//=================================Vecos20============================================ + + +//------------------------------------------------------------------------------ +FiringQuantity* Transition::GetFiringQuantity() +{ + return (firingquantity); +} + +//------------------------------------------------------------------------------ +// Returns firing quantity +//------------------------------------------------------------------------------ + + +//==========================Steady firing quantity from initial marking============== +// +// It computes the steady firing quantity of each transition from initial marking. +//===================================================================================== +void Transition::SetSteadyFiringQuantity(double _firingquantity) +{ + firingquantity->SetSteadyFiringQuantity(_firingquantity); +} +//===================================================================================== +double Transition::GetSteadyFiringQuantity() +{ + return(steadyfiringquantity); +} + +//==========================Current firing quantity from initial marking============== +// +// It computes the current firing quantity of each transition from initial marking. +//===================================================================================== +//void Transition::setCurrentFiringQuantity(double _firingquantity) +//{ +// firingquantity->SetCurrentFiringQuantity(_firingquantity); +//} + +//====================================================================== + +double Transition::CurrentFiringQuantity(double steptime) +{ + Flow *f; + // FiringQuantity *firingquantity; + // Transition *t; + // double currentfiringquantity; + // currentfiringquantity=firingquantity->GetCurrentFiringQuantity(); + currentfiringquantity+= f->GetCurrentFlow() * steptime; + + // firingquantity=t->GetFiringQuantity(); + // firingquantity->SetCurrentFiringQuantity(currentfiringquantity); + return (currentfiringquantity); +} + + +//=========================================================================== +double Transition::GetCurrentFiringQuantity() +{ + return (currentfiringquantity); +} + + +//========================Vecos20======T_Z==================================== +//----------------------------------------------------------------------------------------------------------- +// Compute the set of T_Z that exist one output place satisfy Post(p_i, t_j)(z_j^s-z_j(m)) <= q_i^{f,s} +//----------------------------------------------------------------------------------------------------------- +int Transition::IsFiringQuantityOnState() +{ + double weight; + int transstate = 1; // enabled + Place *p; + // Transition *t; + // FiringQuantity *q; + double Zs; + double z; + + //q= t->GetFiringQuantity(); + Zs=firingquantity->GetSteadyFiringQuantity(); + z =firingquantity->GetCurrentFiringQuantity(); + + + if (GetNumberOfOutputArcs() == 0){ + return 1; // enabled sink transition + } + else{ + for (int i=0; i<numberofarcs; i++){ + if (outputarcs[i] != 0){ +// p = simulation->sbpn->GetPlace(i); + p = (Place*)outputnodes[i]; + + // for (int j=0; j<NumberOfTransitions(); j++) { + // V[j] = 0.0; + weight = outputarcs[i]; + switch (p->IsA()){ + case Continuous_pl : if (weight * (Zs-z) <= 0)// FreeSteadyMarkingQuantity= 0 in P^C + return 0; + break; + case Batch_pl : if (weight*(Zs-z) <= ((BatchPlace*)p)->GetFreeSteadyQuantity()) + return 0; + break; + } + } + } + } + return transstate; +} + + +//========================RBF========Event================================= +// It gets the rbf event. (a new ) objective : +//=========================================================================== +double Transition::GetRBFEvent() +{ + double date; + double min_date=-1.0; + double weight; + double transitionflow; + Flow *f; + Place *p; +// Transition *t; +// FiringQuantity *q; + double Zs; + double z; + + // q=t->GetFiringQuantity(); + Zs=firingquantity->GetSteadyFiringQuantity(); + z =firingquantity->GetCurrentFiringQuantity(); + + if (GetNumberOfOutputArcs() == 0){ + return (-1.0); + } + else if(z >= Zs){ + return (-1.0); + } + else{ + for (int i=0; i<numberofarcs; i++){ + if (outputarcs[i] != 0){ +// p = simulation->sbpn->GetPlace(i); + p = (Place*)outputnodes[i]; + + weight = outputarcs[i]; + // f=t->GetFlow(); + transitionflow=f->GetCurrentFlow(); + switch (p->IsA()){ + case Continuous_pl : + date = (Zs-z) / transitionflow; // FreeSteadyMarkingQuantity= 0 in P^C + date += simulation->stime->GetCurrentDate(); + + + break; + case Batch_pl : + date = (Zs-z -(((BatchPlace*)p)->GetFreeSteadyQuantity() / weight) / transitionflow); + if (date < 0){ + return (-1.0); + } + else{ + date += simulation->stime->GetCurrentDate(); + } + break; + } + if (date < min_date || min_date==-1.0){ + min_date= date; + } + } + } + return(min_date); + } + return (-1.0); +} +//----------------------------------------------------------------------------------- + + +//double BatchPlace::GetBOBEvent() +//{ +// double pos; +// double date; +// Batch b; +// +// if (marks->empty()){ +// return (-1.0); // no event of this type +// } +// +// if (state != 1.0){ +// b = marks->front(); +// pos = b.GetPosition(); +// date = (length - pos) / instantaneousspeed; +// date += simulation->stime->GetCurrentDate(); +// return (date); +// } +// return (-1.0); +//} + + + + + +//------------------------------------------------------------------------------ +// Print +//------------------------------------------------------------------------------ +void Transition::Print(ostream &fout) +{ + fout << "Name: " << name << endl; + fout << " Arcs: " << endl; + PrintArcs(fout); +} + diff --git a/src/bpn/transition.h b/src/bpn/transition.h new file mode 100644 index 0000000000000000000000000000000000000000..b5cbceb94ef46402b126d6e51a90fcf5e3c89451 --- /dev/null +++ b/src/bpn/transition.h @@ -0,0 +1,189 @@ +//====================================================================================// +// // +// Transition classes inherit of node class // +// // +//====================================================================================// +// This File: transition.h Language: C++ (xlC and CC) // +// Software: SIMULEAU // +//====================================================================================// +// Creation: 22/apr/16 by: Leonardo.Brenner@lsis.org // +// Last Change: 22/apr/16 by: Leonardo.Brenner@lsis.org // +//====================================================================================// +#ifndef TRANSITION_H +#define TRANSITION_H +#include <simuleau.h> +#include <flow.h> +#include <firingquantity.h> + + +//====================================================================================// +// Generic transition class // +//====================================================================================// +// Transition class implements a generic transition that will be used to implement // +// all other transition classes (discrete, continuous, batch) that can compose a // +// Batch Petri Net. // +//====================================================================================// +class Transition : public Node +{ + public: + Transition(); + Transition(simuleau_name _name); + virtual ~Transition(); + + + virtual void SetSteadyFiringQuantity(double _firingquantity); + FiringQuantity* GetFiringQuantity(); + + + void Copy(const Transition *_transition); + virtual trans_type IsA(){}; + + virtual Flow* GetFlow(){}; + virtual Flow* GetSteadyFlow(){}; + virtual int IsSteadyFlowReached(){}; + + void SetPreviousState(double _state); + virtual void ComputeState(); + int IsOnState(); + int IsFiringQuantityOnState(); // The current firing quantity satisfy belongs to T_z. +// double SteadyFiringQuantity(); // The steady firing quantity computed by the initial marking to a + // given steady state. (minimal firing quantity) + double GetSteadyFiringQuantity(); + double CurrentFiringQuantity(double steptime); // current firing quantity of transition. + double GetCurrentFiringQuantity(); //Get the current firing quantity + + double GetRBFEvent(); // + + + + virtual void WalkThrough(double duration){}; + // virtual void CurrentFiringQuantity(Simtime *_stime); + + // print functions + virtual void Print(ostream &fout); + + protected: + double previousstate; + FiringQuantity *firingquantity; + double steadyfiringquantity; + double currentfiringquantity; //Firing quantity from initial marking + private: +}; + + +//====================================================================================// +// Discrete transition class // +//====================================================================================// +// Discrete transition class associates a fire timing to discrete transitions. // +//====================================================================================// +class DiscreteTransition : public Transition +{ + public: + DiscreteTransition(); + DiscreteTransition(simuleau_name _name, double _time, double _steadytime); + virtual ~DiscreteTransition(); + + void Copy(const DiscreteTransition *_transition); + trans_type IsA(){return Discrete_tr;}; + + // simulation functions + void InitEnabledDate(); + void SetEnabledDate(double _date); + void ReserveMarksInputPlaces(); + + double GetTime(); + double GetSteadyTime(); + double GetEnabledDate(); + void ComputeState(); + double GetRBFEvent(); + + + void WalkThrough(double duration); + void FireDiscreteTransition(); + + + // print functions + void Print(ostream &fout); + + + protected: + double time; + double steadytime; + double enableddate; + private: +}; + +//====================================================================================// +// Continuous transition class // +//====================================================================================// +// Continuous transition class associates a flow to continuous transitions. // +//====================================================================================// +class ContinuousTransition : public Transition +{ + public: + ContinuousTransition(); + ContinuousTransition(simuleau_name _name, double _flow, double _steadyflow); + virtual ~ContinuousTransition(); + + void Copy(const ContinuousTransition *_transition); + virtual trans_type IsA(){return Continuous_tr;}; + + Flow* GetFlow(); + void SetInitialFlow(double _flow); + void SetTheoreticalFlow(double _flow); + int IsSteadyFlowReached(); + + double ComputeMinimumFlow(double f1, double f2); + virtual void ComputeTheoreticalFlow(); + + virtual void WalkThrough(double duration); + void FireContinuousTransition(double duration); + + double GetRBFEvent(); + + // print functions + void Print(ostream &fout); + virtual void Write(ostream &fout); + + protected: + Flow *flow; + + double ComputeTheoreticalFlowOfPlace(); + + private: +}; + + +//====================================================================================// +// Batch transition class // +//====================================================================================// +// Batch transition class associates a flow to batch transitions. // +//====================================================================================// +class BatchTransition : public ContinuousTransition +{ + public: + BatchTransition(); + BatchTransition(simuleau_name _name, double _flow, double _steadyflow); + virtual ~BatchTransition(); + + void Copy(const BatchTransition *_transition); + trans_type IsA(){return Batch_tr;}; + + double GetInputTheoreticalFlow(); + double GetOutputTheoreticalFlow(); + + void ComputeInputTheoreticalFlow(); + void ComputeOutputTheoreticalFlow(); + void ComputeTheoreticalFlow(); + double GetRBFEvent(); + // print functions + void Print(ostream &fout); + void Write(ostream &fout); + + protected: + double inputtheoreticalflow; + double outputtheoreticalflow; + private: +}; + +#endif // TRANSITION_H diff --git a/src/bpn/triangularbatchplace.cpp b/src/bpn/triangularbatchplace.cpp new file mode 100644 index 0000000000000000000000000000000000000000..90f170a2f3c83bb17694449617655cc7d52e1153 --- /dev/null +++ b/src/bpn/triangularbatchplace.cpp @@ -0,0 +1,1114 @@ +//====================================================================================// +// // +// Triangular batch place classes inherit of place class // +// // +//====================================================================================// +// This File: triangularbatchplace.cpp Language: C++ (xlC and CC) // +// Software: SIMULEAU // +//====================================================================================// +// Creation: 22/apr/16 by: Leonardo.Brenner@lsis.org // +// Last Change: 22/apr/16 by: Leonardo.Brenner@lsis.org // +//====================================================================================// +#include "simuleau.h" + +//------------------------------------------------------------------------------ +//------------------------------------------------------------------------------ +// Methods of the Triangular Batch Place class +//------------------------------------------------------------------------------ +//------------------------------------------------------------------------------ + +//------------------------------------------------------------------------------ +// Constructor +//------------------------------------------------------------------------------ +TriangularBatchPlace::TriangularBatchPlace() +{ + +} + +//------------------------------------------------------------------------------ +// Initialized Constructor +//------------------------------------------------------------------------------ +TriangularBatchPlace::TriangularBatchPlace(simuleau_name _name, double _speed, double _density, double _length, + double _flow):BatchPlace(_name, _speed, _density, _length) +{ + + flow = _flow; + maxflow = _flow; + marks = new list<ControllableBatch>; + marks->clear(); + initialmarks = new list<ControllableBatch>; + initialmarks->clear(); + steadymarks = new list<ControllableBatch>; + steadymarks->clear(); + +} +//------------------------------------------------------------------------------ +// Destructor +//------------------------------------------------------------------------------ +TriangularBatchPlace::~TriangularBatchPlace() +{ + if (marks) + delete[] marks; + if (initialmarks) + delete[] initialmarks; + if (steadymarks) + delete[] steadymarks; + +} + + +//------------------------------------------------------------------------------ +// Copy +//------------------------------------------------------------------------------ +void TriangularBatchPlace::Copy(const TriangularBatchPlace * _place) +{ + TransferNode(_place); + + conflict = _place->conflict; + structuralconflict = _place->structuralconflict; + + // batch place + behaviour = _place->behaviour; + formalisation = _place->formalisation; + + density = _place->density; + maxspeed = _place->maxspeed; + speed = _place->speed; + instantaneousspeed = _place->instantaneousspeed; + length = _place->length; + flow = _place->flow; + maxflow = _place->maxflow; + + marks = new list<ControllableBatch>; + marks->clear(); + + for (list<ControllableBatch>::iterator it=_place->marks->begin(); it!=_place->marks->end(); ++it) { + ControllableBatch *newbatch = new ControllableBatch; + newbatch->Copy(*it); + marks->push_back(*newbatch); + } + + initialmarks = new list<ControllableBatch>; + initialmarks->clear(); + + for (list<ControllableBatch>::iterator it=_place->initialmarks->begin(); it!=_place->initialmarks->end(); ++it) { + ControllableBatch *newbatch = new ControllableBatch; + newbatch->Copy(*it); + initialmarks->push_back(*newbatch); + } + + + steadymarks = new list<ControllableBatch>; + steadymarks->clear(); + + for (list<ControllableBatch>::iterator it=_place->steadymarks->begin(); it!=_place->steadymarks->end(); ++it) { + ControllableBatch *newbatch = new ControllableBatch; + newbatch->Copy(*it); + steadymarks->push_back(*newbatch); + } + + } + +//------------------------------------------------------------------------------ +// It set the initial marking of the place +//------------------------------------------------------------------------------ +void TriangularBatchPlace::AddBatchToInitialMarking(ControllableBatch &b) +{ + initialmarks->push_back(b); + marks->push_back(b); +} + +//------------------------------------------------------------------------------ +// It add a batch to the steady marking of the place +//------------------------------------------------------------------------------ +void TriangularBatchPlace::AddBatchToSteadyMarking(ControllableBatch &b) +{ + steadymarks->push_back(b); +} + +//------------------------------------------------------------------------------ +// It add a batch to the marking of the place +//------------------------------------------------------------------------------ +void TriangularBatchPlace::AddBatchToMarking(ControllableBatch &b) +{ + marks->push_back(b); +} + + +//------------------------------------------------------------------------------ +// It set the new flow +//------------------------------------------------------------------------------ +void TriangularBatchPlace::SetFlow(double _flow) +{ + flow = _flow; +} + +//------------------------------------------------------------------------------ +// It set the maximum flow +//------------------------------------------------------------------------------ +void TriangularBatchPlace::SetMaxFlow(double _flow) +{ + maxflow = _flow; +} + +//------------------------------------------------------------------------------ +// It set the new flow +//------------------------------------------------------------------------------ +double TriangularBatchPlace::GetFlow() +{ + return (flow); +} + +//------------------------------------------------------------------------------ +// It set the maximum flow +//------------------------------------------------------------------------------ +double TriangularBatchPlace::GetMaxFlow() +{ + return (maxflow); +} + +//------------------------------------------------------------------------------ +// It returns true if the triangular batch place is full +//------------------------------------------------------------------------------ +int TriangularBatchPlace::IsFull() +{ + double full = length * density; + double quantity = 0.0; + + if (marks->size() != 0){ + for (list<ControllableBatch>::iterator cb=marks->begin(); cb!=marks->end(); cb++) { + quantity += cb->GetDensity() * cb->GetLength(); + } + if (abs(quantity - full) < PRF::prf.Min_Err()){ + return 1; + } + else{ + return 0; + } + } + else { + return 0; + } +} + + +//------------------------------------------------------------------------------ +// It returns true if the place has an output batch +//------------------------------------------------------------------------------ +int TriangularBatchPlace::HasOutputBatch() +{ + int result; + + ControllableBatch cb; + + if (marks->size() == 0){ + result = 0; + } + else{ + cb = marks->front(); + if ((length - cb.GetPosition()) <= PRF::prf.Min_Err()){ + result = 1; + } + else{ + result = 0; + } + } + return (result); +} + + +//------------------------------------------------------------------------------ +// It returns the output controllable batch +//------------------------------------------------------------------------------ +ControllableBatch* TriangularBatchPlace::GetOutputControllableBatch() +{ + if (HasOutputBatch()){ + return (&marks->front()); + } + else{ + return (NULL); + } +} + +//------------------------------------------------------------------------------ +// It returns the critical density +//------------------------------------------------------------------------------ +double TriangularBatchPlace::GetCriticalDensity() +{ + double dcri; + dcri = ((GetPropagationSpeed() * density) / (instantaneousspeed + GetPropagationSpeed())); + return (dcri); +} + +//------------------------------------------------------------------------------ +// It returns the density of the output batch +//------------------------------------------------------------------------------ +double TriangularBatchPlace::GetDensityOutputBatch() +{ + double densityoutputbatch = 0.0; + ControllableBatch *cb; + + if (HasOutputBatch()){ + cb = GetOutputControllableBatch(); + densityoutputbatch = cb->GetDensity(); + } + return (densityoutputbatch); +} + +//------------------------------------------------------------------------------ +// It returns the speed of the output batch +//------------------------------------------------------------------------------ +double TriangularBatchPlace::GetSpeedOutputBatch() +{ + double speedoutputbatch = 0.0; + ControllableBatch *cb; + + if (HasOutputBatch()){ + cb = GetOutputControllableBatch(); + speedoutputbatch = cb->GetSpeed(); + } + return (speedoutputbatch); +} + +//------------------------------------------------------------------------------ +// It returns the flow of the output batch +//------------------------------------------------------------------------------ +double TriangularBatchPlace::GetFlowOutputBatch() +{ + return (GetDensityOutputBatch() * GetSpeedOutputBatch()); +} + +//------------------------------------------------------------------------------ +// It returns the congested density of the place +//------------------------------------------------------------------------------ +double TriangularBatchPlace::GetCongestionDensity() +{ + return (density - (GetOutputTransitonsFlow() / GetPropagationSpeed())); +} + +//------------------------------------------------------------------------------ +// It returns the propagation speed of congestion/decongestion +//------------------------------------------------------------------------------ +double TriangularBatchPlace::GetPropagationSpeed() +{ + double w; + w = (maxflow * maxspeed) / (density * maxspeed - maxflow); + return (w); +} + + +//------------------------------------------------------------------------------ +// It computes the state of the triangular batch place +//------------------------------------------------------------------------------ +void TriangularBatchPlace::ComputeState() +{ + if (marks->empty()){ + state = 0.0; + } + else{ + if (HasOutputBatch() == 1){ + state = 1.0; + } + else{ + state = 0.0; + } + } +} + + +//------------------------------------------------------------------------------ +// It creates a controllable batch if the place has a least an input transition (continuous or batch) +// and the input flow is non-null +// It returns a positive value if a batch was created and 0 otherwise +// TODO verify multiple input transitions +//------------------------------------------------------------------------------ +int TriangularBatchPlace::CreateBatches() +{ + double inputtransflow = 0.0; + int result = 0; + + Transition *t; + Flow *f; + ControllableBatch *newcb; + + formalisation = no; + + if (GetNumberOfInputArcs() != 0){ + inputtransflow = GetInputTransitonsFlow(); + if (inputtransflow > 0.0){ + if (!marks->empty()){ + ControllableBatch &cb = marks->back(); + if ((cb.GetLength() != 0.0 ) && (cb.GetPosition() != 0.0)){ + newcb = new ControllableBatch(inputtransflow, instantaneousspeed); + AddBatchToMarking(*newcb); + } + } + else{ + newcb = new ControllableBatch(inputtransflow, instantaneousspeed); + AddBatchToMarking(*newcb); + } + } + } +} + +//------------------------------------------------------------------------------ +// It merges the batch that have the same speed and density and are in contact +//------------------------------------------------------------------------------ +void TriangularBatchPlace::MergeBatches() +{ + int merged = 0; + double endposition; + double newlength; + int numberofbatches = marks->size(); + ControllableBatch *newcb; + list<ControllableBatch> *newmarks = new list<ControllableBatch>; + list<ControllableBatch>::iterator cb1, cb2, cbi; + + if (numberofbatches > 1){ + cb1 = marks->begin(); + cbi = marks->begin(); + cbi++; + for (int i=1; i<numberofbatches; i++){ + endposition = cb1->GetPosition() - cb1->GetLength(); + cb2 = cbi; + + if ((abs(cb1->GetDensity() - cb2->GetDensity()) < PRF::prf.Min_Err()) && + (abs(cb2->GetPosition() - endposition) < PRF::prf.Min_Err())){ // merge batches + newlength = cb1->GetLength() + cb2->GetLength(); + cb1->SetLength(newlength); + cbi++; + merged = 1; + } + else{ + newcb = new ControllableBatch; + newcb->Copy(*cb1); + newmarks->push_back(*newcb); + cb1 = cb2; + cbi++; + merged = 0; + } + } + + newcb = new ControllableBatch; + if (merged){ + newcb->Copy(*cb1); + } + else{ + newcb->Copy(*cb2); + } + + newmarks->push_back(*newcb); + marks->clear(); + marks = newmarks; + } +} + +//------------------------------------------------------------------------------ +// It destructs the Controllable batches that have a length or density equal to 0 +// and are not the input batch (position equal to length) +//------------------------------------------------------------------------------ +void TriangularBatchPlace::DestructBatches() +{ + int numberofbatches = marks->size(); + ControllableBatch *newcb; + list<ControllableBatch> *newmarks = new list<ControllableBatch>; + list<ControllableBatch>::iterator cb1; + + if (numberofbatches != 0){ + for (cb1=marks->begin(); cb1!=marks->end(); ++cb1) { + if ((cb1->GetLength() > PRF::prf.Min_Err()) || ((cb1->GetPosition() == 0.0) && (cb1->GetLength() == 0.0))){ + newcb = new ControllableBatch; + newcb->Copy(*cb1); + newmarks->push_back(*newcb); + } + } + marks->clear(); + marks = newmarks; + } +} + +//------------------------------------------------------------------------------ +// It computes the behaviour of a triangular batch place +// TODO all batch places have no structural conflit +//------------------------------------------------------------------------------ +void TriangularBatchPlace::ComputeBehaviour() +{ + int i=0; + double outflow; + double trflow; + double pcb_speed = -1.0; + list<ControllableBatch>::iterator cbi, pcbi; + ControllableBatch *cb, *pcb; + ControllableBatch *ocb = NULL; + + if (HasOutputBatch()){ + ocb = GetOutputControllableBatch(); + } + + for (i=0, cbi=marks->begin(); cbi!=marks->end(); ++i, ++cbi) { + cb = (ControllableBatch*) &(*cbi); + if (cb == ocb){ + outflow = ocb->GetFlow(); + trflow = GetOutputTransitonsFlow(); + + if (cb->GetState(this) == Free_st){ + if ((outflow - trflow) <= PRF::prf.Min_Err()){ + cb->SetBehaviour(Free_behaviour); + } + else{ + cb->SetBehaviour(Congesting_behaviour); + } + } + else{ // not free state + if ((outflow - trflow) < (-PRF::prf.Min_Err())){ + cb->SetBehaviour(Uncongesting_behaviour); + } + else{ + if ((outflow - trflow) > PRF::prf.Min_Err()){ + cb->SetBehaviour(Congesting_behaviour); + } + else{ + cb->SetBehaviour(Free_behaviour); + } + } + } + } + else{ // not the output batch + pcbi = cbi; + pcbi--; // previous controllable batch iterator; + pcb = (ControllableBatch*) &(*pcbi); // previous controllable batch + pcb_speed = -1.0; + + if ((i!=0) && (cb != pcb) && (cb->IsInContactWithByFront(*pcb))){ + pcb_speed = pcb->GetSpeed(); + } + + if (cb->GetState(this) == Free_st){ + if ((pcb_speed >= 0.0) && (pcb_speed < cb->GetSpeed())){ + cb->SetBehaviour(Congesting_behaviour); + } + else{ + cb->SetBehaviour(Free_behaviour); + } + } + else{ + if ((pcb_speed >= 0.0) && (pcb_speed < cb->GetSpeed())){ // <= + cb->SetBehaviour(Congesting_behaviour); + } + else{ + cb->SetBehaviour(Uncongesting_behaviour); + } + } + } + } +} + + +//------------------------------------------------------------------------------ +// This function sets the new speed and recompute the state of the controllable batches +//------------------------------------------------------------------------------ +void TriangularBatchPlace::SetAndRecomputeSpeed(double newspeed) +{ + ctrl_batch_state st; + double newcriticaldensity; + + for (list<ControllableBatch>::iterator cbi=marks->begin(); cbi!=marks->end(); ++cbi) { + st = cbi->GetState(this); + if (newspeed < instantaneousspeed){ + if ((st == Free_st) || (st == Congested_st) && (cbi->GetSpeed() > newspeed)){ + cbi->SetSpeed(newspeed); + } + } + else{ + if (newspeed > instantaneousspeed){ + newcriticaldensity = flow / newspeed; + if (st == Free_st) { + if (cbi->GetDensity() <= newcriticaldensity){ + cbi->SetSpeed(newspeed); + } + else{ + cbi->SetSpeed(GetPropagationSpeed() * (density - cbi->GetDensity()) / cbi->GetDensity()); + } + } + } + } + } + SetSpeed(newspeed); +} + + + +//------------------------------------------------------------------------------ +// This function sets the corresponding evolution function to each batch +//------------------------------------------------------------------------------ +void TriangularBatchPlace::SetBehaviourFunctions() +{ + int i=0; + list<ControllableBatch>::iterator cbi; + + for (i=0, cbi=marks->begin(); cbi!=marks->end(); ++i, ++cbi) { + switch(cbi->GetBehaviour()){ + case Free_behaviour: SetFunctionFreeBatch(cbi, i); + break; + case Congesting_behaviour: SetFunctionCongestedBatch(cbi, i); + break; + case Uncongesting_behaviour: SetFunctionUncongestingBatch(cbi, i); + break; + } + } +} + +//------------------------------------------------------------------------------ +// It sets the evolution function to a free batch +//------------------------------------------------------------------------------ +void TriangularBatchPlace::SetFunctionFreeBatch(list<ControllableBatch>::iterator cbi, int i) +{ + switch(cbi->GetState(this)){ + case Free_st : cbi->SetEvolveFunction(&ControllableBatch::EvolveInFreeBehaviour); + break; + case Congested_st : cbi->SetEvolveFunction(&ControllableBatch::EvolveInCongestingOutputBehaviour); + break; + } +} + + +//------------------------------------------------------------------------------ +// It sets the evolution function to a congested batch +// TODO verify cbi adn pcbi +//------------------------------------------------------------------------------ +void TriangularBatchPlace::SetFunctionCongestedBatch(list<ControllableBatch>::iterator cbi, int i) +{ + double diffdensity; + + list<ControllableBatch>::iterator pcbi = prev(cbi); + list<ControllableBatch>::iterator ncbi = next(cbi); + + int cbiisoutputbatch = cbi->IsOutputControllableBatch(this); + int pcbiisoutputbatch = pcbi->IsOutputControllableBatch(this); + + cbi->SetEvolveFunction(&ControllableBatch::EvolveInFreeBehaviour); // default case + + if (cbiisoutputbatch) { + diffdensity = cbi->GetDensity() - GetCongestionDensity(); + if (abs(diffdensity) <= PRF::prf.Min_Err()){ + if (cbi->GetBehaviour() == Congesting_behaviour){ + cbi->SetEvolveFunction(&ControllableBatch::EvolveInCongestingOutputBehaviour); + } + } + else{ // density != congestion density and cbi is outpubatch + ControllableBatch *newcb = new ControllableBatch; + newcb->Copy(*cbi); // create a copy of the current batch + + newcb->SetLength(0.0); + newcb->SetDensity(GetCongestionDensity()); + newcb->SetSpeed(GetFlowOfOutputTransition() / GetCongestionDensity()); + newcb->SetEvolveFunction(&ControllableBatch::EvolveInFreeToCongestingBehaviourCongBatch); + + marks->insert(cbi, *newcb); + + // set function cbi + cbi->SetEvolveFunction(&ControllableBatch::EvolveInFreeToCongestingBehaviourFreeBatch); + cbi++; + } + } + else{ + if ((!cbiisoutputbatch) && (i != 0) && (cbi->IsInContactWithByFront(*pcbi))){ + ControllableBatch *newcb = new ControllableBatch; + newcb->Copy(*cbi); // create a copy of the current batch + + + newcb->SetLength(0.0); + newcb->SetDensity(pcbi->GetDensity()); + newcb->SetSpeed(pcbi->GetSpeed()); + newcb->SetEvolveFunction(&ControllableBatch::EvolveInFreeToCongestingBehaviourMiddlePlaceWithContactCongBatch); + + marks->insert(cbi, *newcb); + // set function + cbi->SetEvolveFunction(&ControllableBatch::EvolveInFreeToCongestingBehaviourMiddlePlaceWithContactFreeBatch); + cbi++; + } + } +} + + +//------------------------------------------------------------------------------ +// It sets the evolution function to an uncongesting batch +//------------------------------------------------------------------------------ +void TriangularBatchPlace::SetFunctionUncongestingBatch(list<ControllableBatch>::iterator cbi, int i) +{ + double diffdensity; + double downflow; + + list<ControllableBatch>::iterator pcbi = prev(cbi); + list<ControllableBatch>::iterator ncbi = next(cbi); + + int cbiisoutputbatch = cbi->IsOutputControllableBatch(this); + int pcbiisoutputbatch = pcbi->IsOutputControllableBatch(this); + + cbi->SetEvolveFunction(&ControllableBatch::EvolveInFreeBehaviour); // default case + + if (cbiisoutputbatch){ + downflow = GetOutputTransitonsFlow(); + diffdensity = pcbi->GetDensity() - (downflow/instantaneousspeed); + if (abs(diffdensity) <= PRF::prf.Min_Err()){ + if (cbi->GetBehaviour() == Uncongesting_behaviour){ + cbi->SetEvolveFunction(&ControllableBatch::EvolveInUncongestingOutputBehaviour); + } + } + else{ + ControllableBatch *newcb = new ControllableBatch; + newcb->Copy(*cbi); + + newcb->SetLength(0.0); + newcb->SetDensity(downflow/instantaneousspeed); + newcb->SetSpeed(instantaneousspeed); + newcb->SetEvolveFunction(&ControllableBatch::EvolveInFreeToCongestingBehaviourCongBatch); + marks->insert(cbi, *newcb); // create a copy of the current batch + + //update batches evolve functions + cbi->SetEvolveFunction(&ControllableBatch::EvolveInFreeToCongestingBehaviourFreeBatch); + cbi++; + } + } + else{ + if (!cbiisoutputbatch && (i == 0)){ + // create a new batch + ControllableBatch *newcb = new ControllableBatch; + newcb->Copy(*cbi); + + newcb->SetLength(0.0); + newcb->SetDensity(GetCriticalDensity()); + newcb->SetSpeed(instantaneousspeed); + newcb->SetEvolveFunction(&ControllableBatch::EvolveInUncongestingToFreeBehaviourFreeBatch); + marks->insert(cbi, *newcb); // create a copy of the current batch + + //update batches evolve functions + cbi->SetEvolveFunction(&ControllableBatch::EvolveInUncongestingToFreeBehaviourCongBatch); + cbi++; + } + else{ + if (!cbiisoutputbatch && (i != 0) && cbi->IsInContactWithByFront(*pcbi)){ + ControllableBatch *newcb = new ControllableBatch; + newcb->Copy(*cbi); + if ((pcbi->GetState(this) == Congested_st) && pcbi->GetSpeed() > cbi->GetSpeed()){ + newcb->SetLength(0.0); + newcb->SetDensity(pcbi->GetDensity()); + newcb->SetSpeed(pcbi->GetSpeed()); + //update batches evolve functions + newcb->SetEvolveFunction(&ControllableBatch::EvolveInFreeToCongestingBehaviourMiddlePlaceWithContactCongBatch); + marks->insert(cbi, *newcb); // create a copy of the current batch + cbi->SetEvolveFunction(&ControllableBatch::EvolveInFreeToCongestingBehaviourMiddlePlaceWithContactFreeBatch); + } + else{ + newcb->SetLength(0.0); + newcb->SetDensity(GetCriticalDensity()); + newcb->SetSpeed(instantaneousspeed); + //update batches evolve functions + newcb->SetEvolveFunction(&ControllableBatch::EvolveInUncongestingToFreeBehaviourFreeBatch); + cbi->SetEvolveFunction(&ControllableBatch::EvolveInUncongestingToFreeBehaviourCongBatch); + marks->insert(cbi, *newcb); // create a copy of the current batch + } + cbi++; + } + } + } +} + +//------------------------------------------------------------------------------ +// It evolves the marks (controllable batches) of the triangular batch place +//------------------------------------------------------------------------------ +void TriangularBatchPlace::EvolveMarks(double _date) +{ +/* cout << "========================\n" << "Before evolution\n" << "========================\n"; + for (list<ControllableBatch>::iterator cbi=marks->begin(); cbi!=marks->end(); ++cbi) { + cbi->Print(ofstream &fout); + } +*/ + for (list<ControllableBatch>::iterator cbi=marks->begin(); cbi!=marks->end(); ++cbi) { + EvolveControllableBatch(cbi, _date); + // fixerror? + } +/* cout << "========================\n" << "After evolution\n" << "========================\n"; + for (list<ControllableBatch>::iterator cbi=marks->begin(); cbi!=marks->end(); ++cbi) { + cbi->Print(ofstream &fout); + } +*/ +} + +//------------------------------------------------------------------------------ +// It evolves a specific controllable batch +// TODO: verify first and last batch +//------------------------------------------------------------------------------ +void TriangularBatchPlace::EvolveControllableBatch(list<ControllableBatch>::iterator cbi, double _date) +{ + list<ControllableBatch>::iterator pcbi = cbi; + list<ControllableBatch>::iterator ncbi = cbi; + ControllableBatch *cb, *pcb, *ncb; + + pcbi--; + ncbi++; + + cb = (ControllableBatch*) &(*cbi); + pcb = (ControllableBatch*) &(*pcbi); + ncb = (ControllableBatch*) &(*ncbi); + + cb->Evolve(simulation->stime, this, pcb, ncb); +} + +//------------------------------------------------------------------------------ +// It computes the date of the next event to a Controllable Batch becomes an Output Batch type +// returns -1.0 if no BOB event is possible +//------------------------------------------------------------------------------ +double TriangularBatchPlace::GetBOBEvent() +{ + double cbpos; + double cbspeed; + double date; + ControllableBatch cb; + + if (marks->empty()){ + return (-1.0); // no event of this type + } + + if (state != 1.0){ + cb = marks->front(); + cbpos = cb.GetPosition(); + cbspeed = cb.GetSpeed(); + date = (length - cbpos) / cbspeed; + date += simulation->stime->GetCurrentDate(); + return (date); + } + return (-1.0); +} + + +//------------------------------------------------------------------------------ +// It computes the date of the next event to a Destruction of an Output Batch type +//------------------------------------------------------------------------------ +double TriangularBatchPlace::GetDOBEvent() +{ + double date = -1.0; + double outputflow = GetOutputTransitonsFlow(); + ControllableBatch *ocb; + + if (HasOutputBatch() == 1){ + ocb = GetOutputControllableBatch(); + if (ocb->GetState(this) == Free_st){ // free state + if ((ocb->GetBehaviour() == Free_behaviour) && (instantaneousspeed != 0.0)){ + date = simulation->stime->GetCurrentDate() + (ocb->GetLength()/ocb->GetSpeed()); + } + } + else{ + if((outputflow != 0.0) && ((ocb->GetBehaviour() == Free_behaviour))) { +// date = simulation->stime->GetCurrentDate() + cb->GetLength() * GetCongestionDensity() / outputflow; + date = ocb->GetLength() * ocb->GetDensity() / outputflow; + date += simulation->stime->GetCurrentDate(); + } + } + } + return (date); +} + +//------------------------------------------------------------------------------ +// It computes the date of the next event to a Full accumulation/congestion of any batch +// (Batch Becomes Dense) type +//------------------------------------------------------------------------------ +double TriangularBatchPlace::GetBBDEvent() +{ + double date = -1.0; + double mindate = -1.0; + int i = 0; + double diffdensity; // difference of densities + double outputtransitionflow; + double congesteddensity; + ControllableBatch *ocb; + list<ControllableBatch>::iterator pcb; // previous controllable batch + + i = 0; + for (list<ControllableBatch>::iterator cb=marks->begin(); cb!=marks->end(); ++cb, i++) { + if (cb->IsOutputControllableBatch(this)) { // congestion of the output batch + congesteddensity = GetCongestionDensity(); + if ((cb->GetBehaviour() == Congesting_behaviour) && (abs(congesteddensity - cb->GetDensity()) > PRF::prf.Min_Err())){ + outputtransitionflow = GetOutputTransitonsFlow(); + date = cb->GetLength() * (congesteddensity - cb->GetDensity()) / (cb->GetSpeed() * congesteddensity - outputtransitionflow); + date = date + simulation->stime->GetCurrentDate(); + } + } + else{ + if (i != 0){ + pcb = cb; + pcb--; + + diffdensity = pcb->GetDensity() - cb->GetDensity(); + + if (cb->IsInContactWithByFront(*pcb) && (diffdensity > PRF::prf.Min_Err())){ // in contact, compute date to full congestion + date = (cb->GetLength() * diffdensity) / ((cb->GetSpeed() * pcb->GetDensity()) - (pcb->GetSpeed() * pcb->GetDensity())) ; + date = date + simulation->stime->GetCurrentDate(); + } + } + } + // get the minimal date + if ((mindate > date) || (mindate == -1.0)) { + mindate = date; + } + } + + return (mindate); +} + +//------------------------------------------------------------------------------ +// It computes the date of the next event to a Two Batches Meet +//------------------------------------------------------------------------------ +double TriangularBatchPlace::GetTBMEvent() +{ + + double date = -1.0; + double mindate = -1.0; + int i = 0; + double diffdensity; // difference of densities + list<ControllableBatch>::iterator pcb; // previous controllable batch + + if (marks->size() <= 1) + return(date); + + i = 0; + for (list<ControllableBatch>::iterator cb=marks->begin(); cb!=marks->end(); ++cb, i++) { + if (cb->IsOutputControllableBatch(this) || i==0 ) // not previous lot + continue; + + pcb = cb; + pcb--; + + if (pcb->GetState() == Free_st) // Front batch is a free batch + continue; + + if ((pcb->GetState() == Congested_st) && (pcb->IsOutputControllableBatch(this))) + continue; // bmob event + + diffdensity = pcb->GetDensity() - cb->GetDensity(); + + + if (((cb->GetSpeed() - pcb->GetSpeed()) > PRF::prf.Min_Err()) && (diffdensity > PRF::prf.Min_Err())) { // compute meeting date + date = simulation->stime->GetCurrentDate() + + (cb->GetPosition() - pcb->GetPosition() + pcb->GetLength()) / (pcb->GetSpeed() - cb->GetSpeed()) ; + } + + // get the minimal date + if ((mindate > date) || (mindate == -1.0)) { + mindate = date; + } + } + + return (mindate); +} + +//------------------------------------------------------------------------------ +// It computes the date of the next event to a Batch Meets Output Batch +// TODO: review this method +//------------------------------------------------------------------------------ +double TriangularBatchPlace::GetBMOBEvent() +{ + double date = -1.0; + double outputtransitionflow; + double congesteddensity; + ControllableBatch *ocb; + list<ControllableBatch>::iterator cb; + + +/* if ((HasOutputBatch() == 0) || (marks->size() <= 1)){ + return (date); + } + + ocb = GetOutputControllableBatch(); + cb = marks->begin(); + cb++; + congesteddensity = GetCongestionDensity(); + + if (//(abs(congesteddensity - ocb->GetDensity()) < PRF::prf.Min_Err()) && + (ocb->GetState() == Congested_st)){ // output batch is congested + outputtransitionflow = GetOutputTransitonsFlow(); + if ((cb->GetBehaviour() != Congesting_behaviour) && (!cb->IsInContactWithByFront(*ocb))){ // batches are not in contact + if (((congesteddensity * cb->GetSpeed()) - outputtransitionflow) != 0){ // maybe congesteddensity is ocb->density + date = simulation->stime->GetCurrentDate() + + (congesteddensity * (length - ocb->GetLength() - cb->GetPosition()) / ( (cb->GetSpeed() * congesteddensity) - outputtransitionflow)); + } + } + else{ + if (((congesteddensity - cb->GetDensity()) > PRF::prf.Min_Err()) && (cb->GetLength() > PRF::prf.Min_Err()) && + (cb->GetSpeed() > PRF::prf.Min_Err()) && (abs(congesteddensity - cb->GetDensity()) > PRF::prf.Min_Err())){ + date = simulation->stime->GetCurrentDate() + + (((congesteddensity - cb->GetDensity()) * cb->GetLength()) / ((cb->GetSpeed() * congesteddensity) - outputtransitionflow)); + } + } + } +*/ + return (date); + +} + +//------------------------------------------------------------------------------ +// It computes the date of the next event to Output Batch Decongestion +//------------------------------------------------------------------------------ +double TriangularBatchPlace::GetOBDEvent() +{ + double date = -1; + double outflow; + double ddensity; + ControllableBatch *ocb; + + if (HasOutputBatch() == 0) + return (date); + + outflow = GetOutputTransitonsFlow(); + ddensity = outflow / GetInstantaneousSpeed(); + ocb = GetOutputControllableBatch(); + + if ((ocb->GetBehaviour() == Uncongesting_behaviour) && (abs(ocb->GetDensity() - ddensity) > PRF::prf.Min_Err())){ + if (abs(ocb->GetSpeed() * ddensity - outflow) > PRF::prf.Min_Err()){ + date = ( simulation->stime->GetCurrentDate() + + (ocb->GetLength() * (ddensity - ocb->GetDensity())) / ((ocb->GetSpeed() * ddensity) - outflow)); + } + } + return (date); +} + +//------------------------------------------------------------------------------ +// It computes the date of the next event to Batch Decongestion +// TODO : review this method for all batches +//------------------------------------------------------------------------------ +double TriangularBatchPlace::GetBDEvent() +{ + int i = 0; + double date = -1; + double mindate = -1; + double diffdensity; // difference of densities + list<ControllableBatch>::iterator pcb; // previous controllable batch + + if (marks->size() <= 1) + return(date); + + i = 0; + for (list<ControllableBatch>::iterator cb=marks->begin(); cb!=marks->end(); ++cb, i++) { + if (i == 0) // BBF event + continue; + + if (cb->IsOutputControllableBatch(this)) + continue; // OBD event + + if (cb->GetBehaviour() != Uncongesting_behaviour) + continue; + + pcb = cb; + pcb--; + + if (!cb->IsInContactWithByFront(*pcb)) // BFF event + continue; + + diffdensity = pcb->GetDensity() - cb->GetDensity(); + if (((cb->GetSpeed() - pcb->GetSpeed()) < PRF::prf.Min_Err()) && (diffdensity < PRF::prf.Min_Err())) { // verify if need diffdensity + date = (cb->GetLength() * diffdensity) / ((cb->GetSpeed() * pcb->GetDensity()) - (pcb->GetSpeed() * pcb->GetDensity())); + date = date + simulation->stime->GetCurrentDate(); + } + + // get the minimal date + if ((mindate > date) || (mindate == -1.0)) { + mindate = date; + } + } + return (date); +} + +//------------------------------------------------------------------------------ +// It computes the date of the next event to Batch Becomes Free +//------------------------------------------------------------------------------ +double TriangularBatchPlace::GetBBFEvent() +{ + double date = -1; + double mindate = -1; + int i = 0; + list<ControllableBatch>::iterator pcb; // previous controllable batch + + i = 0; + for (list<ControllableBatch>::iterator cb=marks->begin(); cb!=marks->end(); ++cb, i++) { + if (cb->IsOutputControllableBatch(this)) + continue; + if (cb->GetBehaviour() != Uncongesting_behaviour) + continue; + + pcb = cb; + pcb--; + + if ((i == 0) || (!cb->IsInContactWithByFront(*pcb))){ + date = (cb->GetLength() * (GetCriticalDensity() - cb->GetDensity())) / ((cb->GetSpeed() * GetCriticalDensity()) - (instantaneousspeed * GetCriticalDensity())); + date = date + simulation->stime->GetCurrentDate(); + + } + + // get the minimal date + if ((mindate > date) || (mindate == -1.0)) { + mindate = date; + } + } + return (date); +} + + + +//------------------------------------------------------------------------------ +// Print +//------------------------------------------------------------------------------ +void TriangularBatchPlace::Print(ostream &fout) +{ fout << "Name: " << name << endl; + fout << " Type: " << "Triangular Batch" << endl; + fout << " Behaviour: " << behaviour << endl; + fout << " Density: " << density << endl; + fout << " Maximum speed: " << maxspeed << endl; + fout << " Speed: " << speed << endl; + fout << " Length: " << length << endl; + fout << " Maximum Flow: " << maxflow << endl; + fout << " Flow: " << flow << endl; + fout << " Initial Tr. Batches:" << initialmarks->size() << endl; + + for (list<ControllableBatch>::iterator it=initialmarks->begin(); it!=initialmarks->end(); ++it) { + it->GetState(this); + it->Print(fout); + } + + if (!steadymarks->empty()){ + fout << " Steady Tr. Batches: " << steadymarks->size() << endl; + + for (list<ControllableBatch>::iterator it=steadymarks->begin(); it!=steadymarks->end(); ++it) { + it->GetState(this); + it->Print(fout); + } + } + + fout << " Triangular Batches: " << marks->size() << endl; + + for (list<ControllableBatch>::iterator it=marks->begin(); it!=marks->end(); ++it) { + it->GetState(this); + it->Print(fout); + } + fout << " Arcs: " << endl; + PrintArcs(fout); +} + + +//------------------------------------------------------------------------------ +// Write +//------------------------------------------------------------------------------ +void TriangularBatchPlace::Write(ostream &fout) +{ + fout << "Name: " << name << endl; + fout << " Type: " << "Triangular Batch" << endl; + fout << " Density: " << density << endl; + fout << " Speed: " << speed << endl; + fout << " Length: " << length << endl; + fout << " Flow: " << flow << endl; + fout << " Batches: " << marks->size() << endl; + + for (list<ControllableBatch>::iterator it=marks->begin(); it!=marks->end(); ++it) { + it->GetState(this); + it->Write(fout); + } +} diff --git a/src/interf/bpnfile.h b/src/interf/bpnfile.h new file mode 100644 index 0000000000000000000000000000000000000000..6f8ec246ec4c5e69deaca1ee2b1c3dc84d03b0bc --- /dev/null +++ b/src/interf/bpnfile.h @@ -0,0 +1,5 @@ +#include "simuleau.h" +#include "y.tab.h" +#include "error_msgs.h" + +using namespace std; diff --git a/src/interf/error_msgs.h b/src/interf/error_msgs.h new file mode 100644 index 0000000000000000000000000000000000000000..1cfceb4b258bed2da3445a1c67c6e54f27677213 --- /dev/null +++ b/src/interf/error_msgs.h @@ -0,0 +1,92 @@ +//====================================================================================// +// // +// Error Messages // +// // +//====================================================================================// +// This File: error_msgs.h Language: C++ (xlC and CC) // +// Software: SIMULEAU // +//====================================================================================// +// Creation: 12/apr/16 by: Leonardo.Brenner@lsis.org // +// Last Change: 12/apr/16 by: Leonardo.Brenner@lsis.org // +//====================================================================================// +// This file has macro definitions to put error messages of SIMULEAU parser // +//====================================================================================// +#ifndef _ERROR_MSGS_H_ +#define _ERROR_MSGS_H_ + +#define Lexical_Error(yacc_number, yacc_line, id) \ + cout << " " << yacc_number \ + << ":Line(" << yacc_line \ + << ") - Lexical Error - \"" << id \ + << "\" is an unrecognized symbol." \ + << endl; + +#define Syntatic_Error(yacc_number, yacc_line, str, id) \ + cout << " " << yacc_number \ + << ":Line(" << yacc_line \ + << ") - " << str << " - \"" << id \ + << "\" (not expected)." \ + << endl; + +#define Semantic_Error_YACC(yacc_number, yacc_line, id, number) \ + cout << " " << yacc_number \ + << ":Line(" << yacc_line \ + << ") - Semantic Error - " << id \ + << " - (" << number << ")." \ + << endl; + +#define Semantic_Error(text, number) \ + cout << "Semantic Error - " << number << " (** " \ + << text << " **).\n"; + +#define Semantic_Warning(text_1, text_2, number) \ + cout << "Semantic Warning - " << number << " (** " \ + << text_1 << " - " << text_2 << " **)." \ + << endl; + +#define Programming_Error1(text) \ + cout << "Programming Error - at \"" << text \ + << "\" (file '" << __FILE__ << "' - line " << __LINE__ << ")" \ + << endl; + +#define Programming_Error2(text, number) \ + cout << "Programming Error - " << number << " (at " \ + << text << ")\n" \ + << "(file '" << __FILE__ << "' - line " << __LINE__ << ")" \ + << endl; + +// Semantic Errors - YACC (00 .. 99) +#define Parser_00 "Place name already defined in this model" +#define Parser_01 "Transition name already defined in this model" +#define Parser_02 "can not solve identifier." +#define Parser_03 "automaton identifier already defined." +#define Parser_04 "event not declared." +#define Parser_05 "state identifier already defined for this automaton." +#define Parser_06 "state identifier already defined as function identifier." + +// Semantic Errors - ordinary files (100 - 199) +#define Parser_100 "Functions are only defined for batch or triangular batch places" +#define Parser_101 "The flow parameter are only defined for triangular batch places" +#define Parser_102 "The flow parameter must be defined for triangular batch places" +#define Parser_103 "The marking of batches or triangular batches is a list of batches" +#define Parser_104 "The marking of discrete places is an integer" +#define Parser_105 "The marking of discrete places is a float" +#define Parser_106 "Transition arc destination doesn't exist" +#define Parser_107 "Place arc destination doesn't exist" +#define Parser_108 "Bad arc destination (no arc allowed from batch/triangular batch place and discrete transition)" +#define Parser_109 "Place or transition doesn't exist" +#define Parser_110 "Transition doesn't exist" +#define Parser_111 "Place doesn't exist" +#define Parser_112 "Speed modification are only allowed for triangular batch places" +#define Parser_113 "Flow modification are only allowed for continuous or batch transitions" +#define Parser_114 "Wrong interval (final limit appears before initial)." +#define Parser_115 "Bad destination state (this operation cannot be used with the \'from\' primitive)" +#define Parser_116 "Bad destination state (this operation can be used only in a replicated state)" + +// Programming Errors (200 - 299) +#define Parser_200 "Out of range (see FUNCTION define)." +#define Parser_201 "Index out of range." +#define Parser_202 "Can not alloc memory." + + +#endif diff --git a/src/interf/glc.y b/src/interf/glc.y new file mode 100644 index 0000000000000000000000000000000000000000..35b7e211957a973746148bbe6a42c8037485bfc5 --- /dev/null +++ b/src/interf/glc.y @@ -0,0 +1,773 @@ +%{ +//====================================================================================// +// // +// Parser and Semantic Analysis // +// // +//====================================================================================// +// This File: glc.y Tool: YACC // +// Software: SIMULEAU // +//====================================================================================// +// Creation: 15/apr/16 by: Leonardo.Brenner@lsis.org // +// Last Change: 15/apr/16 by: Leonardo.Brenner@lsis.org // +//====================================================================================// +// YACC is a general-purpose parser generator that converts a context-free grammar // +// a C program.In this module are make the actions to generate the internal SAN's // +// tables and the others functionalities of this textual interface for PEPS. // +//====================================================================================// +#include "bpnfile.h" +#include "simuleau.h" + +//====================================================================================// +// Global variables // +//====================================================================================// + +extern BPN *bpn; // Network structure +extern Schedule *schedule; // schedule structure + +int not_error = 1; +int is_integer = 1; + +int tour; // Set the times that the parser was called, the first to count the number + // of places, the number of transitions and others + +//====================================================================================// +// Variables // +//====================================================================================// + + int discreteplaces; // number of discrete places + int continuousplaces; // number of continuous places + int batchplaces; // number of batch places + int triangularplaces; // number of triangular batch places + + int currentdiscreteplace; // index of the current discrete place used to add place + int currentcontinuousplace; // index of the current continuous place + int currentbatchplace; // index of the current batch place + int currenttriangularplace; // index of the current triangular batch place + + int discretetransitions; // number of discrete transitions + int continuoustransitions; // number of continuous transitions + int batchtransitions; // number of batch transitions + + int currentdiscretetransition; // index of the current discrete place used to add place + int currentcontinuoustransition;// index of the current continuous place + int currentbatchtransition; // index of the current batch place + + place_id idplacenumber; // number of the place id + simuleau_name idplace; // name of the place id + place_type ptype; // place type + double pdensity; // place density + double pspeed; // place speed + double plength; // place length + double pflow; // place flow + + double bdensity; // batch density + double bspeed; // batch speed + double blength; // batch length + double bposition; // batch position + + trans_id idtransitionnumber; // number of the transition id + simuleau_name idtransition; // name of the transition id + trans_type ttype; // transition type + double ttime; // time of the discrete transitions + double tsteadytime; // steady time of the discrete transitions + double tflow; // flow of the continuous and batch transitions + double tsteadyflow; // steady flow of the continuous and batch transitions + + double arcweight; // arc weight + + simuleau_name idcevent; // name of the controlled event + ev_type cetype; // type of the controlled event + simuleau_name idnode; // name of the place or transition + double cedate; // controlled event date + double cevalue; // new value of the flow/speed + + simuleau_name idbreakpoint; // name of the breakpoint + breakpoint_type bptype; // type of the breakpoint (at (?) or every (*)) + double bpdate; // date or frequency + + +//====================================================================================// +// Parser variables // +//====================================================================================// + +extern int yynerrs; // Variable of the YACC generator to count the number of errors. +extern int yylineno; // Variable of the YACC generator to count the current line + +extern int yylex(void); // Get the next token +extern void yyrestart(FILE *input_file); +extern char *yytext; +extern FILE *yyin; // Input file + + +//====================================================================================// +// Function errors // +//====================================================================================// +// These functions analysis which error occurred and put the error into a message // +// more specific. // +//====================================================================================// + + +//==================================================================================== +// Function that YACC use to put syntatic message errors +//==================================================================================== +extern void yyerror(string s) +{ + yynerrs++; + not_error = 0; + Syntatic_Error(yynerrs, yylineno, s, yytext); +} + +//==================================================================================== +// Function to put semantic error messages +//==================================================================================== +void type_error(char* text, const char* error_number) +{ + yynerrs++; + not_error = 0; + Semantic_Error_YACC(yynerrs, yylineno, text, error_number); +} + + +%} + + //-----------------------------------------------------------// + // Definition of tokens (terminals) of the grammar. // + // YACC used these definitions to generate the file // + // y.tab.h that is included in a LEX file (tokens.l) // + //-----------------------------------------------------------// + +%token TK_ARC TK_BATCH TK_CONTINUOUS TK_CONTROLLED TK_DESCRIPTION +%token TK_DISCRETE TK_EVENTS TK_FLOW TK_FUNCTION TK_INITIAL TK_INSPECTION +%token TK_LENGTH TK_MARKING TK_MODEL TK_NETWORK TK_OUTPUT TK_PLACE +%token TK_PLACES TK_SPEED TK_STEADY TK_TIME TK_TIMING TK_TRANSITION TK_TRANSITIONS +%token TK_TRIANGULAR TK_UNITY TK_ID TK_INTEGER TK_REAL TK_EXPONENT TK_AT +%token TK_EVERY TK_LEFT_BRACKET TK_RIGHT_BRACKET TK_PL_TR TK_ALL +%token TK_LEFT_PARENTHESIS TK_RIGHT_PARENTHESIS +%token TK_LEFT_SQUARE_BRACKET TK_RIGHT_SQUARE_BRACKET +%token TK_SEMICOLON TK_COMMA TK_ATTRIB TK_COLON + +%% + + //-----------------------------------------------------------// + // Begin of grammar // + //-----------------------------------------------------------// + +start:blk_def blk_net blk_controlled_events blk_time_inspection + ; + + //-----------------------------------------------------------// + // Block of definitions (model name, length and time unity) // + //-----------------------------------------------------------// + +blk_def: + blk_model blk_unity + ; + +blk_model: + TK_MODEL TK_ID {if (tour == 1) bpn->PutName(yytext);} semi_colon + | + ; + +blk_unity: + blk_lenght blk_time + ; + +blk_lenght: + TK_LENGTH TK_UNITY TK_ATTRIB TK_ID {PRF::prf.Length_Unity(yytext);} semi_colon + | + ; + +blk_time: + TK_TIME TK_UNITY TK_ATTRIB TK_ID {PRF::prf.Time_Unity(yytext);} semi_colon + | + ; + +semi_colon: + TK_SEMICOLON + | + ; + +number: + TK_REAL { is_integer = 0; } + |TK_INTEGER { is_integer = 1; } + |TK_EXPONENT { is_integer = 0; } + ; + + + //-----------------------------------------------------------// + // Block to network description // + //-----------------------------------------------------------// + +blk_net: + TK_NETWORK TK_DESCRIPTION blk_places blk_transitions + ; + +blk_places: + TK_PLACES { cout << "Compiling places\n";} blk_place + ; + +blk_transitions: + TK_TRANSITIONS { cout << "Compiling transitions\n";} blk_transition + ; + + + //-----------------------------------------------------------// + // Block to place description // + //-----------------------------------------------------------// + +blk_place: + TK_PLACE TK_ID + { strcpy(idplace,yytext); + if (tour == 1) { + if (bpn->VerifyName(idplace)) + type_error(idplace, Parser_00); + } + } TK_LEFT_PARENTHESIS blk_place_type TK_RIGHT_PARENTHESIS + blk_function + { if (tour == 1) { + Place *newp; + switch (ptype) { + case Discrete_pl : newp = new DiscretePlace(idplace); + bpn->AddPlace(currentdiscreteplace, newp); + currentdiscreteplace++; + break; + case Continuous_pl : newp = new ContinuousPlace(idplace); + bpn->AddPlace(currentcontinuousplace, newp); + currentcontinuousplace++; + break; + case Batch_pl : newp = new BatchPlace(idplace, pspeed, pdensity, plength); + bpn->AddPlace(currentbatchplace, newp); + currentbatchplace++; + break; + case Triangular_pl : newp = new TriangularBatchPlace(idplace, pspeed, pdensity, plength, pflow); + bpn->AddPlace(currenttriangularplace, newp); + currenttriangularplace++; + break; + } + } + } blk_initial_marking blk_steady_marking blk_place_arcs blk_place2 + ; + +blk_place2: + blk_place + | + ; + +blk_place_type: + TK_DISCRETE { discreteplaces++; ptype = Discrete_pl; } + | TK_CONTINUOUS { continuousplaces++; ptype = Continuous_pl; } + | TK_BATCH { batchplaces++; ptype = Batch_pl; } + | TK_TRIANGULAR{ triangularplaces++; ptype = Triangular_pl;} + ; + + //-----------------------------------------------------------// + // Block to function description for batch places // + //-----------------------------------------------------------// + +blk_function: + TK_FUNCTION { if ((ptype != Batch_pl) && (ptype != Triangular_pl)) { + type_error(yytext, Parser_100); + } + } TK_LEFT_PARENTHESIS number { pspeed = atof(yytext); } + TK_COMMA number { pdensity = atof(yytext); } + TK_COMMA number { plength = atof(yytext); } blk_triangular_place TK_RIGHT_PARENTHESIS + | + ; + +blk_triangular_place: + TK_COMMA number { if (ptype != Triangular_pl) { + type_error(yytext, Parser_101); + } + pflow = atof(yytext); } + | { if (ptype == Triangular_pl) { + yyerror(Parser_102); + } + } + ; + //-----------------------------------------------------------// + // Block to initial marking description // + //-----------------------------------------------------------// + +blk_initial_marking: + TK_INITIAL TK_MARKING TK_LEFT_BRACKET blk_initial_marking_int TK_RIGHT_BRACKET + ; + +blk_initial_marking_int: + number + { if (tour == 1){ + switch (ptype) { + case Discrete_pl : if (!is_integer){ + type_error(yytext, Parser_104); + } + else{ + bpn->SetInitialMarking((currentdiscreteplace-1), atoi(yytext)); + } + break; + case Continuous_pl : bpn->SetInitialMarking((currentcontinuousplace-1), atof(yytext)); + break; + case Batch_pl : + case Triangular_pl : type_error(yytext, Parser_103); + break; + } + } + } + | blk_batch + ; + +blk_batch: + TK_LEFT_PARENTHESIS number { blength = atof(yytext); } TK_COMMA number { bdensity = atof(yytext); } + TK_COMMA number { bposition = atof(yytext); } blk_triangular_batch TK_RIGHT_PARENTHESIS + { if (tour == 1){ + Batch *newb; + ControllableBatch *newcb; + switch (ptype) { + case Discrete_pl : type_error(yytext, Parser_104); + break; + case Continuous_pl : type_error(yytext, Parser_105); + break; + case Batch_pl : newb = new Batch(blength, bdensity, bposition); + bpn->AddBatchToInitialMarking((currentbatchplace-1), *newb); + break; + case Triangular_pl : newcb = new ControllableBatch(blength, bdensity, bposition, bspeed); + bpn->AddTriangularToInitialMarking((currenttriangularplace-1), *newcb); + break; + } + } + } blk_batch2 + | + ; + +blk_batch2: + TK_COMMA blk_batch + | + ; + +blk_triangular_batch: + TK_COMMA number { bspeed = atof(yytext); } + | { bspeed = -1;} + ; + + //-----------------------------------------------------------// + // Block to steady marking description // + //-----------------------------------------------------------// + +blk_steady_marking: + TK_STEADY TK_MARKING TK_LEFT_BRACKET blk_steady_marking_int TK_RIGHT_BRACKET + | + ; + +blk_steady_marking_int: + number + { if (tour == 1){ + switch (ptype) { + case Discrete_pl : if (!is_integer){ + type_error(yytext, Parser_104); + } + else{ + bpn->SetSteadyMarking((currentdiscreteplace-1), atoi(yytext)); + } + break; + case Continuous_pl : bpn->SetSteadyMarking((currentcontinuousplace-1), atof(yytext)); + break; + case Batch_pl : + case Triangular_pl : type_error(yytext, Parser_103); + break; + } + } + } + | blk_steady_batch + ; + +blk_steady_batch: + TK_LEFT_PARENTHESIS number { blength = atof(yytext); } TK_COMMA number { bdensity = atof(yytext); } + TK_COMMA number { bposition = atof(yytext); } blk_steady_triangular_batch TK_RIGHT_PARENTHESIS + { if (tour == 1){ + Batch *newb; + ControllableBatch *newcb; + switch (ptype) { + case Discrete_pl : type_error(yytext, Parser_104); + break; + case Continuous_pl : type_error(yytext, Parser_105); + break; + case Batch_pl : newb = new Batch(blength, bdensity, bposition); + bpn->AddBatchToSteadyMarking((currentbatchplace-1), *newb); + break; + case Triangular_pl : newcb = new ControllableBatch(blength, bdensity, bposition, bspeed); + bpn->AddTriangularToSteadyMarking((currenttriangularplace-1), *newcb); + break; + } + } + } blk_steady_batch2 + | + ; + +blk_steady_batch2: + TK_COMMA blk_steady_batch + | + ; + +blk_steady_triangular_batch: + TK_COMMA number { bspeed = atof(yytext); } + | { bspeed = -1;} + ; + + //-----------------------------------------------------------// + // Block to place arcs description // + //-----------------------------------------------------------// + +blk_place_arcs: + TK_OUTPUT TK_ARC TK_ID { strcpy (idtransition, yytext); } blk_place_weight + { if (tour == 2){ + idplacenumber = bpn->GetPlacePosition(idplace); + idtransitionnumber = bpn->GetTransitionPosition(idtransition); + if (idtransitionnumber < 0){ + type_error(idtransition, Parser_106); + } + else{ + if ((bpn->GetTransitionType(idtransition) == Discrete_tr) && !((bpn->GetPlaceType(idplace) == Discrete_pl) || (bpn->GetPlaceType(idplace) == Continuous_pl))){ + type_error(idtransition, Parser_108); + } + else{ + bpn->AddPlaceOutputArc(idplacenumber, idtransitionnumber, arcweight); + } + } + } + } blk_place_arcs2 + | + ; + +blk_place_arcs2: + blk_place_arcs + ; + +blk_place_weight: + TK_LEFT_PARENTHESIS number { arcweight = atof(yytext); } TK_RIGHT_PARENTHESIS + | {arcweight = 1.0;} + ; + + + + //-----------------------------------------------------------// + // Block to transition description // + //-----------------------------------------------------------// + +blk_transition: + TK_TRANSITION TK_ID + { strcpy(idtransition,yytext); + if (tour == 1) { + if (bpn->VerifyName(idtransition)) + type_error(idtransition, Parser_01); + } + } TK_LEFT_PARENTHESIS blk_transition_type TK_RIGHT_PARENTHESIS + blk_transition_function + { tsteadytime = 0.0; + tsteadyflow = 0.0; + } + blk_steady_transition_function + { if (tour == 1) { + Transition *newt; + switch (ttype) { + case Discrete_tr : newt = new DiscreteTransition(idtransition, ttime, tsteadytime); + bpn->AddTransition(currentdiscretetransition, newt); + currentdiscretetransition++; + break; + case Continuous_tr : newt = new ContinuousTransition(idtransition, tflow, tsteadyflow); + bpn->AddTransition(currentcontinuoustransition, newt); + currentcontinuoustransition++; + break; + case Batch_tr : newt = new BatchTransition(idtransition, tflow, tsteadyflow); + bpn->AddTransition(currentbatchtransition, newt); + currentbatchtransition++; + break; + } + } + } + blk_transition_arcs blk_transition2 + ; + +blk_transition2: + blk_transition + | + ; + +blk_transition_type: + TK_DISCRETE {discretetransitions++; ttype = Discrete_tr; } + | TK_CONTINUOUS {continuoustransitions++; ttype = Continuous_tr; } + | TK_BATCH {batchtransitions++; ttype = Batch_tr; } + ; + +blk_transition_function: + TK_TIMING TK_LEFT_PARENTHESIS number { ttime = atof(yytext); } TK_RIGHT_PARENTHESIS + | TK_FLOW TK_LEFT_PARENTHESIS number { tflow = atof(yytext); } TK_RIGHT_PARENTHESIS + ; + +blk_steady_transition_function: + TK_STEADY blk_steady_transition_function_int + | + ; + +blk_steady_transition_function_int: + TK_TIMING TK_LEFT_PARENTHESIS number { tsteadytime = atof(yytext); } TK_RIGHT_PARENTHESIS + | TK_FLOW TK_LEFT_PARENTHESIS number { tsteadyflow = atof(yytext); } TK_RIGHT_PARENTHESIS + ; + + + //-----------------------------------------------------------// + // Block to transition arcs description // + //-----------------------------------------------------------// + + +blk_transition_arcs: + TK_OUTPUT TK_ARC TK_ID { strcpy (idplace, yytext); } blk_transition_weight + { if (tour == 2){ + idtransitionnumber = bpn->GetTransitionPosition(idtransition); + idplacenumber = bpn->GetPlacePosition(idplace); + if (idplacenumber < 0){ + type_error(idplace, Parser_107); + } + else{ + bpn->AddTransitionOutputArc(idtransitionnumber, idplacenumber, arcweight); + } + } + } blk_transition_arcs2 + | + ; + +blk_transition_arcs2: + blk_transition_arcs + ; + +blk_transition_weight: + TK_LEFT_PARENTHESIS number { arcweight = atof(yytext); } TK_RIGHT_PARENTHESIS + | {arcweight = 1.0;} + ; + + //-----------------------------------------------------------// + // Block to evaluation of controlled events // + //-----------------------------------------------------------// + +blk_controlled_events: + TK_CONTROLLED TK_EVENTS { cout << "Compiling controlled events\n";} controlled_events + | + ; + +controlled_events: + TK_ID { strcpy(idcevent,yytext); } TK_ATTRIB TK_LEFT_PARENTHESIS controlled_events_type TK_COMMA TK_ID { strcpy(idnode, yytext); } + TK_COMMA number { cevalue = atof(yytext); } TK_COMMA number { cedate = atof(yytext); } TK_RIGHT_PARENTHESIS semi_colon + { + if (tour == 1){ + Node *evnode = bpn->GetNode(idnode); + ControlledEvent *ev; + if (evnode){ + switch (cetype){ + case Trans_flow_ce : if (bpn->GetTransitionPosition(idnode) == -1){ + type_error(idnode, Parser_110); + } + else{ + if (bpn->GetTransitionType(idnode) == Discrete_tr) { + type_error(idnode, Parser_113); + } + else{ + ev = new ControlledEvent(idnode, *evnode, cedate, Trans_flow_ce, cevalue, idcevent); + schedule->AddControlledEvent(*ev, Trans_flow_ce); + } + } + break; + case Place_speed_ce : if (bpn->GetPlacePosition(idnode) == -1){ + type_error(idnode, Parser_111); + } + else{ + if (bpn->GetPlaceType(idnode) != Triangular_pl) { + type_error(idnode, Parser_112); + } + else{ + ev = new ControlledEvent(idnode, *evnode, cedate, Place_speed_ce, cevalue, idcevent); + schedule->AddControlledEvent(*ev, Place_speed_ce); + } + } + break; + } + } + else{ + type_error(idnode, Parser_109); + } + } + } controlled_events2 + | + ; + +controlled_events2: + controlled_events + ; + +controlled_events_type: + TK_FLOW { cetype = Trans_flow_ce; } + | TK_SPEED {cetype = Place_speed_ce; } + ; + + //-----------------------------------------------------------// + // Block to evaluation of time inspection // + //-----------------------------------------------------------// + +blk_time_inspection: + TK_TIME TK_INSPECTION { cout << "Compiling inspection points\n";} time_inspection + | + ; + +time_inspection: + TK_ID { strcpy(idbreakpoint,yytext); } TK_ATTRIB blk_op_time number { bpdate = atof(yytext); } blk_op_pt { strcpy(idnode, yytext); } semi_colon + { + if (tour == 1){ + Node *bpnode = bpn->GetNode(idnode); + Breakpoint *bp; + if ((bpnode) || (!strcmp(idnode, "places")) || (!strcmp(idnode, "transitions"))){ + bp = new Breakpoint(idnode, *bpnode, bpdate, bptype, idbreakpoint); + schedule->AddBreakpoint(*bp); + } + else{ + type_error(idnode, Parser_109); + } + } + } + time_inspection2 + | + ; + +time_inspection2: + time_inspection + ; + +blk_op_time: + TK_AT { bptype = at_bp; } + | TK_EVERY { bptype = every_bp; } + ; + +blk_op_pt: + TK_PL_TR TK_ID + | TK_ALL blk_pl_tr + ; + +blk_pl_tr: + TK_PLACES + | TK_TRANSITIONS + ; + +%% + + +void Init_Variables() +{ + yylineno = 0; + + //current place/transition + currentdiscreteplace = 0; + currentcontinuousplace = discreteplaces; + currentbatchplace = continuousplaces + discreteplaces; + currenttriangularplace = batchplaces + continuousplaces + discreteplaces; + + currentdiscretetransition = 0; + currentcontinuoustransition = discretetransitions; + currentbatchtransition = continuoustransitions + discretetransitions; +} + + +//int main(int argv, char *argc[]) +void Compile_Network(const simuleau_name bpn_level_name, const simuleau_name str_level_name) +{ + int totalplaces; + int totaltransitions; + ofstream fstr; + simuleau_name bpn_file; + + + strcpy(bpn_file, bpn_level_name); strcat(bpn_file,".bpn"); + + + //first tour: semantical analysis and number of places and transitions + tour = 0; + //counters + discreteplaces = 0; + continuousplaces = 0; + batchplaces = 0; + triangularplaces = 0; + + discretetransitions = 0; + continuoustransitions = 0; + batchtransitions = 0; + + Init_Variables(); + yyin = fopen(bpn_file, "r"); + cout << "Start model compilation\n\n"; + + cout << "First turn\n" + << "==========\n"; + cout << "Creating places and transitions structures\n"; + cout << "Creating controlled events schedule\n"; + yyparse(); + fclose(yyin); + + totalplaces = discreteplaces + continuousplaces + batchplaces + triangularplaces; + totaltransitions = discretetransitions + continuoustransitions + batchtransitions; + + if (bpn!=NULL) + delete bpn; + bpn = new BPN(totalplaces, totaltransitions); + + if (schedule!=NULL) + delete schedule; + schedule = new Schedule; + + // places initialisation + bpn->NumberOfDiscretePlaces(discreteplaces); + bpn->NumberOfContinuousPlaces(continuousplaces); + bpn->NumberOfBatchPlaces(batchplaces); + bpn->NumberOfTriangularBatchPlaces(triangularplaces); + + // transitions initialisation + bpn->NumberOfDiscreteTransitions(discretetransitions); + bpn->NumberOfContinuousTransitions(continuoustransitions); + bpn->NumberOfBatchTransitions(batchtransitions); + + + // second tour + if(!not_error){ + exit (EXIT_FAILURE); + } + + cout << "\nSecond turn\n" + << "===========\n"; + cout << "Initialising places and transitions parameters\n"; + tour++; + Init_Variables(); + yyin = fopen(bpn_file, "r"); + yyrestart(yyin); + yyparse(); + fclose(yyin); + + + // thrid tour + if(!not_error){ + exit (EXIT_FAILURE); + } + + cout << "\nThrid turn\n" + << "==========\n"; + cout << "Initialising places and transitions arcs\n"; + tour++; + bpn->AllocArcs(); + Init_Variables(); + yyin = fopen(bpn_file, "r"); + yyrestart(yyin); + yyparse(); + fclose(yyin); + bpn->AddNodeLinks(); + if(!not_error){ + exit (EXIT_FAILURE); + } + + cout << endl << bpn->GetName() << " model created\n"; + + Open_File(str_level_name, str_file, fstr); + bpn->Print(fstr); + Close_File(str_level_name, str_file, fstr); +} diff --git a/src/interf/interf.cpp b/src/interf/interf.cpp new file mode 100644 index 0000000000000000000000000000000000000000..34c0fb1f0d4abe53cdab0edd634183af5b5af85e --- /dev/null +++ b/src/interf/interf.cpp @@ -0,0 +1,690 @@ +//====================================================================================// +// // +// SIMULEAU User Interface // +// // +//====================================================================================// +// This File: interf.cpp Language: C++ (xlC and CC) // +// Software: SIMULEAU // +//====================================================================================// +// Creation: 12/apr/16 by: Leonardo.Brenner@lsis.org // +// Last Change: 12/apr/16 by: Leonardo.Brenner@lsis.org // +//====================================================================================// +#include "simuleau.h" + + + extern BPN *bpn; + extern Schedule *schedule; + extern Simulate *simulation; + +//====================================================================================// +// Simuleau Name Definitions // +//====================================================================================// + +const simuleau_name no_name = "\0"; // Default empty value for simuleau_name + +//====================================================================================// +// Internal Function Add_Extension // +//====================================================================================// +void Add_Extension(const simuleau_name file, const file_types ft, simuleau_name tmp) +{ + strcpy(tmp, file); + switch (ft) { + case bpn_file : strcat(tmp, ".bpn"); + break; + case str_file : strcat(tmp, ".str"); + break; + case xct_file : strcat(tmp, ".xct"); + break; + case dyn_file : strcat(tmp, ".dyn"); + break; + case tim_file : strcat(tmp, ".tim"); + break; + case dbg_file : strcat(tmp, ".dbg"); + break; + case prf_file : strcat(tmp, ".prf"); + break; + case dot_file : // no extension! + break; + default : strcat(tmp, ".err"); + } +} +//====================================================================================// +// Open_File (to input) // +//====================================================================================// +void Open_File(const simuleau_name file, const file_types ft, ifstream & f_tmp) +{ + simuleau_name n_tmp; + + Add_Extension(file, ft, n_tmp); + + // f_tmp.open(n_tmp, ios::nocreate); + f_tmp.open(n_tmp); + if (!f_tmp) + cerr << "System Error - Cannot open the file '" << n_tmp << "' (#### 0001 ####)" << endl; + else + f_tmp.precision(simuleau_precision); +} + +//====================================================================================// +// Open_File (to output) // +//====================================================================================// +void Open_File(const simuleau_name file, const file_types ft, ofstream & f_tmp) +{ + simuleau_name n_tmp; + + Add_Extension(file, ft, n_tmp); + f_tmp.open(n_tmp); + if (!f_tmp) + cerr << "System Error - Cannot open the file '" << n_tmp << "' (#### 0002 ####)" << endl; + else + f_tmp.precision(simuleau_precision); +} +//====================================================================================// +// Append_File (to output) // +//====================================================================================// +void Append_File(const simuleau_name file, const file_types ft, ofstream & f_tmp) +{ + simuleau_name n_tmp; + + Add_Extension(file, ft, n_tmp); + f_tmp.open(n_tmp, ios::app); + if (!f_tmp) + cerr << "System Error - Cannot open the file '" << n_tmp << "' (#### 0003 ####)" << endl; + else + f_tmp.precision(simuleau_precision); +} +//====================================================================================// +// Close_File (to input) // +//====================================================================================// +void Close_File(const simuleau_name file, const file_types ft, ifstream & f_tmp) +{ + simuleau_name n_tmp; + + Add_Extension(file, ft, n_tmp); + f_tmp.close(); + if (!f_tmp) + cerr << "System Error - Cannot close the file '" << n_tmp << "' (#### 0004 ####)" << endl; + else + cout << " :-) file '" << n_tmp << "' read\n"; +} +//====================================================================================// +// Close_File (to output) // +//====================================================================================// +void Close_File(const simuleau_name file, const file_types ft, ofstream & f_tmp) +{ + simuleau_name n_tmp; + + Add_Extension(file, ft, n_tmp); + f_tmp.close(); + if (!f_tmp) + cerr << "System Error - Cannot close the file '" << n_tmp << "' (#### 0005 ####)" << endl; + else + cout << " :-) file '" << n_tmp << "' saved\n"; +} +//====================================================================================// +// Exists_File // +//====================================================================================// +bool Exists_File(const simuleau_name file, const file_types ft) +{ + ifstream f_tmp; + simuleau_name n_tmp; + + Add_Extension(file, ft, n_tmp); + // f_tmp.open(n_tmp, ios::nocreate); + f_tmp.open(n_tmp); + if (f_tmp) { + return(true); + f_tmp.close(); + } + else + return(false); +} + +//====================================================================================// +// Create Temporary Directories // +//====================================================================================// +void Create_Temporary_Directories() +{ + struct stat st; + if(stat("str",&st) != 0){ + if (mkdir("str", S_IRWXU | S_IRWXG | S_IRWXO)) { + cerr << "System Error - Cannot create directory '" << "str" << "' (#### 0006 ####)" << endl; + } + } + if(stat("dbg",&st) != 0){ + if (mkdir("dbg", S_IRWXU | S_IRWXG | S_IRWXO)) { + cerr << "System Error - Cannot create directory '" << "dbg" << "' (#### 0006 ####)" << endl; + } + } + if(stat("dyn",&st) != 0){ + if (mkdir("dyn", S_IRWXU | S_IRWXG | S_IRWXO)) { + cerr << "System Error - Cannot create directory '" << "dyn" << "' (#### 0006 ####)" << endl; + } + } +} +//====================================================================================// +// Remove Temporary Directories // +//====================================================================================// +void Remove_Temporary_Directories() +{ + system("rm -rf str"); + system("rm -rf dbg"); + system("rm -rf dyn"); +} +//====================================================================================// +// Remove Probability Vectors // +//====================================================================================// +void Remove_Dynamics_Files() +{ + system("rm -f dyn/*.dyn"); +} +//====================================================================================// +// Remove Tim Files // +//====================================================================================// +void Remove_Tim_Files() +{ + system("rm -f *.tim"); +} + +//====================================================================================// +// Ask_a_File_Name // +//====================================================================================// +void Ask_a_File_Name(simuleau_name & name, const file_types ft) +{ + cout << "\nEnter "; + switch (ft) { + case bpn_file : cout << "textual BPN"; + break; + case str_file : cout << "internal representation of BPN structure"; + break; + case xct_file : cout << "textual external controlled events"; + break; + case dyn_file : cout << "dynamics log"; + break; + case tim_file : cout << "time report"; + break; + case dbg_file : cout << "debugging"; + break; + case prf_file : cout << "user preferences"; + break; + default : cout << "unrecognized"; + } + cout << " file name: "; + cin >> name; +} +//====================================================================================// +// Ask_an_Existing_File_Name // +//====================================================================================// +void Ask_an_Existing_File_Name(simuleau_name & name, const file_types ft) +{ + bool exists; + + do { + Ask_a_File_Name(name, ft); + exists = Exists_File(name, ft); + if (!exists) + cout << "This file can not be found!"; + } while (!exists); +} +//====================================================================================// +// Permission_to_Proceed // +//====================================================================================// +bool Permission_to_Proceed(const simuleau_name name, const file_types ft) +{ + bool answer = true; + char y_n; + simuleau_name tmp; + + if (Exists_File(name, ft)) { + Add_Extension(name, ft, tmp); + cout << "File '" << tmp << "' already exists and will be replaced. " + << "Procede anyway (y/n)? "; + cin >> y_n; + answer = ((y_n == 'y') || (y_n == 'Y')); + cout << "\n"; + } + return(answer); +} + +//====================================================================================// +// Get_Only_the_File_Name // +//====================================================================================// +void Get_Only_the_File_Name(const simuleau_name full_name, simuleau_name & just_the_file_name) +{ + int last_slash_position = -1; + int mark = 0; + + do { + if (full_name[mark] == '/') + last_slash_position = mark; + mark++; + } while (full_name[mark] != '\0'); + strcpy(just_the_file_name, &full_name[last_slash_position+1]); +} + + +//====================================================================================// +// Ask_a_Place // +//====================================================================================// +place_id Ask_a_Place() +{ + simuleau_name name; + place_id i, place; + + cout << "The places are: "; + for (i=0; i<bpn->NumberOfPlaces(); i++) { + cout << "\n " << i << ") " << bpn->GetPlaceName(i); + } + cout << "\n\nChoose a place (enter its index, -1 to show all): "; + cin >> place; + if (place == -1) + return place; + if ( (place < 0) || (place >= bpn->NumberOfPlaces()) ) { + place = fst_place; + cout << "Assuming first place\n"; + } + return place; +} + +//====================================================================================// +// Ask_a_Transition // +//====================================================================================// +trans_id Ask_a_Transition() +{ + simuleau_name name; + trans_id i, trans; + + cout << "The transitions are: "; + for (i=0; i<bpn->NumberOfTransitions(); i++) { + cout << "\n " << i << ") " << bpn->GetTransitionName(i); + } + cout << "\n\nChoose a transition (enter its index, -1 to show all): "; + cin >> trans; + if (trans == -1) + return trans; + if ( (trans < 0) || (trans >= bpn->NumberOfTransitions()) ) { + trans = fst_trans; + cout << "Assuming first transition\n"; + } + return trans; +} + + +//====================================================================================// +// See_BPN // +//====================================================================================// +void See_BPN() +{ + if (simulation != NULL ){ + if (!simulation->IsEmpty()) { + cout << "\n---------------------------------------------------------------" + << "\nInspecting the BPN model and scheduled events" + << "\n---------------------------------------------------------------\n\n"; + simulation->Print(std::cout); + } + } + else{ + cout << "There is no Batch Petri Net model (bpn) in memory.\n" + << "You must compile a bpn using the option 1 in main menu.\n"; + } +} + +//====================================================================================// +// See_place // +//====================================================================================// +void See_place() +{ + place_id placenumber; + BPN *b; + Place *p; + + if ((simulation != NULL)){ + placenumber = Ask_a_Place(); + b = simulation->GetBpn(); + if (placenumber == -1){ + cout << "\n---------------------------------------------------------------" + << "\nInspecting all places" + << "\n---------------------------------------------------------------\n\n"; + + for (int i=0; i<b->NumberOfPlaces(); i++) { + p = b->GetNode(b->GetPlaceName(i)); + p->Print(std::cout); + } + return; + } + cout << "\n---------------------------------------------------------------" + << "\nInspecting place " << b->GetPlaceName(placenumber) + << "\n---------------------------------------------------------------\n\n"; + + p = b->GetNode(b->GetPlaceName(placenumber)); + p->Print(std::cout); + } +} + +//====================================================================================// +// See_trans // +//====================================================================================// +void See_trans() +{ + trans_id transnumber; + BPN *b; + Transition *t; + + if ((simulation != NULL)){ + transnumber = Ask_a_Transition(); + b = simulation->GetBpn(); + if (transnumber == -1){ + cout << "\n---------------------------------------------------------------" + << "\nInspecting all transitions" + << "\n---------------------------------------------------------------\n\n"; + + for (int i=0; i<b->NumberOfTransitions(); i++) { + t = b->GetNode(b->GetTransitionName(i)); + t->Print(std::cout); + } + return; + } + cout << "\n---------------------------------------------------------------" + << "\nInspecting transition " << b->GetTransitionName(transnumber) + << "\n---------------------------------------------------------------\n\n"; + + t = b->GetNode(b->GetTransitionName(transnumber)); + t->Print(std::cout); + } +} + +//====================================================================================// +// See_events // +//====================================================================================// +void See_events() +{ + Schedule *s; + + if ((simulation != NULL)){ + cout << "\n---------------------------------------------------------------" + << "\nInspecting all scheduled events" + << "\n---------------------------------------------------------------\n\n"; + s = simulation->GetSchedule(); + s->Print(std::cout); + } +} + + +//====================================================================================// +// Ask an Answer // +//====================================================================================// +bool Ask_an_Answer(const simuleau_name name) +{ + bool answer = true; + char y_n; + + cout << name << " (y/n)? "; + cin >> y_n; + answer = ((y_n == 'y') || (y_n == 'Y') || (y_n == '0')); + cout << "\n"; + return(answer); +} +//====================================================================================// +// Ask an Error // +//====================================================================================// +double Ask_an_Error() +{ + double error; + + cout << "Enter tolerance: "; + cin >> error; + if (error < 0) { + error = def_err; + cout << "Assuming default value: " << def_err << "\n"; + } + return(error); +} +//====================================================================================// +// Ask an Inspect Time // +//====================================================================================// +double Ask_an_Inspect_Time() +{ + double time; + + cout << "Enter time to inspect: "; + cin >> time; + if (time < 0) { + time = zero; + cout << "Assuming default value: " << zero << "\n"; + } + return(time); +} + +//====================================================================================// +// Ask a Simulation Time // +//====================================================================================// +double Ask_a_Simulation_Time() +{ + double time; + + cout << "Enter maximum simulation time: "; + cin >> time; + if (time <= 0) { + time = def_time; + cout << "Assuming default value: " << def_time << "\n"; + } + return(time); +} + +//====================================================================================// +// Ask a Length Unity // +//====================================================================================// +char* Ask_a_Length_Unity() +{ + simuleau_name length; + + cout << "Enter the lenght unity: "; + cin >> length; + if (!strcmp(length,"0")) { + strcpy(length, def_length_unity); + cout << "Assuming default value: " << def_length_unity << "\n"; + } + return(length); +} + +//====================================================================================// +// Ask a Time Unity // +//====================================================================================// +char* Ask_a_Time_Unity() +{ + simuleau_name time; + + cout << "Enter the time unity: "; + cin >> time; + if (!strcmp(time,"0")) { + strcpy(time, def_time_unity); + cout << "Assuming default value: " << def_time_unity << "\n"; + } + return(time); +} + + +//====================================================================================// +// Notify_Time_Spend (stdout) - translations version // +//====================================================================================// +void Notify_Time_Spend(const Timer T, const simuleau_name op) +{ + ofstream out_file; + + cout << "\nTranslation performed: " << op << endl + << " - user time spent: " << T.usertime() << " seconds\n" + << " - system time spent: " << T.systime() << " seconds\n" + << " - real time spent: " << T.realtime() << " seconds\n"; +} + + +//====================================================================================// +// Show Credits // +//====================================================================================// +void Show_Credits() +{ + cout << "\n\n Simuleau - Simulator of Batch Petri Nets - version 2016 " + << "\n\n Simuleau is a software tool for simulate Batch Petri Nets (BPN)" + << "\n\n The current version (2016) is (still) an experimental version." + << "\n Mathematical basis for BPN may be obtained in the literature." +// << "\n\n Simuleau is a collective software effort and its authors may be" +// << "\n reached at:" +// << "\n simuleau@lsis.org or http://www.lsis.org/spip.php?id_rubrique=385" + << "\n\n The distribution of this software is free. Any comercial use of" + << "\n Simuleauu or modified versions of Simuleau cannot be performed without" + << "\n the formal autorization of the authors. Any scientific benefit of the" + << "\n use of the Simuleau tool must mention it." + << "\n\n This version of Simuleau was released on: " << __RELEASE_DATE__ + << "\n and it has been compiled on: " << __DATE__ +#ifdef _SIMULEAU_DEBUG_ + << " (debug version)\n\n"; +#else + << " (optimized version)\n\n"; +#endif +} +//====================================================================================// +// Say Goodbye // +//====================================================================================// +void Say_Goodbye() +{ + cout << "\n\nThanks for using Simuleau!\n\n"; +} +//====================================================================================// +// Say Sorry // +//====================================================================================// +void Say_Sorry() +{ + cout << "\nI'm sorry this option does not work right now!\n"; +} + +//====================================================================================// +// Welcome_Get_Simuleau_Option // +//====================================================================================// +simuleau_options Welcome_Get_Simuleau_Option() +{ + char option; + simuleau_options answer = nothing; + simuleau_name buf; + + do +{cout << "\n\n +--------------------------------------------------------+" + << "\n | This is Simuleau 2016 - the BPN tool |" + << "\n | released on: " << __RELEASE_DATE__ << " -- compiled on: " << __DATE__ << " |" +#ifdef _SIMULEAU_DEBUG_ + << "\n | *** debug version *** |" +#endif + << "\n +--------------------------------------------------------+" + << "\n\n 1) Compile a BPN model 4) Inspect data structures" + << "\n 2) Simulate a compiled BPN model 5) Dynamics facilities" + << "\n 3) Preferences 6) About this version" + << "\n\n 0) Exit Simuleau (Option 0 always exits the current menu)\n"; + + cin >> option; + switch (option) { + case '1': cout << "\n\n ******* Compiling a BPN Model *******" + << "\n\n 1) Standard Compilation\n"; + cin >> option; + switch (option) { + case '1': answer = compile; break; + } break; + case '2': cout << "\n\n ******* Simulating a BPN model *******" + << "\n\n 1) With controlled events 3) On/Off control method\n" + << " 2) Without conntrolled events 4) MF-On/Off control method\n"; +// << " 4) Computation of steady state 6) Computation of periodic steady state\n"; + + + + + cin >> option; + switch (option) { + case '1': answer = simulate_xct; break; + case '2': answer = simulate; break; + case '3': answer = simulate_onoff; break; + case '4': answer = simulate_mf_onoff; break; + case '5': answer = compute_steadystate; break; + case '6': answer = compute_periodicsteadystate; break; + } break; + case '3': cout << "\n\n ******* Changing Preferences *******" + << "\n\n 1) Verbose Mode: "; + cout << PRF::prf.Sverb(); + cout << "\n 2) Maximum simulation time: " + << PRF::prf.Max_Time(); + cout << "\n 3) Tolerance accepted: " + << PRF::prf.Min_Err(); + cout << "\n 4) Length unity: " + << PRF::prf.Length_Unity(); + cout << "\n 5) Time unity: " + << PRF::prf.Time_Unity(); + cout << "\n\nEnter a number to change the corresponding parameter: "; + cin >> option; + switch (option) { + case '1': PRF::prf.Verb(Ask_an_Answer("Do you want verbose mode")); break; + case '2': PRF::prf.Max_Time(Ask_a_Simulation_Time()); break; + case '3': PRF::prf.Min_Err(Ask_an_Error()); break; + case '4': PRF::prf.Length_Unity(Ask_a_Length_Unity()); break; + case '5': PRF::prf.Time_Unity(Ask_a_Time_Unity()); break; + } break; + case '4': cout << "\n\n ******* Inspect Data Structures *******" + << "\n\n 1) BPN in Memory " + << "\n 2) Place " + << "\n 3) Transition " + << "\n 4) Controlled events\n"; + cin >> option; + switch (option) { + case '1': answer = see_bpn; break; + case '2': answer = see_place; break; + case '3': answer = see_trans; break; + case '4': answer = see_events; } break; +/*case '5': cout << "\n\n ******* Probability Vector Facilities *******" + << "\n\n 1) local state probabilities 5) global state probabilities" + << "\n 2) integrate results 6) compute residue" + << "\n 3) compare two vectors 7) vector characteristics" + << "\n 4) inspect probability vector 8) inspect reachable state space\n" + << "\n 9) import a MARCA vector\n"; + cin >> option; + switch (option) { + case '1': answer = integrate_local; break; + case '2': answer = integrate_results; break; + case '3': answer = compare_vct; break; + case '4': answer = slice_vct; break; + case '5': answer = look_global_vct; break; + case '6': answer = residue_vct; break; + case '7': answer = charac_vct; break; + case '8': answer = analyse_reachable; break; + case '9': answer = import_marca_vct; } break;*/ + case '6': answer = credits; break; + /*case 'd': cout << "\n\n ******* Entering Simuleau 2016 debug mode *******" + << "\n *** i.e., you shouldn't be here ***" + << "\n\n 1) edit inner preferences 5) print rss" + << "\n 2) print dsc 6) print cnd" + << "\n 3) print dct 7) print cnd-diag" + << "\n 4) print ftb 8) print inf" + << "\n 9) Show Structures\n"; + cin >> option; + switch (option) { + case '1': Preferences(); break; + case '2': DSC::dsc.print(); break; + case '3': DCT::dct.print(); break; + case '4': FTB::ftb.print(); break; + case '5': RSS::rss.print(); break; + case '6': CND::cnd.print(); break; + case '7': CND::cnd.dprint(); break; + case '8': INF::inf.print(); break; + case '9': Show_Structures(); } break;*/ + case '0': answer = goodbye; + break; + default : answer = nothing; + break; + } +} + while (answer == nothing); + return(answer); +} + + + + + + + + diff --git a/src/interf/interf.h b/src/interf/interf.h new file mode 100644 index 0000000000000000000000000000000000000000..3c21ca0aa4db043093cd45fa4130e13ea428a08f --- /dev/null +++ b/src/interf/interf.h @@ -0,0 +1,152 @@ +//====================================================================================// +// // +// SIMULEAU User Interface // +// // +//====================================================================================// +// This File: interf.h Language: C++ (xlC and CC) // +// Software: SIMULEAU // +//====================================================================================// +// Creation: 12/apr/16 by: Leonardo.Brenner@lsis.org // +// Last Change: 12/apr/16 by: Leonardo.Brenner@lsis.org // +//====================================================================================// +#ifndef INTERF_H +#define INTERF_H + + +//------------------------------------------------------------------------------------// +// Operations Performed by Simuleau // +//------------------------------------------------------------------------------------// + +enum simuleau_options { // all operations that simuleau can do +//====================================================================================// +//------------------------------- Compiling Operations -------------------------------// +//====================================================================================// + compile , // compile (bpn -> str) + +//====================================================================================// +//--------------------------------- Simule Operations --------------------------------// +//====================================================================================// + simulate , // simulate + simulate_xct , // simulate with external controlled events + simulate_onoff, // simulate with on/off control method + compute_steadystate, //simulate with computation of steady state + simulate_mf_onoff, // simulate with maximal flow based on/off control method + compute_periodicsteadystate, //simulate with computation of periodic steady state + +//====================================================================================// +//--------------------------------- Inspect Operations -------------------------------// +//====================================================================================// + see_bpn , // inspect BPN internal representation + see_place , // inspect a specific place + see_trans , // inspect a specific transition + see_events , // inspect current events + see_dyn , // inspect dynamics + see_tim , // inspect dynamics in a specific instant + +//====================================================================================// +//---------------------------------- Other operations --------------------------------// +//====================================================================================// + credits , // show Simuleau credits + nothing , // do nothing + goodbye }; // exit Simuleau tool + + +//------------------------------------------------------------------------------------// +// Interface Functions used by Simuleau // +//------------------------------------------------------------------------------------// +void Open_File(const simuleau_name file, const file_types ft, ifstream & f_tmp); + +void Open_File(const simuleau_name file, const file_types ft, ofstream & f_tmp); + +void Append_File(const simuleau_name file, const file_types ft, ofstream & f_tmp); + +void Close_File(const simuleau_name file, const file_types ft, ifstream & f_tmp); + +void Close_File(const simuleau_name file, const file_types ft, ofstream & f_tmp); + +bool Exists_File(const simuleau_name file, const file_types ft); + +void Create_Temporary_Directories(); + +void Remove_Temporary_Directories(); + +void Remove_Dynamics_Files(); + +void Remove_Tim_Files(); + +void Ask_a_File_Name(simuleau_name & name, const file_types ft); + +void Ask_an_Existing_File_Name(simuleau_name & name, const file_types ft); + +bool Permission_to_Proceed(const simuleau_name name, const file_types ft); + +void Get_Only_the_File_Name(const simuleau_name full_name, simuleau_name & just_the_file_name); + +place_id Ask_a_Place(); + +trans_id Ask_a_Transition(); + +bool Provide_BPN(); + +bool Provide_XCT(); + +void See_BPN(); + +void See_place(); + +void See_trans(); + +void See_events(); + +void See_DYN(); + +void See_TIM(); + +bool Ask_an_Answer(const simuleau_name name); + +double Ask_an_Error(); + +double Ask_an_Inspect_Time(); + +double Ask_a_Simulation_Time(); + +void Show_User_Preferences(); + +void Change_User_Preferences(); + +void Notify_Time_Spend(const Timer T, const simuleau_name op); + +void Show_Credits(); + +void Say_Goodbye(); + +void Say_Sorry(); + +simuleau_options Welcome_Get_Simuleau_Option(); + +void Show_Structures(); + +void Preferences(); + + +//------------------------------------------------------------------------------------// +// Macro definition of error messages // +//------------------------------------------------------------------------------------// + +#define Programming_Error(text, number) \ + { cerr << "Programming Error - " << text << " (**** " << number << " ****)\n" \ + << "(file '" << __FILE__ << "' - line " << __LINE__ << ")\n" \ + << "****************************************************************\n"; \ + exit(1); } + +#define Programming_Warning(text, number) \ + { cerr << "Programming Warning - " << text << " (++++ " << number << " ++++)\n" \ + << "(file '" << __FILE__ << "' - line " << __LINE__ << ")\n"; } + +#define Compilation_Error(structure, text) \ + { cerr << structure << " Compilation Error - " << text << "\n" \ + << "****************************************************************\n"; \ + exit(1); } + + +#endif // INTERF_H diff --git a/src/interf/lex.yy.c b/src/interf/lex.yy.c new file mode 100644 index 0000000000000000000000000000000000000000..bee692c6a3fe5a826773f96c6aa867de2f0b6e7b --- /dev/null +++ b/src/interf/lex.yy.c @@ -0,0 +1,2152 @@ + +#line 3 "lex.yy.c" + +#define YY_INT_ALIGNED short int + +/* A lexical scanner generated by flex */ + +#define FLEX_SCANNER +#define YY_FLEX_MAJOR_VERSION 2 +#define YY_FLEX_MINOR_VERSION 6 +#define YY_FLEX_SUBMINOR_VERSION 0 +#if YY_FLEX_SUBMINOR_VERSION > 0 +#define FLEX_BETA +#endif + +/* First, we deal with platform-specific or compiler-specific issues. */ + +/* begin standard C headers. */ +#include <stdio.h> +#include <string.h> +#include <errno.h> +#include <stdlib.h> + +/* end standard C headers. */ + +/* flex integer type definitions */ + +#ifndef FLEXINT_H +#define FLEXINT_H + +/* C99 systems have <inttypes.h>. Non-C99 systems may or may not. */ + +#if defined (__STDC_VERSION__) && __STDC_VERSION__ >= 199901L + +/* C99 says to define __STDC_LIMIT_MACROS before including stdint.h, + * if you want the limit (max/min) macros for int types. + */ +#ifndef __STDC_LIMIT_MACROS +#define __STDC_LIMIT_MACROS 1 +#endif + +#include <inttypes.h> +typedef int8_t flex_int8_t; +typedef uint8_t flex_uint8_t; +typedef int16_t flex_int16_t; +typedef uint16_t flex_uint16_t; +typedef int32_t flex_int32_t; +typedef uint32_t flex_uint32_t; +#else +typedef signed char flex_int8_t; +typedef short int flex_int16_t; +typedef int flex_int32_t; +typedef unsigned char flex_uint8_t; +typedef unsigned short int flex_uint16_t; +typedef unsigned int flex_uint32_t; + +/* Limits of integral types. */ +#ifndef INT8_MIN +#define INT8_MIN (-128) +#endif +#ifndef INT16_MIN +#define INT16_MIN (-32767-1) +#endif +#ifndef INT32_MIN +#define INT32_MIN (-2147483647-1) +#endif +#ifndef INT8_MAX +#define INT8_MAX (127) +#endif +#ifndef INT16_MAX +#define INT16_MAX (32767) +#endif +#ifndef INT32_MAX +#define INT32_MAX (2147483647) +#endif +#ifndef UINT8_MAX +#define UINT8_MAX (255U) +#endif +#ifndef UINT16_MAX +#define UINT16_MAX (65535U) +#endif +#ifndef UINT32_MAX +#define UINT32_MAX (4294967295U) +#endif + +#endif /* ! C99 */ + +#endif /* ! FLEXINT_H */ + +#ifdef __cplusplus + +/* The "const" storage-class-modifier is valid. */ +#define YY_USE_CONST + +#else /* ! __cplusplus */ + +/* C99 requires __STDC__ to be defined as 1. */ +#if defined (__STDC__) + +#define YY_USE_CONST + +#endif /* defined (__STDC__) */ +#endif /* ! __cplusplus */ + +#ifdef YY_USE_CONST +#define yyconst const +#else +#define yyconst +#endif + +/* Returned upon end-of-file. */ +#define YY_NULL 0 + +/* Promotes a possibly negative, possibly signed char to an unsigned + * integer for use as an array index. If the signed char is negative, + * we want to instead treat it as an 8-bit unsigned char, hence the + * double cast. + */ +#define YY_SC_TO_UI(c) ((unsigned int) (unsigned char) c) + +/* Enter a start condition. This macro really ought to take a parameter, + * but we do it the disgusting crufty way forced on us by the ()-less + * definition of BEGIN. + */ +#define BEGIN (yy_start) = 1 + 2 * + +/* Translate the current start state into a value that can be later handed + * to BEGIN to return to the state. The YYSTATE alias is for lex + * compatibility. + */ +#define YY_START (((yy_start) - 1) / 2) +#define YYSTATE YY_START + +/* Action number for EOF rule of a given start state. */ +#define YY_STATE_EOF(state) (YY_END_OF_BUFFER + state + 1) + +/* Special action meaning "start processing a new file". */ +#define YY_NEW_FILE yyrestart(yyin ) + +#define YY_END_OF_BUFFER_CHAR 0 + +/* Size of default input buffer. */ +#ifndef YY_BUF_SIZE +#ifdef __ia64__ +/* On IA-64, the buffer size is 16k, not 8k. + * Moreover, YY_BUF_SIZE is 2*YY_READ_BUF_SIZE in the general case. + * Ditto for the __ia64__ case accordingly. + */ +#define YY_BUF_SIZE 32768 +#else +#define YY_BUF_SIZE 16384 +#endif /* __ia64__ */ +#endif + +/* The state buf must be large enough to hold one state per character in the main buffer. + */ +#define YY_STATE_BUF_SIZE ((YY_BUF_SIZE + 2) * sizeof(yy_state_type)) + +#ifndef YY_TYPEDEF_YY_BUFFER_STATE +#define YY_TYPEDEF_YY_BUFFER_STATE +typedef struct yy_buffer_state *YY_BUFFER_STATE; +#endif + +#ifndef YY_TYPEDEF_YY_SIZE_T +#define YY_TYPEDEF_YY_SIZE_T +typedef size_t yy_size_t; +#endif + +extern yy_size_t yyleng; + +extern FILE *yyin, *yyout; + +#define EOB_ACT_CONTINUE_SCAN 0 +#define EOB_ACT_END_OF_FILE 1 +#define EOB_ACT_LAST_MATCH 2 + + #define YY_LESS_LINENO(n) + #define YY_LINENO_REWIND_TO(ptr) + +/* Return all but the first "n" matched characters back to the input stream. */ +#define yyless(n) \ + do \ + { \ + /* Undo effects of setting up yytext. */ \ + int yyless_macro_arg = (n); \ + YY_LESS_LINENO(yyless_macro_arg);\ + *yy_cp = (yy_hold_char); \ + YY_RESTORE_YY_MORE_OFFSET \ + (yy_c_buf_p) = yy_cp = yy_bp + yyless_macro_arg - YY_MORE_ADJ; \ + YY_DO_BEFORE_ACTION; /* set up yytext again */ \ + } \ + while ( 0 ) + +#define unput(c) yyunput( c, (yytext_ptr) ) + +#ifndef YY_STRUCT_YY_BUFFER_STATE +#define YY_STRUCT_YY_BUFFER_STATE +struct yy_buffer_state + { + FILE *yy_input_file; + + char *yy_ch_buf; /* input buffer */ + char *yy_buf_pos; /* current position in input buffer */ + + /* Size of input buffer in bytes, not including room for EOB + * characters. + */ + yy_size_t yy_buf_size; + + /* Number of characters read into yy_ch_buf, not including EOB + * characters. + */ + int yy_n_chars; + + /* Whether we "own" the buffer - i.e., we know we created it, + * and can realloc() it to grow it, and should free() it to + * delete it. + */ + int yy_is_our_buffer; + + /* Whether this is an "interactive" input source; if so, and + * if we're using stdio for input, then we want to use getc() + * instead of fread(), to make sure we stop fetching input after + * each newline. + */ + int yy_is_interactive; + + /* Whether we're considered to be at the beginning of a line. + * If so, '^' rules will be active on the next match, otherwise + * not. + */ + int yy_at_bol; + + int yy_bs_lineno; /**< The line count. */ + int yy_bs_column; /**< The column count. */ + + /* Whether to try to fill the input buffer when we reach the + * end of it. + */ + int yy_fill_buffer; + + int yy_buffer_status; + +#define YY_BUFFER_NEW 0 +#define YY_BUFFER_NORMAL 1 + /* When an EOF's been seen but there's still some text to process + * then we mark the buffer as YY_EOF_PENDING, to indicate that we + * shouldn't try reading from the input source any more. We might + * still have a bunch of tokens to match, though, because of + * possible backing-up. + * + * When we actually see the EOF, we change the status to "new" + * (via yyrestart()), so that the user can continue scanning by + * just pointing yyin at a new input file. + */ +#define YY_BUFFER_EOF_PENDING 2 + + }; +#endif /* !YY_STRUCT_YY_BUFFER_STATE */ + +/* Stack of input buffers. */ +static size_t yy_buffer_stack_top = 0; /**< index of top of stack. */ +static size_t yy_buffer_stack_max = 0; /**< capacity of stack. */ +static YY_BUFFER_STATE * yy_buffer_stack = 0; /**< Stack as an array. */ + +/* We provide macros for accessing buffer states in case in the + * future we want to put the buffer states in a more general + * "scanner state". + * + * Returns the top of the stack, or NULL. + */ +#define YY_CURRENT_BUFFER ( (yy_buffer_stack) \ + ? (yy_buffer_stack)[(yy_buffer_stack_top)] \ + : NULL) + +/* Same as previous macro, but useful when we know that the buffer stack is not + * NULL or when we need an lvalue. For internal use only. + */ +#define YY_CURRENT_BUFFER_LVALUE (yy_buffer_stack)[(yy_buffer_stack_top)] + +/* yy_hold_char holds the character lost when yytext is formed. */ +static char yy_hold_char; +static int yy_n_chars; /* number of characters read into yy_ch_buf */ +yy_size_t yyleng; + +/* Points to current character in buffer. */ +static char *yy_c_buf_p = (char *) 0; +static int yy_init = 0; /* whether we need to initialize */ +static int yy_start = 0; /* start state number */ + +/* Flag which is used to allow yywrap()'s to do buffer switches + * instead of setting up a fresh yyin. A bit of a hack ... + */ +static int yy_did_buffer_switch_on_eof; + +void yyrestart (FILE *input_file ); +void yy_switch_to_buffer (YY_BUFFER_STATE new_buffer ); +YY_BUFFER_STATE yy_create_buffer (FILE *file,int size ); +void yy_delete_buffer (YY_BUFFER_STATE b ); +void yy_flush_buffer (YY_BUFFER_STATE b ); +void yypush_buffer_state (YY_BUFFER_STATE new_buffer ); +void yypop_buffer_state (void ); + +static void yyensure_buffer_stack (void ); +static void yy_load_buffer_state (void ); +static void yy_init_buffer (YY_BUFFER_STATE b,FILE *file ); + +#define YY_FLUSH_BUFFER yy_flush_buffer(YY_CURRENT_BUFFER ) + +YY_BUFFER_STATE yy_scan_buffer (char *base,yy_size_t size ); +YY_BUFFER_STATE yy_scan_string (yyconst char *yy_str ); +YY_BUFFER_STATE yy_scan_bytes (yyconst char *bytes,yy_size_t len ); + +void *yyalloc (yy_size_t ); +void *yyrealloc (void *,yy_size_t ); +void yyfree (void * ); + +#define yy_new_buffer yy_create_buffer + +#define yy_set_interactive(is_interactive) \ + { \ + if ( ! YY_CURRENT_BUFFER ){ \ + yyensure_buffer_stack (); \ + YY_CURRENT_BUFFER_LVALUE = \ + yy_create_buffer(yyin,YY_BUF_SIZE ); \ + } \ + YY_CURRENT_BUFFER_LVALUE->yy_is_interactive = is_interactive; \ + } + +#define yy_set_bol(at_bol) \ + { \ + if ( ! YY_CURRENT_BUFFER ){\ + yyensure_buffer_stack (); \ + YY_CURRENT_BUFFER_LVALUE = \ + yy_create_buffer(yyin,YY_BUF_SIZE ); \ + } \ + YY_CURRENT_BUFFER_LVALUE->yy_at_bol = at_bol; \ + } + +#define YY_AT_BOL() (YY_CURRENT_BUFFER_LVALUE->yy_at_bol) + +/* Begin user sect3 */ + +typedef unsigned char YY_CHAR; + +FILE *yyin = (FILE *) 0, *yyout = (FILE *) 0; + +typedef int yy_state_type; + +extern int yylineno; + +int yylineno = 1; + +extern char *yytext; +#ifdef yytext_ptr +#undef yytext_ptr +#endif +#define yytext_ptr yytext + +static yy_state_type yy_get_previous_state (void ); +static yy_state_type yy_try_NUL_trans (yy_state_type current_state ); +static int yy_get_next_buffer (void ); +#if defined(__GNUC__) && __GNUC__ >= 3 +__attribute__((__noreturn__)) +#endif +static void yy_fatal_error (yyconst char msg[] ); + +/* Done after the current pattern has been matched and before the + * corresponding action - sets up yytext. + */ +#define YY_DO_BEFORE_ACTION \ + (yytext_ptr) = yy_bp; \ + yyleng = (size_t) (yy_cp - yy_bp); \ + (yy_hold_char) = *yy_cp; \ + *yy_cp = '\0'; \ + (yy_c_buf_p) = yy_cp; + +#define YY_NUM_RULES 49 +#define YY_END_OF_BUFFER 50 +/* This struct is not used in this scanner, + but its presence is necessary. */ +struct yy_trans_info + { + flex_int32_t yy_verify; + flex_int32_t yy_nxt; + }; +static yyconst flex_int16_t yy_accept[185] = + { 0, + 46, 46, 50, 48, 46, 47, 33, 38, 39, 35, + 43, 48, 29, 45, 42, 44, 34, 32, 28, 40, + 41, 28, 28, 28, 28, 28, 28, 28, 28, 28, + 28, 28, 28, 28, 28, 28, 36, 37, 46, 1, + 0, 29, 0, 28, 28, 28, 28, 28, 28, 28, + 28, 28, 28, 28, 28, 28, 28, 28, 28, 28, + 28, 28, 28, 28, 1, 30, 0, 31, 2, 28, + 28, 28, 28, 28, 28, 28, 28, 28, 28, 28, + 28, 28, 28, 28, 28, 28, 28, 28, 28, 28, + 28, 28, 28, 28, 28, 9, 28, 28, 28, 28, + + 28, 28, 28, 28, 28, 28, 28, 22, 28, 28, + 28, 28, 3, 28, 28, 28, 28, 28, 28, 28, + 28, 28, 28, 15, 28, 28, 18, 20, 28, 28, + 28, 28, 27, 28, 28, 28, 28, 8, 28, 28, + 28, 13, 28, 28, 17, 19, 21, 23, 28, 28, + 28, 28, 28, 28, 28, 11, 28, 14, 16, 28, + 28, 28, 28, 28, 7, 10, 28, 28, 28, 28, + 28, 28, 28, 28, 28, 4, 5, 28, 12, 24, + 26, 6, 25, 0 + } ; + +static yyconst YY_CHAR yy_ec[256] = + { 0, + 1, 1, 1, 1, 1, 1, 1, 1, 2, 3, + 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, + 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, + 1, 4, 5, 5, 6, 5, 5, 5, 5, 7, + 8, 9, 10, 11, 10, 12, 13, 14, 14, 14, + 14, 14, 14, 14, 14, 14, 14, 15, 16, 5, + 17, 5, 18, 19, 20, 20, 20, 20, 21, 20, + 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, + 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, + 22, 5, 23, 5, 20, 1, 24, 25, 26, 27, + + 28, 29, 30, 31, 32, 20, 33, 34, 35, 36, + 37, 38, 20, 39, 40, 41, 42, 43, 44, 20, + 45, 20, 46, 5, 47, 5, 1, 1, 1, 1, + 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, + 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, + 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, + 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, + 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, + 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, + 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, + + 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, + 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, + 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, + 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, + 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, + 1, 1, 1, 1, 1 + } ; + +static yyconst YY_CHAR yy_meta[48] = + { 0, + 1, 1, 1, 2, 2, 2, 2, 2, 2, 2, + 2, 2, 2, 3, 2, 2, 2, 2, 2, 3, + 3, 2, 2, 3, 3, 3, 3, 3, 3, 3, + 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, + 3, 3, 3, 3, 3, 2, 2 + } ; + +static yyconst flex_uint16_t yy_base[187] = + { 0, + 0, 0, 207, 208, 46, 208, 208, 208, 208, 208, + 208, 193, 37, 208, 208, 208, 208, 208, 0, 208, + 208, 166, 180, 166, 24, 159, 19, 165, 172, 30, + 171, 156, 163, 19, 23, 160, 208, 208, 62, 0, + 181, 56, 49, 0, 168, 152, 156, 151, 150, 161, + 151, 151, 39, 150, 146, 157, 142, 141, 157, 152, + 151, 143, 48, 145, 0, 55, 162, 161, 0, 148, + 132, 146, 145, 134, 125, 142, 126, 128, 135, 131, + 135, 118, 123, 134, 131, 134, 46, 121, 132, 114, + 123, 43, 114, 113, 110, 0, 109, 117, 120, 106, + + 114, 111, 107, 101, 114, 114, 113, 0, 103, 98, + 101, 91, 0, 99, 97, 101, 104, 91, 98, 105, + 102, 96, 90, 0, 86, 83, 83, 0, 77, 91, + 88, 89, 0, 76, 83, 78, 74, 0, 77, 79, + 71, 0, 81, 77, 0, 0, 0, 0, 68, 66, + 70, 72, 64, 76, 67, 0, 70, 0, 0, 69, + 66, 57, 70, 65, 0, 0, 59, 58, 70, 53, + 65, 54, 54, 53, 49, 0, 0, 51, 0, 41, + 0, 0, 0, 208, 70, 83 + } ; + +static yyconst flex_int16_t yy_def[187] = + { 0, + 184, 1, 184, 184, 184, 184, 184, 184, 184, 184, + 184, 184, 184, 184, 184, 184, 184, 184, 185, 184, + 184, 185, 185, 185, 185, 185, 185, 185, 185, 185, + 185, 185, 185, 185, 185, 185, 184, 184, 184, 186, + 184, 184, 184, 185, 185, 185, 185, 185, 185, 185, + 185, 185, 185, 185, 185, 185, 185, 185, 185, 185, + 185, 185, 185, 185, 186, 184, 184, 184, 185, 185, + 185, 185, 185, 185, 185, 185, 185, 185, 185, 185, + 185, 185, 185, 185, 185, 185, 185, 185, 185, 185, + 185, 185, 185, 185, 185, 185, 185, 185, 185, 185, + + 185, 185, 185, 185, 185, 185, 185, 185, 185, 185, + 185, 185, 185, 185, 185, 185, 185, 185, 185, 185, + 185, 185, 185, 185, 185, 185, 185, 185, 185, 185, + 185, 185, 185, 185, 185, 185, 185, 185, 185, 185, + 185, 185, 185, 185, 185, 185, 185, 185, 185, 185, + 185, 185, 185, 185, 185, 185, 185, 185, 185, 185, + 185, 185, 185, 185, 185, 185, 185, 185, 185, 185, + 185, 185, 185, 185, 185, 185, 185, 185, 185, 185, + 185, 185, 185, 0, 184, 184 + } ; + +static yyconst flex_uint16_t yy_nxt[256] = + { 0, + 4, 5, 6, 5, 4, 7, 8, 9, 10, 4, + 11, 4, 12, 13, 14, 15, 16, 17, 18, 19, + 19, 20, 21, 22, 23, 24, 25, 26, 27, 19, + 19, 28, 19, 29, 30, 31, 32, 33, 19, 34, + 35, 36, 19, 19, 19, 37, 38, 39, 41, 39, + 42, 48, 51, 55, 62, 49, 60, 43, 67, 61, + 52, 63, 68, 39, 43, 39, 56, 41, 66, 42, + 77, 88, 44, 108, 114, 43, 43, 109, 78, 89, + 183, 115, 43, 43, 65, 65, 182, 181, 180, 179, + 178, 177, 176, 175, 174, 173, 172, 171, 170, 169, + + 168, 167, 166, 165, 164, 163, 162, 161, 160, 159, + 158, 157, 156, 155, 154, 153, 152, 151, 150, 149, + 148, 147, 146, 145, 144, 143, 142, 141, 140, 139, + 138, 137, 136, 135, 134, 133, 132, 131, 130, 129, + 128, 127, 126, 125, 124, 123, 122, 121, 120, 119, + 118, 117, 116, 113, 112, 111, 110, 107, 106, 105, + 104, 103, 102, 101, 100, 99, 98, 97, 96, 95, + 94, 93, 92, 91, 68, 68, 90, 87, 86, 85, + 84, 83, 82, 81, 80, 79, 76, 75, 74, 73, + 72, 71, 70, 69, 66, 64, 59, 58, 57, 54, + + 53, 50, 47, 46, 45, 40, 184, 3, 184, 184, + 184, 184, 184, 184, 184, 184, 184, 184, 184, 184, + 184, 184, 184, 184, 184, 184, 184, 184, 184, 184, + 184, 184, 184, 184, 184, 184, 184, 184, 184, 184, + 184, 184, 184, 184, 184, 184, 184, 184, 184, 184, + 184, 184, 184, 184, 184 + } ; + +static yyconst flex_int16_t yy_chk[256] = + { 0, + 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, + 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, + 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, + 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, + 1, 1, 1, 1, 1, 1, 1, 5, 13, 5, + 13, 25, 27, 30, 35, 25, 34, 13, 43, 34, + 27, 35, 43, 39, 13, 39, 30, 42, 66, 42, + 53, 63, 185, 87, 92, 66, 42, 87, 53, 63, + 180, 92, 66, 42, 186, 186, 178, 175, 174, 173, + 172, 171, 170, 169, 168, 167, 164, 163, 162, 161, + + 160, 157, 155, 154, 153, 152, 151, 150, 149, 144, + 143, 141, 140, 139, 137, 136, 135, 134, 132, 131, + 130, 129, 127, 126, 125, 123, 122, 121, 120, 119, + 118, 117, 116, 115, 114, 112, 111, 110, 109, 107, + 106, 105, 104, 103, 102, 101, 100, 99, 98, 97, + 95, 94, 93, 91, 90, 89, 88, 86, 85, 84, + 83, 82, 81, 80, 79, 78, 77, 76, 75, 74, + 73, 72, 71, 70, 68, 67, 64, 62, 61, 60, + 59, 58, 57, 56, 55, 54, 52, 51, 50, 49, + 48, 47, 46, 45, 41, 36, 33, 32, 31, 29, + + 28, 26, 24, 23, 22, 12, 3, 184, 184, 184, + 184, 184, 184, 184, 184, 184, 184, 184, 184, 184, + 184, 184, 184, 184, 184, 184, 184, 184, 184, 184, + 184, 184, 184, 184, 184, 184, 184, 184, 184, 184, + 184, 184, 184, 184, 184, 184, 184, 184, 184, 184, + 184, 184, 184, 184, 184 + } ; + +static yy_state_type yy_last_accepting_state; +static char *yy_last_accepting_cpos; + +extern int yy_flex_debug; +int yy_flex_debug = 0; + +/* The intent behind this definition is that it'll catch + * any uses of REJECT which flex missed. + */ +#define REJECT reject_used_but_not_detected +#define yymore() yymore_used_but_not_detected +#define YY_MORE_ADJ 0 +#define YY_RESTORE_YY_MORE_OFFSET +char *yytext; +#line 1 "tokens.l" +#line 2 "tokens.l" +//====================================================================================// +// // +// Lexical Analyzer // +// // +//====================================================================================// +// This File: tokens.l Tool: lex // +// Software: SIMULEAU // +// Doc: // +//====================================================================================// +// Creation: 15/Apr/16 by: Leonardo.Brenner@lsis.org // +// Last Change: 15/Apr/16 by: Leonardo.Brenner@lsis.org // +//====================================================================================// +// This file has the definitions of the tokens that must to be recognized by the // +// grammar contained in the "glc.y" file. These definitions are used by LEX tool, // +// which is a generator of lexical parsers. // +// The lexical analyzer (scanner) is a function that reads an input stream and // +// returns the correspondents tokens. // +//====================================================================================// +#include "bpnfile.h" + +extern int yynerrs; // Variable of the YACC generator to count the number of errors. +extern int yylineno; + +//====================================================================================// +// Below are defined the R.E.(Regular Expressions) that defines the format of the // +// digits (symbols between 0 and 9, inclusively), integers, reals, exponents and // +// identifies. The symbol "+" indicate one or more occurrences, the symbol "*" // +// indicate zero or more occurrences and the symbol "?" indicate that the occurrence // +// is optional. // +//====================================================================================// + +#line 612 "lex.yy.c" + +#define INITIAL 0 + +#ifndef YY_NO_UNISTD_H +/* Special case for "unistd.h", since it is non-ANSI. We include it way + * down here because we want the user's section 1 to have been scanned first. + * The user has a chance to override it with an option. + */ +#include <unistd.h> +#endif + +#ifndef YY_EXTRA_TYPE +#define YY_EXTRA_TYPE void * +#endif + +static int yy_init_globals (void ); + +/* Accessor methods to globals. + These are made visible to non-reentrant scanners for convenience. */ + +int yylex_destroy (void ); + +int yyget_debug (void ); + +void yyset_debug (int debug_flag ); + +YY_EXTRA_TYPE yyget_extra (void ); + +void yyset_extra (YY_EXTRA_TYPE user_defined ); + +FILE *yyget_in (void ); + +void yyset_in (FILE * _in_str ); + +FILE *yyget_out (void ); + +void yyset_out (FILE * _out_str ); + +yy_size_t yyget_leng (void ); + +char *yyget_text (void ); + +int yyget_lineno (void ); + +void yyset_lineno (int _line_number ); + +/* Macros after this point can all be overridden by user definitions in + * section 1. + */ + +#ifndef YY_SKIP_YYWRAP +#ifdef __cplusplus +extern "C" int yywrap (void ); +#else +extern int yywrap (void ); +#endif +#endif + +#ifndef YY_NO_UNPUT + + static void yyunput (int c,char *buf_ptr ); + +#endif + +#ifndef yytext_ptr +static void yy_flex_strncpy (char *,yyconst char *,int ); +#endif + +#ifdef YY_NEED_STRLEN +static int yy_flex_strlen (yyconst char * ); +#endif + +#ifndef YY_NO_INPUT + +#ifdef __cplusplus +static int yyinput (void ); +#else +static int input (void ); +#endif + +#endif + +/* Amount of stuff to slurp up with each read. */ +#ifndef YY_READ_BUF_SIZE +#ifdef __ia64__ +/* On IA-64, the buffer size is 16k, not 8k */ +#define YY_READ_BUF_SIZE 16384 +#else +#define YY_READ_BUF_SIZE 8192 +#endif /* __ia64__ */ +#endif + +/* Copy whatever the last rule matched to the standard output. */ +#ifndef ECHO +/* This used to be an fputs(), but since the string might contain NUL's, + * we now use fwrite(). + */ +#define ECHO do { if (fwrite( yytext, yyleng, 1, yyout )) {} } while (0) +#endif + +/* Gets input and stuffs it into "buf". number of characters read, or YY_NULL, + * is returned in "result". + */ +#ifndef YY_INPUT +#define YY_INPUT(buf,result,max_size) \ + if ( YY_CURRENT_BUFFER_LVALUE->yy_is_interactive ) \ + { \ + int c = '*'; \ + size_t n; \ + for ( n = 0; n < max_size && \ + (c = getc( yyin )) != EOF && c != '\n'; ++n ) \ + buf[n] = (char) c; \ + if ( c == '\n' ) \ + buf[n++] = (char) c; \ + if ( c == EOF && ferror( yyin ) ) \ + YY_FATAL_ERROR( "input in flex scanner failed" ); \ + result = n; \ + } \ + else \ + { \ + errno=0; \ + while ( (result = fread(buf, 1, max_size, yyin))==0 && ferror(yyin)) \ + { \ + if( errno != EINTR) \ + { \ + YY_FATAL_ERROR( "input in flex scanner failed" ); \ + break; \ + } \ + errno=0; \ + clearerr(yyin); \ + } \ + }\ +\ + +#endif + +/* No semi-colon after return; correct usage is to write "yyterminate();" - + * we don't want an extra ';' after the "return" because that will cause + * some compilers to complain about unreachable statements. + */ +#ifndef yyterminate +#define yyterminate() return YY_NULL +#endif + +/* Number of entries by which start-condition stack grows. */ +#ifndef YY_START_STACK_INCR +#define YY_START_STACK_INCR 25 +#endif + +/* Report a fatal error. */ +#ifndef YY_FATAL_ERROR +#define YY_FATAL_ERROR(msg) yy_fatal_error( msg ) +#endif + +/* end tables serialization structures and prototypes */ + +/* Default declaration of generated scanner - a define so the user can + * easily add parameters. + */ +#ifndef YY_DECL +#define YY_DECL_IS_OURS 1 + +extern int yylex (void); + +#define YY_DECL int yylex (void) +#endif /* !YY_DECL */ + +/* Code executed at the beginning of each rule, after yytext and yyleng + * have been set up. + */ +#ifndef YY_USER_ACTION +#define YY_USER_ACTION +#endif + +/* Code executed at the end of each rule. */ +#ifndef YY_BREAK +#define YY_BREAK /*LINTED*/break; +#endif + +#define YY_RULE_SETUP \ + YY_USER_ACTION + +/** The main scanner function which does all the work. + */ +YY_DECL +{ + yy_state_type yy_current_state; + char *yy_cp, *yy_bp; + int yy_act; + + if ( !(yy_init) ) + { + (yy_init) = 1; + +#ifdef YY_USER_INIT + YY_USER_INIT; +#endif + + if ( ! (yy_start) ) + (yy_start) = 1; /* first start state */ + + if ( ! yyin ) + yyin = stdin; + + if ( ! yyout ) + yyout = stdout; + + if ( ! YY_CURRENT_BUFFER ) { + yyensure_buffer_stack (); + YY_CURRENT_BUFFER_LVALUE = + yy_create_buffer(yyin,YY_BUF_SIZE ); + } + + yy_load_buffer_state( ); + } + + { +#line 41 "tokens.l" + + +#line 833 "lex.yy.c" + + while ( /*CONSTCOND*/1 ) /* loops until end-of-file is reached */ + { + yy_cp = (yy_c_buf_p); + + /* Support of yytext. */ + *yy_cp = (yy_hold_char); + + /* yy_bp points to the position in yy_ch_buf of the start of + * the current run. + */ + yy_bp = yy_cp; + + yy_current_state = (yy_start); +yy_match: + do + { + YY_CHAR yy_c = yy_ec[YY_SC_TO_UI(*yy_cp)] ; + if ( yy_accept[yy_current_state] ) + { + (yy_last_accepting_state) = yy_current_state; + (yy_last_accepting_cpos) = yy_cp; + } + while ( yy_chk[yy_base[yy_current_state] + yy_c] != yy_current_state ) + { + yy_current_state = (int) yy_def[yy_current_state]; + if ( yy_current_state >= 185 ) + yy_c = yy_meta[(unsigned int) yy_c]; + } + yy_current_state = yy_nxt[yy_base[yy_current_state] + (unsigned int) yy_c]; + ++yy_cp; + } + while ( yy_base[yy_current_state] != 208 ); + +yy_find_action: + yy_act = yy_accept[yy_current_state]; + if ( yy_act == 0 ) + { /* have to back up */ + yy_cp = (yy_last_accepting_cpos); + yy_current_state = (yy_last_accepting_state); + yy_act = yy_accept[yy_current_state]; + } + + YY_DO_BEFORE_ACTION; + +do_action: /* This label is used only to access EOF actions. */ + + switch ( yy_act ) + { /* beginning of action switch */ + case 0: /* must back up */ + /* undo the effects of YY_DO_BEFORE_ACTION */ + *yy_cp = (yy_hold_char); + yy_cp = (yy_last_accepting_cpos); + yy_current_state = (yy_last_accepting_state); + goto yy_find_action; + +case 1: +YY_RULE_SETUP +#line 43 "tokens.l" + + YY_BREAK +case 2: +YY_RULE_SETUP +#line 44 "tokens.l" +{return(TK_ARC);} + YY_BREAK +case 3: +YY_RULE_SETUP +#line 45 "tokens.l" +{return(TK_BATCH);} + YY_BREAK +case 4: +YY_RULE_SETUP +#line 46 "tokens.l" +{return(TK_CONTINUOUS);} + YY_BREAK +case 5: +YY_RULE_SETUP +#line 47 "tokens.l" +{return(TK_CONTROLLED);} + YY_BREAK +case 6: +YY_RULE_SETUP +#line 48 "tokens.l" +{return(TK_DESCRIPTION);} + YY_BREAK +case 7: +YY_RULE_SETUP +#line 49 "tokens.l" +{return(TK_DISCRETE);} + YY_BREAK +case 8: +YY_RULE_SETUP +#line 50 "tokens.l" +{return(TK_EVENTS);} + YY_BREAK +case 9: +YY_RULE_SETUP +#line 51 "tokens.l" +{return(TK_FLOW);} + YY_BREAK +case 10: +YY_RULE_SETUP +#line 52 "tokens.l" +{return(TK_FUNCTION);} + YY_BREAK +case 11: +YY_RULE_SETUP +#line 53 "tokens.l" +{return(TK_INITIAL);} + YY_BREAK +case 12: +YY_RULE_SETUP +#line 54 "tokens.l" +{return(TK_INSPECTION);} + YY_BREAK +case 13: +YY_RULE_SETUP +#line 55 "tokens.l" +{return(TK_LENGTH);} + YY_BREAK +case 14: +YY_RULE_SETUP +#line 56 "tokens.l" +{return(TK_MARKING);} + YY_BREAK +case 15: +YY_RULE_SETUP +#line 57 "tokens.l" +{return(TK_MODEL);} + YY_BREAK +case 16: +YY_RULE_SETUP +#line 58 "tokens.l" +{return(TK_NETWORK);} + YY_BREAK +case 17: +YY_RULE_SETUP +#line 59 "tokens.l" +{return(TK_OUTPUT);} + YY_BREAK +case 18: +YY_RULE_SETUP +#line 60 "tokens.l" +{return(TK_PLACE);} + YY_BREAK +case 19: +YY_RULE_SETUP +#line 61 "tokens.l" +{return(TK_PLACES);} + YY_BREAK +case 20: +YY_RULE_SETUP +#line 62 "tokens.l" +{return(TK_SPEED);} + YY_BREAK +case 21: +YY_RULE_SETUP +#line 63 "tokens.l" +{return(TK_STEADY);} + YY_BREAK +case 22: +YY_RULE_SETUP +#line 64 "tokens.l" +{return(TK_TIME);} + YY_BREAK +case 23: +YY_RULE_SETUP +#line 65 "tokens.l" +{return(TK_TIMING);} + YY_BREAK +case 24: +YY_RULE_SETUP +#line 66 "tokens.l" +{return(TK_TRANSITION);} + YY_BREAK +case 25: +YY_RULE_SETUP +#line 67 "tokens.l" +{return(TK_TRANSITIONS);} + YY_BREAK +case 26: +YY_RULE_SETUP +#line 68 "tokens.l" +{return(TK_TRIANGULAR);} + YY_BREAK +case 27: +YY_RULE_SETUP +#line 69 "tokens.l" +{return(TK_UNITY);} + YY_BREAK +case 28: +YY_RULE_SETUP +#line 70 "tokens.l" +{return(TK_ID);} + YY_BREAK +case 29: +YY_RULE_SETUP +#line 71 "tokens.l" +{return(TK_INTEGER);} + YY_BREAK +case 30: +YY_RULE_SETUP +#line 72 "tokens.l" +{return(TK_REAL);} + YY_BREAK +case 31: +YY_RULE_SETUP +#line 73 "tokens.l" +{return(TK_EXPONENT);} + YY_BREAK +case 32: +YY_RULE_SETUP +#line 74 "tokens.l" +{return(TK_AT);} + YY_BREAK +case 33: +YY_RULE_SETUP +#line 75 "tokens.l" +{return(TK_EVERY);} + YY_BREAK +case 34: +YY_RULE_SETUP +#line 76 "tokens.l" +{return(TK_PL_TR);} + YY_BREAK +case 35: +YY_RULE_SETUP +#line 77 "tokens.l" +{return(TK_ALL);} + YY_BREAK +case 36: +YY_RULE_SETUP +#line 78 "tokens.l" +{return(TK_LEFT_BRACKET);} + YY_BREAK +case 37: +YY_RULE_SETUP +#line 79 "tokens.l" +{return(TK_RIGHT_BRACKET);} + YY_BREAK +case 38: +YY_RULE_SETUP +#line 80 "tokens.l" +{return(TK_LEFT_PARENTHESIS);} + YY_BREAK +case 39: +YY_RULE_SETUP +#line 81 "tokens.l" +{return(TK_RIGHT_PARENTHESIS);} + YY_BREAK +case 40: +YY_RULE_SETUP +#line 82 "tokens.l" +{return(TK_LEFT_SQUARE_BRACKET);} + YY_BREAK +case 41: +YY_RULE_SETUP +#line 83 "tokens.l" +{return(TK_RIGHT_SQUARE_BRACKET);} + YY_BREAK +case 42: +YY_RULE_SETUP +#line 84 "tokens.l" +{return(TK_SEMICOLON);} + YY_BREAK +case 43: +YY_RULE_SETUP +#line 85 "tokens.l" +{return(TK_COMMA);} + YY_BREAK +case 44: +YY_RULE_SETUP +#line 86 "tokens.l" +{return(TK_ATTRIB);} + YY_BREAK +case 45: +YY_RULE_SETUP +#line 87 "tokens.l" +{return(TK_COLON);} + YY_BREAK +case 46: +YY_RULE_SETUP +#line 88 "tokens.l" +{/* Ignore the blanks, tabulates and new line */} + YY_BREAK +case 47: +/* rule 47 can match eol */ +YY_RULE_SETUP +#line 89 "tokens.l" +{yylineno++;} + YY_BREAK +case 48: +YY_RULE_SETUP +#line 90 "tokens.l" +{ /* If neither token return, means that the input + stream has a lexical error */ + yynerrs++; + Lexical_Error(yynerrs, yylineno, yytext);} + YY_BREAK +case 49: +YY_RULE_SETUP +#line 94 "tokens.l" +ECHO; + YY_BREAK +#line 1139 "lex.yy.c" +case YY_STATE_EOF(INITIAL): + yyterminate(); + + case YY_END_OF_BUFFER: + { + /* Amount of text matched not including the EOB char. */ + int yy_amount_of_matched_text = (int) (yy_cp - (yytext_ptr)) - 1; + + /* Undo the effects of YY_DO_BEFORE_ACTION. */ + *yy_cp = (yy_hold_char); + YY_RESTORE_YY_MORE_OFFSET + + if ( YY_CURRENT_BUFFER_LVALUE->yy_buffer_status == YY_BUFFER_NEW ) + { + /* We're scanning a new file or input source. It's + * possible that this happened because the user + * just pointed yyin at a new source and called + * yylex(). If so, then we have to assure + * consistency between YY_CURRENT_BUFFER and our + * globals. Here is the right place to do so, because + * this is the first action (other than possibly a + * back-up) that will match for the new input source. + */ + (yy_n_chars) = YY_CURRENT_BUFFER_LVALUE->yy_n_chars; + YY_CURRENT_BUFFER_LVALUE->yy_input_file = yyin; + YY_CURRENT_BUFFER_LVALUE->yy_buffer_status = YY_BUFFER_NORMAL; + } + + /* Note that here we test for yy_c_buf_p "<=" to the position + * of the first EOB in the buffer, since yy_c_buf_p will + * already have been incremented past the NUL character + * (since all states make transitions on EOB to the + * end-of-buffer state). Contrast this with the test + * in input(). + */ + if ( (yy_c_buf_p) <= &YY_CURRENT_BUFFER_LVALUE->yy_ch_buf[(yy_n_chars)] ) + { /* This was really a NUL. */ + yy_state_type yy_next_state; + + (yy_c_buf_p) = (yytext_ptr) + yy_amount_of_matched_text; + + yy_current_state = yy_get_previous_state( ); + + /* Okay, we're now positioned to make the NUL + * transition. We couldn't have + * yy_get_previous_state() go ahead and do it + * for us because it doesn't know how to deal + * with the possibility of jamming (and we don't + * want to build jamming into it because then it + * will run more slowly). + */ + + yy_next_state = yy_try_NUL_trans( yy_current_state ); + + yy_bp = (yytext_ptr) + YY_MORE_ADJ; + + if ( yy_next_state ) + { + /* Consume the NUL. */ + yy_cp = ++(yy_c_buf_p); + yy_current_state = yy_next_state; + goto yy_match; + } + + else + { + yy_cp = (yy_c_buf_p); + goto yy_find_action; + } + } + + else switch ( yy_get_next_buffer( ) ) + { + case EOB_ACT_END_OF_FILE: + { + (yy_did_buffer_switch_on_eof) = 0; + + if ( yywrap( ) ) + { + /* Note: because we've taken care in + * yy_get_next_buffer() to have set up + * yytext, we can now set up + * yy_c_buf_p so that if some total + * hoser (like flex itself) wants to + * call the scanner after we return the + * YY_NULL, it'll still work - another + * YY_NULL will get returned. + */ + (yy_c_buf_p) = (yytext_ptr) + YY_MORE_ADJ; + + yy_act = YY_STATE_EOF(YY_START); + goto do_action; + } + + else + { + if ( ! (yy_did_buffer_switch_on_eof) ) + YY_NEW_FILE; + } + break; + } + + case EOB_ACT_CONTINUE_SCAN: + (yy_c_buf_p) = + (yytext_ptr) + yy_amount_of_matched_text; + + yy_current_state = yy_get_previous_state( ); + + yy_cp = (yy_c_buf_p); + yy_bp = (yytext_ptr) + YY_MORE_ADJ; + goto yy_match; + + case EOB_ACT_LAST_MATCH: + (yy_c_buf_p) = + &YY_CURRENT_BUFFER_LVALUE->yy_ch_buf[(yy_n_chars)]; + + yy_current_state = yy_get_previous_state( ); + + yy_cp = (yy_c_buf_p); + yy_bp = (yytext_ptr) + YY_MORE_ADJ; + goto yy_find_action; + } + break; + } + + default: + YY_FATAL_ERROR( + "fatal flex scanner internal error--no action found" ); + } /* end of action switch */ + } /* end of scanning one token */ + } /* end of user's declarations */ +} /* end of yylex */ + +/* yy_get_next_buffer - try to read in a new buffer + * + * Returns a code representing an action: + * EOB_ACT_LAST_MATCH - + * EOB_ACT_CONTINUE_SCAN - continue scanning from current position + * EOB_ACT_END_OF_FILE - end of file + */ +static int yy_get_next_buffer (void) +{ + char *dest = YY_CURRENT_BUFFER_LVALUE->yy_ch_buf; + char *source = (yytext_ptr); + yy_size_t number_to_move, i; + int ret_val; + + if ( (yy_c_buf_p) > &YY_CURRENT_BUFFER_LVALUE->yy_ch_buf[(yy_n_chars) + 1] ) + YY_FATAL_ERROR( + "fatal flex scanner internal error--end of buffer missed" ); + + if ( YY_CURRENT_BUFFER_LVALUE->yy_fill_buffer == 0 ) + { /* Don't try to fill the buffer, so this is an EOF. */ + if ( (yy_c_buf_p) - (yytext_ptr) - YY_MORE_ADJ == 1 ) + { + /* We matched a single character, the EOB, so + * treat this as a final EOF. + */ + return EOB_ACT_END_OF_FILE; + } + + else + { + /* We matched some text prior to the EOB, first + * process it. + */ + return EOB_ACT_LAST_MATCH; + } + } + + /* Try to read more data. */ + + /* First move last chars to start of buffer. */ + number_to_move = (yy_size_t) ((yy_c_buf_p) - (yytext_ptr)) - 1; + + for ( i = 0; i < number_to_move; ++i ) + *(dest++) = *(source++); + + if ( YY_CURRENT_BUFFER_LVALUE->yy_buffer_status == YY_BUFFER_EOF_PENDING ) + /* don't do the read, it's not guaranteed to return an EOF, + * just force an EOF + */ + YY_CURRENT_BUFFER_LVALUE->yy_n_chars = (yy_n_chars) = 0; + + else + { + yy_size_t num_to_read = + YY_CURRENT_BUFFER_LVALUE->yy_buf_size - number_to_move - 1; + + while ( num_to_read <= 0 ) + { /* Not enough room in the buffer - grow it. */ + + /* just a shorter name for the current buffer */ + YY_BUFFER_STATE b = YY_CURRENT_BUFFER_LVALUE; + + int yy_c_buf_p_offset = + (int) ((yy_c_buf_p) - b->yy_ch_buf); + + if ( b->yy_is_our_buffer ) + { + yy_size_t new_size = b->yy_buf_size * 2; + + if ( new_size <= 0 ) + b->yy_buf_size += b->yy_buf_size / 8; + else + b->yy_buf_size *= 2; + + b->yy_ch_buf = (char *) + /* Include room in for 2 EOB chars. */ + yyrealloc((void *) b->yy_ch_buf,b->yy_buf_size + 2 ); + } + else + /* Can't grow it, we don't own it. */ + b->yy_ch_buf = 0; + + if ( ! b->yy_ch_buf ) + YY_FATAL_ERROR( + "fatal error - scanner input buffer overflow" ); + + (yy_c_buf_p) = &b->yy_ch_buf[yy_c_buf_p_offset]; + + num_to_read = YY_CURRENT_BUFFER_LVALUE->yy_buf_size - + number_to_move - 1; + + } + + if ( num_to_read > YY_READ_BUF_SIZE ) + num_to_read = YY_READ_BUF_SIZE; + + /* Read in more data. */ + YY_INPUT( (&YY_CURRENT_BUFFER_LVALUE->yy_ch_buf[number_to_move]), + (yy_n_chars), num_to_read ); + + YY_CURRENT_BUFFER_LVALUE->yy_n_chars = (yy_n_chars); + } + + if ( (yy_n_chars) == 0 ) + { + if ( number_to_move == YY_MORE_ADJ ) + { + ret_val = EOB_ACT_END_OF_FILE; + yyrestart(yyin ); + } + + else + { + ret_val = EOB_ACT_LAST_MATCH; + YY_CURRENT_BUFFER_LVALUE->yy_buffer_status = + YY_BUFFER_EOF_PENDING; + } + } + + else + ret_val = EOB_ACT_CONTINUE_SCAN; + + if ((int) ((yy_n_chars) + number_to_move) > YY_CURRENT_BUFFER_LVALUE->yy_buf_size) { + /* Extend the array by 50%, plus the number we really need. */ + int new_size = (yy_n_chars) + number_to_move + ((yy_n_chars) >> 1); + YY_CURRENT_BUFFER_LVALUE->yy_ch_buf = (char *) yyrealloc((void *) YY_CURRENT_BUFFER_LVALUE->yy_ch_buf,new_size ); + if ( ! YY_CURRENT_BUFFER_LVALUE->yy_ch_buf ) + YY_FATAL_ERROR( "out of dynamic memory in yy_get_next_buffer()" ); + } + + (yy_n_chars) += number_to_move; + YY_CURRENT_BUFFER_LVALUE->yy_ch_buf[(yy_n_chars)] = YY_END_OF_BUFFER_CHAR; + YY_CURRENT_BUFFER_LVALUE->yy_ch_buf[(yy_n_chars) + 1] = YY_END_OF_BUFFER_CHAR; + + (yytext_ptr) = &YY_CURRENT_BUFFER_LVALUE->yy_ch_buf[0]; + + return ret_val; +} + +/* yy_get_previous_state - get the state just before the EOB char was reached */ + + static yy_state_type yy_get_previous_state (void) +{ + yy_state_type yy_current_state; + char *yy_cp; + + yy_current_state = (yy_start); + + for ( yy_cp = (yytext_ptr) + YY_MORE_ADJ; yy_cp < (yy_c_buf_p); ++yy_cp ) + { + YY_CHAR yy_c = (*yy_cp ? yy_ec[YY_SC_TO_UI(*yy_cp)] : 1); + if ( yy_accept[yy_current_state] ) + { + (yy_last_accepting_state) = yy_current_state; + (yy_last_accepting_cpos) = yy_cp; + } + while ( yy_chk[yy_base[yy_current_state] + yy_c] != yy_current_state ) + { + yy_current_state = (int) yy_def[yy_current_state]; + if ( yy_current_state >= 185 ) + yy_c = yy_meta[(unsigned int) yy_c]; + } + yy_current_state = yy_nxt[yy_base[yy_current_state] + (unsigned int) yy_c]; + } + + return yy_current_state; +} + +/* yy_try_NUL_trans - try to make a transition on the NUL character + * + * synopsis + * next_state = yy_try_NUL_trans( current_state ); + */ + static yy_state_type yy_try_NUL_trans (yy_state_type yy_current_state ) +{ + int yy_is_jam; + char *yy_cp = (yy_c_buf_p); + + YY_CHAR yy_c = 1; + if ( yy_accept[yy_current_state] ) + { + (yy_last_accepting_state) = yy_current_state; + (yy_last_accepting_cpos) = yy_cp; + } + while ( yy_chk[yy_base[yy_current_state] + yy_c] != yy_current_state ) + { + yy_current_state = (int) yy_def[yy_current_state]; + if ( yy_current_state >= 185 ) + yy_c = yy_meta[(unsigned int) yy_c]; + } + yy_current_state = yy_nxt[yy_base[yy_current_state] + (unsigned int) yy_c]; + yy_is_jam = (yy_current_state == 184); + + return yy_is_jam ? 0 : yy_current_state; +} + +#ifndef YY_NO_UNPUT + + static void yyunput (int c, char * yy_bp ) +{ + char *yy_cp; + + yy_cp = (yy_c_buf_p); + + /* undo effects of setting up yytext */ + *yy_cp = (yy_hold_char); + + if ( yy_cp < YY_CURRENT_BUFFER_LVALUE->yy_ch_buf + 2 ) + { /* need to shift things up to make room */ + /* +2 for EOB chars. */ + yy_size_t number_to_move = (yy_n_chars) + 2; + char *dest = &YY_CURRENT_BUFFER_LVALUE->yy_ch_buf[ + YY_CURRENT_BUFFER_LVALUE->yy_buf_size + 2]; + char *source = + &YY_CURRENT_BUFFER_LVALUE->yy_ch_buf[number_to_move]; + + while ( source > YY_CURRENT_BUFFER_LVALUE->yy_ch_buf ) + *--dest = *--source; + + yy_cp += (int) (dest - source); + yy_bp += (int) (dest - source); + YY_CURRENT_BUFFER_LVALUE->yy_n_chars = + (yy_n_chars) = YY_CURRENT_BUFFER_LVALUE->yy_buf_size; + + if ( yy_cp < YY_CURRENT_BUFFER_LVALUE->yy_ch_buf + 2 ) + YY_FATAL_ERROR( "flex scanner push-back overflow" ); + } + + *--yy_cp = (char) c; + + (yytext_ptr) = yy_bp; + (yy_hold_char) = *yy_cp; + (yy_c_buf_p) = yy_cp; +} + +#endif + +#ifndef YY_NO_INPUT +#ifdef __cplusplus + static int yyinput (void) +#else + static int input (void) +#endif + +{ + int c; + + *(yy_c_buf_p) = (yy_hold_char); + + if ( *(yy_c_buf_p) == YY_END_OF_BUFFER_CHAR ) + { + /* yy_c_buf_p now points to the character we want to return. + * If this occurs *before* the EOB characters, then it's a + * valid NUL; if not, then we've hit the end of the buffer. + */ + if ( (yy_c_buf_p) < &YY_CURRENT_BUFFER_LVALUE->yy_ch_buf[(yy_n_chars)] ) + /* This was really a NUL. */ + *(yy_c_buf_p) = '\0'; + + else + { /* need more input */ + yy_size_t offset = (yy_c_buf_p) - (yytext_ptr); + ++(yy_c_buf_p); + + switch ( yy_get_next_buffer( ) ) + { + case EOB_ACT_LAST_MATCH: + /* This happens because yy_g_n_b() + * sees that we've accumulated a + * token and flags that we need to + * try matching the token before + * proceeding. But for input(), + * there's no matching to consider. + * So convert the EOB_ACT_LAST_MATCH + * to EOB_ACT_END_OF_FILE. + */ + + /* Reset buffer status. */ + yyrestart(yyin ); + + /*FALLTHROUGH*/ + + case EOB_ACT_END_OF_FILE: + { + if ( yywrap( ) ) + return EOF; + + if ( ! (yy_did_buffer_switch_on_eof) ) + YY_NEW_FILE; +#ifdef __cplusplus + return yyinput(); +#else + return input(); +#endif + } + + case EOB_ACT_CONTINUE_SCAN: + (yy_c_buf_p) = (yytext_ptr) + offset; + break; + } + } + } + + c = *(unsigned char *) (yy_c_buf_p); /* cast for 8-bit char's */ + *(yy_c_buf_p) = '\0'; /* preserve yytext */ + (yy_hold_char) = *++(yy_c_buf_p); + + return c; +} +#endif /* ifndef YY_NO_INPUT */ + +/** Immediately switch to a different input stream. + * @param input_file A readable stream. + * + * @note This function does not reset the start condition to @c INITIAL . + */ + void yyrestart (FILE * input_file ) +{ + + if ( ! YY_CURRENT_BUFFER ){ + yyensure_buffer_stack (); + YY_CURRENT_BUFFER_LVALUE = + yy_create_buffer(yyin,YY_BUF_SIZE ); + } + + yy_init_buffer(YY_CURRENT_BUFFER,input_file ); + yy_load_buffer_state( ); +} + +/** Switch to a different input buffer. + * @param new_buffer The new input buffer. + * + */ + void yy_switch_to_buffer (YY_BUFFER_STATE new_buffer ) +{ + + /* TODO. We should be able to replace this entire function body + * with + * yypop_buffer_state(); + * yypush_buffer_state(new_buffer); + */ + yyensure_buffer_stack (); + if ( YY_CURRENT_BUFFER == new_buffer ) + return; + + if ( YY_CURRENT_BUFFER ) + { + /* Flush out information for old buffer. */ + *(yy_c_buf_p) = (yy_hold_char); + YY_CURRENT_BUFFER_LVALUE->yy_buf_pos = (yy_c_buf_p); + YY_CURRENT_BUFFER_LVALUE->yy_n_chars = (yy_n_chars); + } + + YY_CURRENT_BUFFER_LVALUE = new_buffer; + yy_load_buffer_state( ); + + /* We don't actually know whether we did this switch during + * EOF (yywrap()) processing, but the only time this flag + * is looked at is after yywrap() is called, so it's safe + * to go ahead and always set it. + */ + (yy_did_buffer_switch_on_eof) = 1; +} + +static void yy_load_buffer_state (void) +{ + (yy_n_chars) = YY_CURRENT_BUFFER_LVALUE->yy_n_chars; + (yytext_ptr) = (yy_c_buf_p) = YY_CURRENT_BUFFER_LVALUE->yy_buf_pos; + yyin = YY_CURRENT_BUFFER_LVALUE->yy_input_file; + (yy_hold_char) = *(yy_c_buf_p); +} + +/** Allocate and initialize an input buffer state. + * @param file A readable stream. + * @param size The character buffer size in bytes. When in doubt, use @c YY_BUF_SIZE. + * + * @return the allocated buffer state. + */ + YY_BUFFER_STATE yy_create_buffer (FILE * file, int size ) +{ + YY_BUFFER_STATE b; + + b = (YY_BUFFER_STATE) yyalloc(sizeof( struct yy_buffer_state ) ); + if ( ! b ) + YY_FATAL_ERROR( "out of dynamic memory in yy_create_buffer()" ); + + b->yy_buf_size = (yy_size_t)size; + + /* yy_ch_buf has to be 2 characters longer than the size given because + * we need to put in 2 end-of-buffer characters. + */ + b->yy_ch_buf = (char *) yyalloc(b->yy_buf_size + 2 ); + if ( ! b->yy_ch_buf ) + YY_FATAL_ERROR( "out of dynamic memory in yy_create_buffer()" ); + + b->yy_is_our_buffer = 1; + + yy_init_buffer(b,file ); + + return b; +} + +/** Destroy the buffer. + * @param b a buffer created with yy_create_buffer() + * + */ + void yy_delete_buffer (YY_BUFFER_STATE b ) +{ + + if ( ! b ) + return; + + if ( b == YY_CURRENT_BUFFER ) /* Not sure if we should pop here. */ + YY_CURRENT_BUFFER_LVALUE = (YY_BUFFER_STATE) 0; + + if ( b->yy_is_our_buffer ) + yyfree((void *) b->yy_ch_buf ); + + yyfree((void *) b ); +} + +/* Initializes or reinitializes a buffer. + * This function is sometimes called more than once on the same buffer, + * such as during a yyrestart() or at EOF. + */ + static void yy_init_buffer (YY_BUFFER_STATE b, FILE * file ) + +{ + int oerrno = errno; + + yy_flush_buffer(b ); + + b->yy_input_file = file; + b->yy_fill_buffer = 1; + + /* If b is the current buffer, then yy_init_buffer was _probably_ + * called from yyrestart() or through yy_get_next_buffer. + * In that case, we don't want to reset the lineno or column. + */ + if (b != YY_CURRENT_BUFFER){ + b->yy_bs_lineno = 1; + b->yy_bs_column = 0; + } + + b->yy_is_interactive = file ? (isatty( fileno(file) ) > 0) : 0; + + errno = oerrno; +} + +/** Discard all buffered characters. On the next scan, YY_INPUT will be called. + * @param b the buffer state to be flushed, usually @c YY_CURRENT_BUFFER. + * + */ + void yy_flush_buffer (YY_BUFFER_STATE b ) +{ + if ( ! b ) + return; + + b->yy_n_chars = 0; + + /* We always need two end-of-buffer characters. The first causes + * a transition to the end-of-buffer state. The second causes + * a jam in that state. + */ + b->yy_ch_buf[0] = YY_END_OF_BUFFER_CHAR; + b->yy_ch_buf[1] = YY_END_OF_BUFFER_CHAR; + + b->yy_buf_pos = &b->yy_ch_buf[0]; + + b->yy_at_bol = 1; + b->yy_buffer_status = YY_BUFFER_NEW; + + if ( b == YY_CURRENT_BUFFER ) + yy_load_buffer_state( ); +} + +/** Pushes the new state onto the stack. The new state becomes + * the current state. This function will allocate the stack + * if necessary. + * @param new_buffer The new state. + * + */ +void yypush_buffer_state (YY_BUFFER_STATE new_buffer ) +{ + if (new_buffer == NULL) + return; + + yyensure_buffer_stack(); + + /* This block is copied from yy_switch_to_buffer. */ + if ( YY_CURRENT_BUFFER ) + { + /* Flush out information for old buffer. */ + *(yy_c_buf_p) = (yy_hold_char); + YY_CURRENT_BUFFER_LVALUE->yy_buf_pos = (yy_c_buf_p); + YY_CURRENT_BUFFER_LVALUE->yy_n_chars = (yy_n_chars); + } + + /* Only push if top exists. Otherwise, replace top. */ + if (YY_CURRENT_BUFFER) + (yy_buffer_stack_top)++; + YY_CURRENT_BUFFER_LVALUE = new_buffer; + + /* copied from yy_switch_to_buffer. */ + yy_load_buffer_state( ); + (yy_did_buffer_switch_on_eof) = 1; +} + +/** Removes and deletes the top of the stack, if present. + * The next element becomes the new top. + * + */ +void yypop_buffer_state (void) +{ + if (!YY_CURRENT_BUFFER) + return; + + yy_delete_buffer(YY_CURRENT_BUFFER ); + YY_CURRENT_BUFFER_LVALUE = NULL; + if ((yy_buffer_stack_top) > 0) + --(yy_buffer_stack_top); + + if (YY_CURRENT_BUFFER) { + yy_load_buffer_state( ); + (yy_did_buffer_switch_on_eof) = 1; + } +} + +/* Allocates the stack if it does not exist. + * Guarantees space for at least one push. + */ +static void yyensure_buffer_stack (void) +{ + yy_size_t num_to_alloc; + + if (!(yy_buffer_stack)) { + + /* First allocation is just for 2 elements, since we don't know if this + * scanner will even need a stack. We use 2 instead of 1 to avoid an + * immediate realloc on the next call. + */ + num_to_alloc = 1; /* After all that talk, this was set to 1 anyways... */ + (yy_buffer_stack) = (struct yy_buffer_state**)yyalloc + (num_to_alloc * sizeof(struct yy_buffer_state*) + ); + if ( ! (yy_buffer_stack) ) + YY_FATAL_ERROR( "out of dynamic memory in yyensure_buffer_stack()" ); + + memset((yy_buffer_stack), 0, num_to_alloc * sizeof(struct yy_buffer_state*)); + + (yy_buffer_stack_max) = num_to_alloc; + (yy_buffer_stack_top) = 0; + return; + } + + if ((yy_buffer_stack_top) >= ((yy_buffer_stack_max)) - 1){ + + /* Increase the buffer to prepare for a possible push. */ + yy_size_t grow_size = 8 /* arbitrary grow size */; + + num_to_alloc = (yy_buffer_stack_max) + grow_size; + (yy_buffer_stack) = (struct yy_buffer_state**)yyrealloc + ((yy_buffer_stack), + num_to_alloc * sizeof(struct yy_buffer_state*) + ); + if ( ! (yy_buffer_stack) ) + YY_FATAL_ERROR( "out of dynamic memory in yyensure_buffer_stack()" ); + + /* zero only the new slots.*/ + memset((yy_buffer_stack) + (yy_buffer_stack_max), 0, grow_size * sizeof(struct yy_buffer_state*)); + (yy_buffer_stack_max) = num_to_alloc; + } +} + +/** Setup the input buffer state to scan directly from a user-specified character buffer. + * @param base the character buffer + * @param size the size in bytes of the character buffer + * + * @return the newly allocated buffer state object. + */ +YY_BUFFER_STATE yy_scan_buffer (char * base, yy_size_t size ) +{ + YY_BUFFER_STATE b; + + if ( size < 2 || + base[size-2] != YY_END_OF_BUFFER_CHAR || + base[size-1] != YY_END_OF_BUFFER_CHAR ) + /* They forgot to leave room for the EOB's. */ + return 0; + + b = (YY_BUFFER_STATE) yyalloc(sizeof( struct yy_buffer_state ) ); + if ( ! b ) + YY_FATAL_ERROR( "out of dynamic memory in yy_scan_buffer()" ); + + b->yy_buf_size = size - 2; /* "- 2" to take care of EOB's */ + b->yy_buf_pos = b->yy_ch_buf = base; + b->yy_is_our_buffer = 0; + b->yy_input_file = 0; + b->yy_n_chars = b->yy_buf_size; + b->yy_is_interactive = 0; + b->yy_at_bol = 1; + b->yy_fill_buffer = 0; + b->yy_buffer_status = YY_BUFFER_NEW; + + yy_switch_to_buffer(b ); + + return b; +} + +/** Setup the input buffer state to scan a string. The next call to yylex() will + * scan from a @e copy of @a str. + * @param yystr a NUL-terminated string to scan + * + * @return the newly allocated buffer state object. + * @note If you want to scan bytes that may contain NUL values, then use + * yy_scan_bytes() instead. + */ +YY_BUFFER_STATE yy_scan_string (yyconst char * yystr ) +{ + + return yy_scan_bytes(yystr,strlen(yystr) ); +} + +/** Setup the input buffer state to scan the given bytes. The next call to yylex() will + * scan from a @e copy of @a bytes. + * @param yybytes the byte buffer to scan + * @param _yybytes_len the number of bytes in the buffer pointed to by @a bytes. + * + * @return the newly allocated buffer state object. + */ +YY_BUFFER_STATE yy_scan_bytes (yyconst char * yybytes, yy_size_t _yybytes_len ) +{ + YY_BUFFER_STATE b; + char *buf; + yy_size_t n; + yy_size_t i; + + /* Get memory for full buffer, including space for trailing EOB's. */ + n = _yybytes_len + 2; + buf = (char *) yyalloc(n ); + if ( ! buf ) + YY_FATAL_ERROR( "out of dynamic memory in yy_scan_bytes()" ); + + for ( i = 0; i < _yybytes_len; ++i ) + buf[i] = yybytes[i]; + + buf[_yybytes_len] = buf[_yybytes_len+1] = YY_END_OF_BUFFER_CHAR; + + b = yy_scan_buffer(buf,n ); + if ( ! b ) + YY_FATAL_ERROR( "bad buffer in yy_scan_bytes()" ); + + /* It's okay to grow etc. this buffer, and we should throw it + * away when we're done. + */ + b->yy_is_our_buffer = 1; + + return b; +} + +#ifndef YY_EXIT_FAILURE +#define YY_EXIT_FAILURE 2 +#endif + +static void yy_fatal_error (yyconst char* msg ) +{ + (void) fprintf( stderr, "%s\n", msg ); + exit( YY_EXIT_FAILURE ); +} + +/* Redefine yyless() so it works in section 3 code. */ + +#undef yyless +#define yyless(n) \ + do \ + { \ + /* Undo effects of setting up yytext. */ \ + int yyless_macro_arg = (n); \ + YY_LESS_LINENO(yyless_macro_arg);\ + yytext[yyleng] = (yy_hold_char); \ + (yy_c_buf_p) = yytext + yyless_macro_arg; \ + (yy_hold_char) = *(yy_c_buf_p); \ + *(yy_c_buf_p) = '\0'; \ + yyleng = yyless_macro_arg; \ + } \ + while ( 0 ) + +/* Accessor methods (get/set functions) to struct members. */ + +/** Get the current line number. + * + */ +int yyget_lineno (void) +{ + + return yylineno; +} + +/** Get the input stream. + * + */ +FILE *yyget_in (void) +{ + return yyin; +} + +/** Get the output stream. + * + */ +FILE *yyget_out (void) +{ + return yyout; +} + +/** Get the length of the current token. + * + */ +yy_size_t yyget_leng (void) +{ + return yyleng; +} + +/** Get the current token. + * + */ + +char *yyget_text (void) +{ + return yytext; +} + +/** Set the current line number. + * @param _line_number line number + * + */ +void yyset_lineno (int _line_number ) +{ + + yylineno = _line_number; +} + +/** Set the input stream. This does not discard the current + * input buffer. + * @param _in_str A readable stream. + * + * @see yy_switch_to_buffer + */ +void yyset_in (FILE * _in_str ) +{ + yyin = _in_str ; +} + +void yyset_out (FILE * _out_str ) +{ + yyout = _out_str ; +} + +int yyget_debug (void) +{ + return yy_flex_debug; +} + +void yyset_debug (int _bdebug ) +{ + yy_flex_debug = _bdebug ; +} + +static int yy_init_globals (void) +{ + /* Initialization is the same as for the non-reentrant scanner. + * This function is called from yylex_destroy(), so don't allocate here. + */ + + (yy_buffer_stack) = 0; + (yy_buffer_stack_top) = 0; + (yy_buffer_stack_max) = 0; + (yy_c_buf_p) = (char *) 0; + (yy_init) = 0; + (yy_start) = 0; + +/* Defined in main.c */ +#ifdef YY_STDINIT + yyin = stdin; + yyout = stdout; +#else + yyin = (FILE *) 0; + yyout = (FILE *) 0; +#endif + + /* For future reference: Set errno on error, since we are called by + * yylex_init() + */ + return 0; +} + +/* yylex_destroy is for both reentrant and non-reentrant scanners. */ +int yylex_destroy (void) +{ + + /* Pop the buffer stack, destroying each element. */ + while(YY_CURRENT_BUFFER){ + yy_delete_buffer(YY_CURRENT_BUFFER ); + YY_CURRENT_BUFFER_LVALUE = NULL; + yypop_buffer_state(); + } + + /* Destroy the stack itself. */ + yyfree((yy_buffer_stack) ); + (yy_buffer_stack) = NULL; + + /* Reset the globals. This is important in a non-reentrant scanner so the next time + * yylex() is called, initialization will occur. */ + yy_init_globals( ); + + return 0; +} + +/* + * Internal utility routines. + */ + +#ifndef yytext_ptr +static void yy_flex_strncpy (char* s1, yyconst char * s2, int n ) +{ + + int i; + for ( i = 0; i < n; ++i ) + s1[i] = s2[i]; +} +#endif + +#ifdef YY_NEED_STRLEN +static int yy_flex_strlen (yyconst char * s ) +{ + int n; + for ( n = 0; s[n]; ++n ) + ; + + return n; +} +#endif + +void *yyalloc (yy_size_t size ) +{ + return (void *) malloc( size ); +} + +void *yyrealloc (void * ptr, yy_size_t size ) +{ + + /* The cast to (char *) in the following accommodates both + * implementations that use char* generic pointers, and those + * that use void* generic pointers. It works with the latter + * because both ANSI C and C++ allow castless assignment from + * any pointer type to void*, and deal with argument conversions + * as though doing an assignment. + */ + return (void *) realloc( (char *) ptr, size ); +} + +void yyfree (void * ptr ) +{ + free( (char *) ptr ); /* see yyrealloc() for (char *) cast */ +} + +#define YYTABLES_NAME "yytables" + +#line 94 "tokens.l" + + + +int yywrap () +{ + return(1); +} + +void go2init() +{ + yy_init = 1; +} + diff --git a/src/interf/lex.yy.cpp b/src/interf/lex.yy.cpp new file mode 100644 index 0000000000000000000000000000000000000000..ce2def860d48067ff3330049147b324f6e1f133c --- /dev/null +++ b/src/interf/lex.yy.cpp @@ -0,0 +1,2153 @@ +#line 2 "lex.yy.cpp" + +#line 4 "lex.yy.cpp" + +#define YY_INT_ALIGNED short int + +/* A lexical scanner generated by flex */ + +#define FLEX_SCANNER +#define YY_FLEX_MAJOR_VERSION 2 +#define YY_FLEX_MINOR_VERSION 6 +#define YY_FLEX_SUBMINOR_VERSION 0 +#if YY_FLEX_SUBMINOR_VERSION > 0 +#define FLEX_BETA +#endif + +/* First, we deal with platform-specific or compiler-specific issues. */ + +/* begin standard C headers. */ +#include <stdio.h> +#include <string.h> +#include <errno.h> +#include <stdlib.h> + +/* end standard C headers. */ + +/* flex integer type definitions */ + +#ifndef FLEXINT_H +#define FLEXINT_H + +/* C99 systems have <inttypes.h>. Non-C99 systems may or may not. */ + +#if defined (__STDC_VERSION__) && __STDC_VERSION__ >= 199901L + +/* C99 says to define __STDC_LIMIT_MACROS before including stdint.h, + * if you want the limit (max/min) macros for int types. + */ +#ifndef __STDC_LIMIT_MACROS +#define __STDC_LIMIT_MACROS 1 +#endif + +#include <inttypes.h> +typedef int8_t flex_int8_t; +typedef uint8_t flex_uint8_t; +typedef int16_t flex_int16_t; +typedef uint16_t flex_uint16_t; +typedef int32_t flex_int32_t; +typedef uint32_t flex_uint32_t; +#else +typedef signed char flex_int8_t; +typedef short int flex_int16_t; +typedef int flex_int32_t; +typedef unsigned char flex_uint8_t; +typedef unsigned short int flex_uint16_t; +typedef unsigned int flex_uint32_t; + +/* Limits of integral types. */ +#ifndef INT8_MIN +#define INT8_MIN (-128) +#endif +#ifndef INT16_MIN +#define INT16_MIN (-32767-1) +#endif +#ifndef INT32_MIN +#define INT32_MIN (-2147483647-1) +#endif +#ifndef INT8_MAX +#define INT8_MAX (127) +#endif +#ifndef INT16_MAX +#define INT16_MAX (32767) +#endif +#ifndef INT32_MAX +#define INT32_MAX (2147483647) +#endif +#ifndef UINT8_MAX +#define UINT8_MAX (255U) +#endif +#ifndef UINT16_MAX +#define UINT16_MAX (65535U) +#endif +#ifndef UINT32_MAX +#define UINT32_MAX (4294967295U) +#endif + +#endif /* ! C99 */ + +#endif /* ! FLEXINT_H */ + +#ifdef __cplusplus + +/* The "const" storage-class-modifier is valid. */ +#define YY_USE_CONST + +#else /* ! __cplusplus */ + +/* C99 requires __STDC__ to be defined as 1. */ +#if defined (__STDC__) + +#define YY_USE_CONST + +#endif /* defined (__STDC__) */ +#endif /* ! __cplusplus */ + +#ifdef YY_USE_CONST +#define yyconst const +#else +#define yyconst +#endif + +/* Returned upon end-of-file. */ +#define YY_NULL 0 + +/* Promotes a possibly negative, possibly signed char to an unsigned + * integer for use as an array index. If the signed char is negative, + * we want to instead treat it as an 8-bit unsigned char, hence the + * double cast. + */ +#define YY_SC_TO_UI(c) ((unsigned int) (unsigned char) c) + +/* Enter a start condition. This macro really ought to take a parameter, + * but we do it the disgusting crufty way forced on us by the ()-less + * definition of BEGIN. + */ +#define BEGIN (yy_start) = 1 + 2 * + +/* Translate the current start state into a value that can be later handed + * to BEGIN to return to the state. The YYSTATE alias is for lex + * compatibility. + */ +#define YY_START (((yy_start) - 1) / 2) +#define YYSTATE YY_START + +/* Action number for EOF rule of a given start state. */ +#define YY_STATE_EOF(state) (YY_END_OF_BUFFER + state + 1) + +/* Special action meaning "start processing a new file". */ +#define YY_NEW_FILE yyrestart(yyin ) + +#define YY_END_OF_BUFFER_CHAR 0 + +/* Size of default input buffer. */ +#ifndef YY_BUF_SIZE +#ifdef __ia64__ +/* On IA-64, the buffer size is 16k, not 8k. + * Moreover, YY_BUF_SIZE is 2*YY_READ_BUF_SIZE in the general case. + * Ditto for the __ia64__ case accordingly. + */ +#define YY_BUF_SIZE 32768 +#else +#define YY_BUF_SIZE 16384 +#endif /* __ia64__ */ +#endif + +/* The state buf must be large enough to hold one state per character in the main buffer. + */ +#define YY_STATE_BUF_SIZE ((YY_BUF_SIZE + 2) * sizeof(yy_state_type)) + +#ifndef YY_TYPEDEF_YY_BUFFER_STATE +#define YY_TYPEDEF_YY_BUFFER_STATE +typedef struct yy_buffer_state *YY_BUFFER_STATE; +#endif + +#ifndef YY_TYPEDEF_YY_SIZE_T +#define YY_TYPEDEF_YY_SIZE_T +typedef size_t yy_size_t; +#endif + +extern yy_size_t yyleng; + +extern FILE *yyin, *yyout; + +#define EOB_ACT_CONTINUE_SCAN 0 +#define EOB_ACT_END_OF_FILE 1 +#define EOB_ACT_LAST_MATCH 2 + + #define YY_LESS_LINENO(n) + #define YY_LINENO_REWIND_TO(ptr) + +/* Return all but the first "n" matched characters back to the input stream. */ +#define yyless(n) \ + do \ + { \ + /* Undo effects of setting up yytext. */ \ + int yyless_macro_arg = (n); \ + YY_LESS_LINENO(yyless_macro_arg);\ + *yy_cp = (yy_hold_char); \ + YY_RESTORE_YY_MORE_OFFSET \ + (yy_c_buf_p) = yy_cp = yy_bp + yyless_macro_arg - YY_MORE_ADJ; \ + YY_DO_BEFORE_ACTION; /* set up yytext again */ \ + } \ + while ( 0 ) + +#define unput(c) yyunput( c, (yytext_ptr) ) + +#ifndef YY_STRUCT_YY_BUFFER_STATE +#define YY_STRUCT_YY_BUFFER_STATE +struct yy_buffer_state + { + FILE *yy_input_file; + + char *yy_ch_buf; /* input buffer */ + char *yy_buf_pos; /* current position in input buffer */ + + /* Size of input buffer in bytes, not including room for EOB + * characters. + */ + yy_size_t yy_buf_size; + + /* Number of characters read into yy_ch_buf, not including EOB + * characters. + */ + int yy_n_chars; + + /* Whether we "own" the buffer - i.e., we know we created it, + * and can realloc() it to grow it, and should free() it to + * delete it. + */ + int yy_is_our_buffer; + + /* Whether this is an "interactive" input source; if so, and + * if we're using stdio for input, then we want to use getc() + * instead of fread(), to make sure we stop fetching input after + * each newline. + */ + int yy_is_interactive; + + /* Whether we're considered to be at the beginning of a line. + * If so, '^' rules will be active on the next match, otherwise + * not. + */ + int yy_at_bol; + + int yy_bs_lineno; /**< The line count. */ + int yy_bs_column; /**< The column count. */ + + /* Whether to try to fill the input buffer when we reach the + * end of it. + */ + int yy_fill_buffer; + + int yy_buffer_status; + +#define YY_BUFFER_NEW 0 +#define YY_BUFFER_NORMAL 1 + /* When an EOF's been seen but there's still some text to process + * then we mark the buffer as YY_EOF_PENDING, to indicate that we + * shouldn't try reading from the input source any more. We might + * still have a bunch of tokens to match, though, because of + * possible backing-up. + * + * When we actually see the EOF, we change the status to "new" + * (via yyrestart()), so that the user can continue scanning by + * just pointing yyin at a new input file. + */ +#define YY_BUFFER_EOF_PENDING 2 + + }; +#endif /* !YY_STRUCT_YY_BUFFER_STATE */ + +/* Stack of input buffers. */ +static size_t yy_buffer_stack_top = 0; /**< index of top of stack. */ +static size_t yy_buffer_stack_max = 0; /**< capacity of stack. */ +static YY_BUFFER_STATE * yy_buffer_stack = 0; /**< Stack as an array. */ + +/* We provide macros for accessing buffer states in case in the + * future we want to put the buffer states in a more general + * "scanner state". + * + * Returns the top of the stack, or NULL. + */ +#define YY_CURRENT_BUFFER ( (yy_buffer_stack) \ + ? (yy_buffer_stack)[(yy_buffer_stack_top)] \ + : NULL) + +/* Same as previous macro, but useful when we know that the buffer stack is not + * NULL or when we need an lvalue. For internal use only. + */ +#define YY_CURRENT_BUFFER_LVALUE (yy_buffer_stack)[(yy_buffer_stack_top)] + +/* yy_hold_char holds the character lost when yytext is formed. */ +static char yy_hold_char; +static int yy_n_chars; /* number of characters read into yy_ch_buf */ +yy_size_t yyleng; + +/* Points to current character in buffer. */ +static char *yy_c_buf_p = (char *) 0; +static int yy_init = 0; /* whether we need to initialize */ +static int yy_start = 0; /* start state number */ + +/* Flag which is used to allow yywrap()'s to do buffer switches + * instead of setting up a fresh yyin. A bit of a hack ... + */ +static int yy_did_buffer_switch_on_eof; + +void yyrestart (FILE *input_file ); +void yy_switch_to_buffer (YY_BUFFER_STATE new_buffer ); +YY_BUFFER_STATE yy_create_buffer (FILE *file,int size ); +void yy_delete_buffer (YY_BUFFER_STATE b ); +void yy_flush_buffer (YY_BUFFER_STATE b ); +void yypush_buffer_state (YY_BUFFER_STATE new_buffer ); +void yypop_buffer_state (void ); + +static void yyensure_buffer_stack (void ); +static void yy_load_buffer_state (void ); +static void yy_init_buffer (YY_BUFFER_STATE b,FILE *file ); + +#define YY_FLUSH_BUFFER yy_flush_buffer(YY_CURRENT_BUFFER ) + +YY_BUFFER_STATE yy_scan_buffer (char *base,yy_size_t size ); +YY_BUFFER_STATE yy_scan_string (yyconst char *yy_str ); +YY_BUFFER_STATE yy_scan_bytes (yyconst char *bytes,yy_size_t len ); + +void *yyalloc (yy_size_t ); +void *yyrealloc (void *,yy_size_t ); +void yyfree (void * ); + +#define yy_new_buffer yy_create_buffer + +#define yy_set_interactive(is_interactive) \ + { \ + if ( ! YY_CURRENT_BUFFER ){ \ + yyensure_buffer_stack (); \ + YY_CURRENT_BUFFER_LVALUE = \ + yy_create_buffer(yyin,YY_BUF_SIZE ); \ + } \ + YY_CURRENT_BUFFER_LVALUE->yy_is_interactive = is_interactive; \ + } + +#define yy_set_bol(at_bol) \ + { \ + if ( ! YY_CURRENT_BUFFER ){\ + yyensure_buffer_stack (); \ + YY_CURRENT_BUFFER_LVALUE = \ + yy_create_buffer(yyin,YY_BUF_SIZE ); \ + } \ + YY_CURRENT_BUFFER_LVALUE->yy_at_bol = at_bol; \ + } + +#define YY_AT_BOL() (YY_CURRENT_BUFFER_LVALUE->yy_at_bol) + +/* Begin user sect3 */ + +typedef unsigned char YY_CHAR; + +FILE *yyin = (FILE *) 0, *yyout = (FILE *) 0; + +typedef int yy_state_type; + +extern int yylineno; + +int yylineno = 1; + +extern char *yytext; +#ifdef yytext_ptr +#undef yytext_ptr +#endif +#define yytext_ptr yytext + +static yy_state_type yy_get_previous_state (void ); +static yy_state_type yy_try_NUL_trans (yy_state_type current_state ); +static int yy_get_next_buffer (void ); +#if defined(__GNUC__) && __GNUC__ >= 3 +__attribute__((__noreturn__)) +#endif +static void yy_fatal_error (yyconst char msg[] ); + +/* Done after the current pattern has been matched and before the + * corresponding action - sets up yytext. + */ +#define YY_DO_BEFORE_ACTION \ + (yytext_ptr) = yy_bp; \ + yyleng = (size_t) (yy_cp - yy_bp); \ + (yy_hold_char) = *yy_cp; \ + *yy_cp = '\0'; \ + (yy_c_buf_p) = yy_cp; + +#define YY_NUM_RULES 49 +#define YY_END_OF_BUFFER 50 +/* This struct is not used in this scanner, + but its presence is necessary. */ +struct yy_trans_info + { + flex_int32_t yy_verify; + flex_int32_t yy_nxt; + }; +static yyconst flex_int16_t yy_accept[185] = + { 0, + 46, 46, 50, 48, 46, 47, 33, 38, 39, 35, + 43, 48, 29, 45, 42, 44, 34, 32, 28, 40, + 41, 28, 28, 28, 28, 28, 28, 28, 28, 28, + 28, 28, 28, 28, 28, 28, 36, 37, 46, 1, + 0, 29, 0, 28, 28, 28, 28, 28, 28, 28, + 28, 28, 28, 28, 28, 28, 28, 28, 28, 28, + 28, 28, 28, 28, 1, 30, 0, 31, 2, 28, + 28, 28, 28, 28, 28, 28, 28, 28, 28, 28, + 28, 28, 28, 28, 28, 28, 28, 28, 28, 28, + 28, 28, 28, 28, 28, 9, 28, 28, 28, 28, + + 28, 28, 28, 28, 28, 28, 28, 22, 28, 28, + 28, 28, 3, 28, 28, 28, 28, 28, 28, 28, + 28, 28, 28, 15, 28, 28, 18, 20, 28, 28, + 28, 28, 27, 28, 28, 28, 28, 8, 28, 28, + 28, 13, 28, 28, 17, 19, 21, 23, 28, 28, + 28, 28, 28, 28, 28, 11, 28, 14, 16, 28, + 28, 28, 28, 28, 7, 10, 28, 28, 28, 28, + 28, 28, 28, 28, 28, 4, 5, 28, 12, 24, + 26, 6, 25, 0 + } ; + +static yyconst YY_CHAR yy_ec[256] = + { 0, + 1, 1, 1, 1, 1, 1, 1, 1, 2, 3, + 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, + 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, + 1, 4, 5, 5, 6, 5, 5, 5, 5, 7, + 8, 9, 10, 11, 10, 12, 13, 14, 14, 14, + 14, 14, 14, 14, 14, 14, 14, 15, 16, 5, + 17, 5, 18, 19, 20, 20, 20, 20, 21, 20, + 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, + 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, + 22, 5, 23, 5, 20, 1, 24, 25, 26, 27, + + 28, 29, 30, 31, 32, 20, 33, 34, 35, 36, + 37, 38, 20, 39, 40, 41, 42, 43, 44, 20, + 45, 20, 46, 5, 47, 5, 1, 1, 1, 1, + 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, + 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, + 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, + 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, + 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, + 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, + 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, + + 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, + 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, + 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, + 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, + 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, + 1, 1, 1, 1, 1 + } ; + +static yyconst YY_CHAR yy_meta[48] = + { 0, + 1, 1, 1, 2, 2, 2, 2, 2, 2, 2, + 2, 2, 2, 3, 2, 2, 2, 2, 2, 3, + 3, 2, 2, 3, 3, 3, 3, 3, 3, 3, + 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, + 3, 3, 3, 3, 3, 2, 2 + } ; + +static yyconst flex_uint16_t yy_base[187] = + { 0, + 0, 0, 207, 208, 46, 208, 208, 208, 208, 208, + 208, 193, 37, 208, 208, 208, 208, 208, 0, 208, + 208, 166, 180, 166, 24, 159, 19, 165, 172, 30, + 171, 156, 163, 19, 23, 160, 208, 208, 62, 0, + 181, 56, 49, 0, 168, 152, 156, 151, 150, 161, + 151, 151, 39, 150, 146, 157, 142, 141, 157, 152, + 151, 143, 48, 145, 0, 55, 162, 161, 0, 148, + 132, 146, 145, 134, 125, 142, 126, 128, 135, 131, + 135, 118, 123, 134, 131, 134, 46, 121, 132, 114, + 123, 43, 114, 113, 110, 0, 109, 117, 120, 106, + + 114, 111, 107, 101, 114, 114, 113, 0, 103, 98, + 101, 91, 0, 99, 97, 101, 104, 91, 98, 105, + 102, 96, 90, 0, 86, 83, 83, 0, 77, 91, + 88, 89, 0, 76, 83, 78, 74, 0, 77, 79, + 71, 0, 81, 77, 0, 0, 0, 0, 68, 66, + 70, 72, 64, 76, 67, 0, 70, 0, 0, 69, + 66, 57, 70, 65, 0, 0, 59, 58, 70, 53, + 65, 54, 54, 53, 49, 0, 0, 51, 0, 41, + 0, 0, 0, 208, 70, 83 + } ; + +static yyconst flex_int16_t yy_def[187] = + { 0, + 184, 1, 184, 184, 184, 184, 184, 184, 184, 184, + 184, 184, 184, 184, 184, 184, 184, 184, 185, 184, + 184, 185, 185, 185, 185, 185, 185, 185, 185, 185, + 185, 185, 185, 185, 185, 185, 184, 184, 184, 186, + 184, 184, 184, 185, 185, 185, 185, 185, 185, 185, + 185, 185, 185, 185, 185, 185, 185, 185, 185, 185, + 185, 185, 185, 185, 186, 184, 184, 184, 185, 185, + 185, 185, 185, 185, 185, 185, 185, 185, 185, 185, + 185, 185, 185, 185, 185, 185, 185, 185, 185, 185, + 185, 185, 185, 185, 185, 185, 185, 185, 185, 185, + + 185, 185, 185, 185, 185, 185, 185, 185, 185, 185, + 185, 185, 185, 185, 185, 185, 185, 185, 185, 185, + 185, 185, 185, 185, 185, 185, 185, 185, 185, 185, + 185, 185, 185, 185, 185, 185, 185, 185, 185, 185, + 185, 185, 185, 185, 185, 185, 185, 185, 185, 185, + 185, 185, 185, 185, 185, 185, 185, 185, 185, 185, + 185, 185, 185, 185, 185, 185, 185, 185, 185, 185, + 185, 185, 185, 185, 185, 185, 185, 185, 185, 185, + 185, 185, 185, 0, 184, 184 + } ; + +static yyconst flex_uint16_t yy_nxt[256] = + { 0, + 4, 5, 6, 5, 4, 7, 8, 9, 10, 4, + 11, 4, 12, 13, 14, 15, 16, 17, 18, 19, + 19, 20, 21, 22, 23, 24, 25, 26, 27, 19, + 19, 28, 19, 29, 30, 31, 32, 33, 19, 34, + 35, 36, 19, 19, 19, 37, 38, 39, 41, 39, + 42, 48, 51, 55, 62, 49, 60, 43, 67, 61, + 52, 63, 68, 39, 43, 39, 56, 41, 66, 42, + 77, 88, 44, 108, 114, 43, 43, 109, 78, 89, + 183, 115, 43, 43, 65, 65, 182, 181, 180, 179, + 178, 177, 176, 175, 174, 173, 172, 171, 170, 169, + + 168, 167, 166, 165, 164, 163, 162, 161, 160, 159, + 158, 157, 156, 155, 154, 153, 152, 151, 150, 149, + 148, 147, 146, 145, 144, 143, 142, 141, 140, 139, + 138, 137, 136, 135, 134, 133, 132, 131, 130, 129, + 128, 127, 126, 125, 124, 123, 122, 121, 120, 119, + 118, 117, 116, 113, 112, 111, 110, 107, 106, 105, + 104, 103, 102, 101, 100, 99, 98, 97, 96, 95, + 94, 93, 92, 91, 68, 68, 90, 87, 86, 85, + 84, 83, 82, 81, 80, 79, 76, 75, 74, 73, + 72, 71, 70, 69, 66, 64, 59, 58, 57, 54, + + 53, 50, 47, 46, 45, 40, 184, 3, 184, 184, + 184, 184, 184, 184, 184, 184, 184, 184, 184, 184, + 184, 184, 184, 184, 184, 184, 184, 184, 184, 184, + 184, 184, 184, 184, 184, 184, 184, 184, 184, 184, + 184, 184, 184, 184, 184, 184, 184, 184, 184, 184, + 184, 184, 184, 184, 184 + } ; + +static yyconst flex_int16_t yy_chk[256] = + { 0, + 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, + 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, + 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, + 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, + 1, 1, 1, 1, 1, 1, 1, 5, 13, 5, + 13, 25, 27, 30, 35, 25, 34, 13, 43, 34, + 27, 35, 43, 39, 13, 39, 30, 42, 66, 42, + 53, 63, 185, 87, 92, 66, 42, 87, 53, 63, + 180, 92, 66, 42, 186, 186, 178, 175, 174, 173, + 172, 171, 170, 169, 168, 167, 164, 163, 162, 161, + + 160, 157, 155, 154, 153, 152, 151, 150, 149, 144, + 143, 141, 140, 139, 137, 136, 135, 134, 132, 131, + 130, 129, 127, 126, 125, 123, 122, 121, 120, 119, + 118, 117, 116, 115, 114, 112, 111, 110, 109, 107, + 106, 105, 104, 103, 102, 101, 100, 99, 98, 97, + 95, 94, 93, 91, 90, 89, 88, 86, 85, 84, + 83, 82, 81, 80, 79, 78, 77, 76, 75, 74, + 73, 72, 71, 70, 68, 67, 64, 62, 61, 60, + 59, 58, 57, 56, 55, 54, 52, 51, 50, 49, + 48, 47, 46, 45, 41, 36, 33, 32, 31, 29, + + 28, 26, 24, 23, 22, 12, 3, 184, 184, 184, + 184, 184, 184, 184, 184, 184, 184, 184, 184, 184, + 184, 184, 184, 184, 184, 184, 184, 184, 184, 184, + 184, 184, 184, 184, 184, 184, 184, 184, 184, 184, + 184, 184, 184, 184, 184, 184, 184, 184, 184, 184, + 184, 184, 184, 184, 184 + } ; + +static yy_state_type yy_last_accepting_state; +static char *yy_last_accepting_cpos; + +extern int yy_flex_debug; +int yy_flex_debug = 0; + +/* The intent behind this definition is that it'll catch + * any uses of REJECT which flex missed. + */ +#define REJECT reject_used_but_not_detected +#define yymore() yymore_used_but_not_detected +#define YY_MORE_ADJ 0 +#define YY_RESTORE_YY_MORE_OFFSET +char *yytext; +#line 1 "tokens.l" +#line 2 "tokens.l" +//====================================================================================// +// // +// Lexical Analyzer // +// // +//====================================================================================// +// This File: tokens.l Tool: lex // +// Software: SIMULEAU // +// Doc: // +//====================================================================================// +// Creation: 15/Apr/16 by: Leonardo.Brenner@lsis.org // +// Last Change: 15/Apr/16 by: Leonardo.Brenner@lsis.org // +//====================================================================================// +// This file has the definitions of the tokens that must to be recognized by the // +// grammar contained in the "glc.y" file. These definitions are used by LEX tool, // +// which is a generator of lexical parsers. // +// The lexical analyzer (scanner) is a function that reads an input stream and // +// returns the correspondents tokens. // +//====================================================================================// +#include "bpnfile.h" + +extern int yynerrs; // Variable of the YACC generator to count the number of errors. +extern int yylineno; + +//====================================================================================// +// Below are defined the R.E.(Regular Expressions) that defines the format of the // +// digits (symbols between 0 and 9, inclusively), integers, reals, exponents and // +// identifies. The symbol "+" indicate one or more occurrences, the symbol "*" // +// indicate zero or more occurrences and the symbol "?" indicate that the occurrence // +// is optional. // +//====================================================================================// + +#line 613 "lex.yy.cpp" + +#define INITIAL 0 + +#ifndef YY_NO_UNISTD_H +/* Special case for "unistd.h", since it is non-ANSI. We include it way + * down here because we want the user's section 1 to have been scanned first. + * The user has a chance to override it with an option. + */ +#include <unistd.h> +#endif + +#ifndef YY_EXTRA_TYPE +#define YY_EXTRA_TYPE void * +#endif + +static int yy_init_globals (void ); + +/* Accessor methods to globals. + These are made visible to non-reentrant scanners for convenience. */ + +int yylex_destroy (void ); + +int yyget_debug (void ); + +void yyset_debug (int debug_flag ); + +YY_EXTRA_TYPE yyget_extra (void ); + +void yyset_extra (YY_EXTRA_TYPE user_defined ); + +FILE *yyget_in (void ); + +void yyset_in (FILE * _in_str ); + +FILE *yyget_out (void ); + +void yyset_out (FILE * _out_str ); + +yy_size_t yyget_leng (void ); + +char *yyget_text (void ); + +int yyget_lineno (void ); + +void yyset_lineno (int _line_number ); + +/* Macros after this point can all be overridden by user definitions in + * section 1. + */ + +#ifndef YY_SKIP_YYWRAP +#ifdef __cplusplus +extern "C" int yywrap (void ); +#else +extern int yywrap (void ); +#endif +#endif + +#ifndef YY_NO_UNPUT + + static void yyunput (int c,char *buf_ptr ); + +#endif + +#ifndef yytext_ptr +static void yy_flex_strncpy (char *,yyconst char *,int ); +#endif + +#ifdef YY_NEED_STRLEN +static int yy_flex_strlen (yyconst char * ); +#endif + +#ifndef YY_NO_INPUT + +#ifdef __cplusplus +static int yyinput (void ); +#else +static int input (void ); +#endif + +#endif + +/* Amount of stuff to slurp up with each read. */ +#ifndef YY_READ_BUF_SIZE +#ifdef __ia64__ +/* On IA-64, the buffer size is 16k, not 8k */ +#define YY_READ_BUF_SIZE 16384 +#else +#define YY_READ_BUF_SIZE 8192 +#endif /* __ia64__ */ +#endif + +/* Copy whatever the last rule matched to the standard output. */ +#ifndef ECHO +/* This used to be an fputs(), but since the string might contain NUL's, + * we now use fwrite(). + */ +#define ECHO do { if (fwrite( yytext, yyleng, 1, yyout )) {} } while (0) +#endif + +/* Gets input and stuffs it into "buf". number of characters read, or YY_NULL, + * is returned in "result". + */ +#ifndef YY_INPUT +#define YY_INPUT(buf,result,max_size) \ + if ( YY_CURRENT_BUFFER_LVALUE->yy_is_interactive ) \ + { \ + int c = '*'; \ + size_t n; \ + for ( n = 0; n < max_size && \ + (c = getc( yyin )) != EOF && c != '\n'; ++n ) \ + buf[n] = (char) c; \ + if ( c == '\n' ) \ + buf[n++] = (char) c; \ + if ( c == EOF && ferror( yyin ) ) \ + YY_FATAL_ERROR( "input in flex scanner failed" ); \ + result = n; \ + } \ + else \ + { \ + errno=0; \ + while ( (result = fread(buf, 1, max_size, yyin))==0 && ferror(yyin)) \ + { \ + if( errno != EINTR) \ + { \ + YY_FATAL_ERROR( "input in flex scanner failed" ); \ + break; \ + } \ + errno=0; \ + clearerr(yyin); \ + } \ + }\ +\ + +#endif + +/* No semi-colon after return; correct usage is to write "yyterminate();" - + * we don't want an extra ';' after the "return" because that will cause + * some compilers to complain about unreachable statements. + */ +#ifndef yyterminate +#define yyterminate() return YY_NULL +#endif + +/* Number of entries by which start-condition stack grows. */ +#ifndef YY_START_STACK_INCR +#define YY_START_STACK_INCR 25 +#endif + +/* Report a fatal error. */ +#ifndef YY_FATAL_ERROR +#define YY_FATAL_ERROR(msg) yy_fatal_error( msg ) +#endif + +/* end tables serialization structures and prototypes */ + +/* Default declaration of generated scanner - a define so the user can + * easily add parameters. + */ +#ifndef YY_DECL +#define YY_DECL_IS_OURS 1 + +extern int yylex (void); + +#define YY_DECL int yylex (void) +#endif /* !YY_DECL */ + +/* Code executed at the beginning of each rule, after yytext and yyleng + * have been set up. + */ +#ifndef YY_USER_ACTION +#define YY_USER_ACTION +#endif + +/* Code executed at the end of each rule. */ +#ifndef YY_BREAK +#define YY_BREAK /*LINTED*/break; +#endif + +#define YY_RULE_SETUP \ + YY_USER_ACTION + +/** The main scanner function which does all the work. + */ +YY_DECL +{ + yy_state_type yy_current_state; + char *yy_cp, *yy_bp; + int yy_act; + + if ( !(yy_init) ) + { + (yy_init) = 1; + +#ifdef YY_USER_INIT + YY_USER_INIT; +#endif + + if ( ! (yy_start) ) + (yy_start) = 1; /* first start state */ + + if ( ! yyin ) + yyin = stdin; + + if ( ! yyout ) + yyout = stdout; + + if ( ! YY_CURRENT_BUFFER ) { + yyensure_buffer_stack (); + YY_CURRENT_BUFFER_LVALUE = + yy_create_buffer(yyin,YY_BUF_SIZE ); + } + + yy_load_buffer_state( ); + } + + { +#line 41 "tokens.l" + + +#line 834 "lex.yy.cpp" + + while ( /*CONSTCOND*/1 ) /* loops until end-of-file is reached */ + { + yy_cp = (yy_c_buf_p); + + /* Support of yytext. */ + *yy_cp = (yy_hold_char); + + /* yy_bp points to the position in yy_ch_buf of the start of + * the current run. + */ + yy_bp = yy_cp; + + yy_current_state = (yy_start); +yy_match: + do + { + YY_CHAR yy_c = yy_ec[YY_SC_TO_UI(*yy_cp)] ; + if ( yy_accept[yy_current_state] ) + { + (yy_last_accepting_state) = yy_current_state; + (yy_last_accepting_cpos) = yy_cp; + } + while ( yy_chk[yy_base[yy_current_state] + yy_c] != yy_current_state ) + { + yy_current_state = (int) yy_def[yy_current_state]; + if ( yy_current_state >= 185 ) + yy_c = yy_meta[(unsigned int) yy_c]; + } + yy_current_state = yy_nxt[yy_base[yy_current_state] + (unsigned int) yy_c]; + ++yy_cp; + } + while ( yy_base[yy_current_state] != 208 ); + +yy_find_action: + yy_act = yy_accept[yy_current_state]; + if ( yy_act == 0 ) + { /* have to back up */ + yy_cp = (yy_last_accepting_cpos); + yy_current_state = (yy_last_accepting_state); + yy_act = yy_accept[yy_current_state]; + } + + YY_DO_BEFORE_ACTION; + +do_action: /* This label is used only to access EOF actions. */ + + switch ( yy_act ) + { /* beginning of action switch */ + case 0: /* must back up */ + /* undo the effects of YY_DO_BEFORE_ACTION */ + *yy_cp = (yy_hold_char); + yy_cp = (yy_last_accepting_cpos); + yy_current_state = (yy_last_accepting_state); + goto yy_find_action; + +case 1: +YY_RULE_SETUP +#line 43 "tokens.l" + + YY_BREAK +case 2: +YY_RULE_SETUP +#line 44 "tokens.l" +{return(TK_ARC);} + YY_BREAK +case 3: +YY_RULE_SETUP +#line 45 "tokens.l" +{return(TK_BATCH);} + YY_BREAK +case 4: +YY_RULE_SETUP +#line 46 "tokens.l" +{return(TK_CONTINUOUS);} + YY_BREAK +case 5: +YY_RULE_SETUP +#line 47 "tokens.l" +{return(TK_CONTROLLED);} + YY_BREAK +case 6: +YY_RULE_SETUP +#line 48 "tokens.l" +{return(TK_DESCRIPTION);} + YY_BREAK +case 7: +YY_RULE_SETUP +#line 49 "tokens.l" +{return(TK_DISCRETE);} + YY_BREAK +case 8: +YY_RULE_SETUP +#line 50 "tokens.l" +{return(TK_EVENTS);} + YY_BREAK +case 9: +YY_RULE_SETUP +#line 51 "tokens.l" +{return(TK_FLOW);} + YY_BREAK +case 10: +YY_RULE_SETUP +#line 52 "tokens.l" +{return(TK_FUNCTION);} + YY_BREAK +case 11: +YY_RULE_SETUP +#line 53 "tokens.l" +{return(TK_INITIAL);} + YY_BREAK +case 12: +YY_RULE_SETUP +#line 54 "tokens.l" +{return(TK_INSPECTION);} + YY_BREAK +case 13: +YY_RULE_SETUP +#line 55 "tokens.l" +{return(TK_LENGTH);} + YY_BREAK +case 14: +YY_RULE_SETUP +#line 56 "tokens.l" +{return(TK_MARKING);} + YY_BREAK +case 15: +YY_RULE_SETUP +#line 57 "tokens.l" +{return(TK_MODEL);} + YY_BREAK +case 16: +YY_RULE_SETUP +#line 58 "tokens.l" +{return(TK_NETWORK);} + YY_BREAK +case 17: +YY_RULE_SETUP +#line 59 "tokens.l" +{return(TK_OUTPUT);} + YY_BREAK +case 18: +YY_RULE_SETUP +#line 60 "tokens.l" +{return(TK_PLACE);} + YY_BREAK +case 19: +YY_RULE_SETUP +#line 61 "tokens.l" +{return(TK_PLACES);} + YY_BREAK +case 20: +YY_RULE_SETUP +#line 62 "tokens.l" +{return(TK_SPEED);} + YY_BREAK +case 21: +YY_RULE_SETUP +#line 63 "tokens.l" +{return(TK_STEADY);} + YY_BREAK +case 22: +YY_RULE_SETUP +#line 64 "tokens.l" +{return(TK_TIME);} + YY_BREAK +case 23: +YY_RULE_SETUP +#line 65 "tokens.l" +{return(TK_TIMING);} + YY_BREAK +case 24: +YY_RULE_SETUP +#line 66 "tokens.l" +{return(TK_TRANSITION);} + YY_BREAK +case 25: +YY_RULE_SETUP +#line 67 "tokens.l" +{return(TK_TRANSITIONS);} + YY_BREAK +case 26: +YY_RULE_SETUP +#line 68 "tokens.l" +{return(TK_TRIANGULAR);} + YY_BREAK +case 27: +YY_RULE_SETUP +#line 69 "tokens.l" +{return(TK_UNITY);} + YY_BREAK +case 28: +YY_RULE_SETUP +#line 70 "tokens.l" +{return(TK_ID);} + YY_BREAK +case 29: +YY_RULE_SETUP +#line 71 "tokens.l" +{return(TK_INTEGER);} + YY_BREAK +case 30: +YY_RULE_SETUP +#line 72 "tokens.l" +{return(TK_REAL);} + YY_BREAK +case 31: +YY_RULE_SETUP +#line 73 "tokens.l" +{return(TK_EXPONENT);} + YY_BREAK +case 32: +YY_RULE_SETUP +#line 74 "tokens.l" +{return(TK_AT);} + YY_BREAK +case 33: +YY_RULE_SETUP +#line 75 "tokens.l" +{return(TK_EVERY);} + YY_BREAK +case 34: +YY_RULE_SETUP +#line 76 "tokens.l" +{return(TK_PL_TR);} + YY_BREAK +case 35: +YY_RULE_SETUP +#line 77 "tokens.l" +{return(TK_ALL);} + YY_BREAK +case 36: +YY_RULE_SETUP +#line 78 "tokens.l" +{return(TK_LEFT_BRACKET);} + YY_BREAK +case 37: +YY_RULE_SETUP +#line 79 "tokens.l" +{return(TK_RIGHT_BRACKET);} + YY_BREAK +case 38: +YY_RULE_SETUP +#line 80 "tokens.l" +{return(TK_LEFT_PARENTHESIS);} + YY_BREAK +case 39: +YY_RULE_SETUP +#line 81 "tokens.l" +{return(TK_RIGHT_PARENTHESIS);} + YY_BREAK +case 40: +YY_RULE_SETUP +#line 82 "tokens.l" +{return(TK_LEFT_SQUARE_BRACKET);} + YY_BREAK +case 41: +YY_RULE_SETUP +#line 83 "tokens.l" +{return(TK_RIGHT_SQUARE_BRACKET);} + YY_BREAK +case 42: +YY_RULE_SETUP +#line 84 "tokens.l" +{return(TK_SEMICOLON);} + YY_BREAK +case 43: +YY_RULE_SETUP +#line 85 "tokens.l" +{return(TK_COMMA);} + YY_BREAK +case 44: +YY_RULE_SETUP +#line 86 "tokens.l" +{return(TK_ATTRIB);} + YY_BREAK +case 45: +YY_RULE_SETUP +#line 87 "tokens.l" +{return(TK_COLON);} + YY_BREAK +case 46: +YY_RULE_SETUP +#line 88 "tokens.l" +{/* Ignore the blanks, tabulates and new line */} + YY_BREAK +case 47: +/* rule 47 can match eol */ +YY_RULE_SETUP +#line 89 "tokens.l" +{yylineno++;} + YY_BREAK +case 48: +YY_RULE_SETUP +#line 90 "tokens.l" +{ /* If neither token return, means that the input + stream has a lexical error */ + yynerrs++; + Lexical_Error(yynerrs, yylineno, yytext);} + YY_BREAK +case 49: +YY_RULE_SETUP +#line 94 "tokens.l" +ECHO; + YY_BREAK +#line 1140 "lex.yy.cpp" +case YY_STATE_EOF(INITIAL): + yyterminate(); + + case YY_END_OF_BUFFER: + { + /* Amount of text matched not including the EOB char. */ + int yy_amount_of_matched_text = (int) (yy_cp - (yytext_ptr)) - 1; + + /* Undo the effects of YY_DO_BEFORE_ACTION. */ + *yy_cp = (yy_hold_char); + YY_RESTORE_YY_MORE_OFFSET + + if ( YY_CURRENT_BUFFER_LVALUE->yy_buffer_status == YY_BUFFER_NEW ) + { + /* We're scanning a new file or input source. It's + * possible that this happened because the user + * just pointed yyin at a new source and called + * yylex(). If so, then we have to assure + * consistency between YY_CURRENT_BUFFER and our + * globals. Here is the right place to do so, because + * this is the first action (other than possibly a + * back-up) that will match for the new input source. + */ + (yy_n_chars) = YY_CURRENT_BUFFER_LVALUE->yy_n_chars; + YY_CURRENT_BUFFER_LVALUE->yy_input_file = yyin; + YY_CURRENT_BUFFER_LVALUE->yy_buffer_status = YY_BUFFER_NORMAL; + } + + /* Note that here we test for yy_c_buf_p "<=" to the position + * of the first EOB in the buffer, since yy_c_buf_p will + * already have been incremented past the NUL character + * (since all states make transitions on EOB to the + * end-of-buffer state). Contrast this with the test + * in input(). + */ + if ( (yy_c_buf_p) <= &YY_CURRENT_BUFFER_LVALUE->yy_ch_buf[(yy_n_chars)] ) + { /* This was really a NUL. */ + yy_state_type yy_next_state; + + (yy_c_buf_p) = (yytext_ptr) + yy_amount_of_matched_text; + + yy_current_state = yy_get_previous_state( ); + + /* Okay, we're now positioned to make the NUL + * transition. We couldn't have + * yy_get_previous_state() go ahead and do it + * for us because it doesn't know how to deal + * with the possibility of jamming (and we don't + * want to build jamming into it because then it + * will run more slowly). + */ + + yy_next_state = yy_try_NUL_trans( yy_current_state ); + + yy_bp = (yytext_ptr) + YY_MORE_ADJ; + + if ( yy_next_state ) + { + /* Consume the NUL. */ + yy_cp = ++(yy_c_buf_p); + yy_current_state = yy_next_state; + goto yy_match; + } + + else + { + yy_cp = (yy_c_buf_p); + goto yy_find_action; + } + } + + else switch ( yy_get_next_buffer( ) ) + { + case EOB_ACT_END_OF_FILE: + { + (yy_did_buffer_switch_on_eof) = 0; + + if ( yywrap( ) ) + { + /* Note: because we've taken care in + * yy_get_next_buffer() to have set up + * yytext, we can now set up + * yy_c_buf_p so that if some total + * hoser (like flex itself) wants to + * call the scanner after we return the + * YY_NULL, it'll still work - another + * YY_NULL will get returned. + */ + (yy_c_buf_p) = (yytext_ptr) + YY_MORE_ADJ; + + yy_act = YY_STATE_EOF(YY_START); + goto do_action; + } + + else + { + if ( ! (yy_did_buffer_switch_on_eof) ) + YY_NEW_FILE; + } + break; + } + + case EOB_ACT_CONTINUE_SCAN: + (yy_c_buf_p) = + (yytext_ptr) + yy_amount_of_matched_text; + + yy_current_state = yy_get_previous_state( ); + + yy_cp = (yy_c_buf_p); + yy_bp = (yytext_ptr) + YY_MORE_ADJ; + goto yy_match; + + case EOB_ACT_LAST_MATCH: + (yy_c_buf_p) = + &YY_CURRENT_BUFFER_LVALUE->yy_ch_buf[(yy_n_chars)]; + + yy_current_state = yy_get_previous_state( ); + + yy_cp = (yy_c_buf_p); + yy_bp = (yytext_ptr) + YY_MORE_ADJ; + goto yy_find_action; + } + break; + } + + default: + YY_FATAL_ERROR( + "fatal flex scanner internal error--no action found" ); + } /* end of action switch */ + } /* end of scanning one token */ + } /* end of user's declarations */ +} /* end of yylex */ + +/* yy_get_next_buffer - try to read in a new buffer + * + * Returns a code representing an action: + * EOB_ACT_LAST_MATCH - + * EOB_ACT_CONTINUE_SCAN - continue scanning from current position + * EOB_ACT_END_OF_FILE - end of file + */ +static int yy_get_next_buffer (void) +{ + char *dest = YY_CURRENT_BUFFER_LVALUE->yy_ch_buf; + char *source = (yytext_ptr); + yy_size_t number_to_move, i; + int ret_val; + + if ( (yy_c_buf_p) > &YY_CURRENT_BUFFER_LVALUE->yy_ch_buf[(yy_n_chars) + 1] ) + YY_FATAL_ERROR( + "fatal flex scanner internal error--end of buffer missed" ); + + if ( YY_CURRENT_BUFFER_LVALUE->yy_fill_buffer == 0 ) + { /* Don't try to fill the buffer, so this is an EOF. */ + if ( (yy_c_buf_p) - (yytext_ptr) - YY_MORE_ADJ == 1 ) + { + /* We matched a single character, the EOB, so + * treat this as a final EOF. + */ + return EOB_ACT_END_OF_FILE; + } + + else + { + /* We matched some text prior to the EOB, first + * process it. + */ + return EOB_ACT_LAST_MATCH; + } + } + + /* Try to read more data. */ + + /* First move last chars to start of buffer. */ + number_to_move = (yy_size_t) ((yy_c_buf_p) - (yytext_ptr)) - 1; + + for ( i = 0; i < number_to_move; ++i ) + *(dest++) = *(source++); + + if ( YY_CURRENT_BUFFER_LVALUE->yy_buffer_status == YY_BUFFER_EOF_PENDING ) + /* don't do the read, it's not guaranteed to return an EOF, + * just force an EOF + */ + YY_CURRENT_BUFFER_LVALUE->yy_n_chars = (yy_n_chars) = 0; + + else + { + yy_size_t num_to_read = + YY_CURRENT_BUFFER_LVALUE->yy_buf_size - number_to_move - 1; + + while ( num_to_read <= 0 ) + { /* Not enough room in the buffer - grow it. */ + + /* just a shorter name for the current buffer */ + YY_BUFFER_STATE b = YY_CURRENT_BUFFER_LVALUE; + + int yy_c_buf_p_offset = + (int) ((yy_c_buf_p) - b->yy_ch_buf); + + if ( b->yy_is_our_buffer ) + { + yy_size_t new_size = b->yy_buf_size * 2; + + if ( new_size <= 0 ) + b->yy_buf_size += b->yy_buf_size / 8; + else + b->yy_buf_size *= 2; + + b->yy_ch_buf = (char *) + /* Include room in for 2 EOB chars. */ + yyrealloc((void *) b->yy_ch_buf,b->yy_buf_size + 2 ); + } + else + /* Can't grow it, we don't own it. */ + b->yy_ch_buf = 0; + + if ( ! b->yy_ch_buf ) + YY_FATAL_ERROR( + "fatal error - scanner input buffer overflow" ); + + (yy_c_buf_p) = &b->yy_ch_buf[yy_c_buf_p_offset]; + + num_to_read = YY_CURRENT_BUFFER_LVALUE->yy_buf_size - + number_to_move - 1; + + } + + if ( num_to_read > YY_READ_BUF_SIZE ) + num_to_read = YY_READ_BUF_SIZE; + + /* Read in more data. */ + YY_INPUT( (&YY_CURRENT_BUFFER_LVALUE->yy_ch_buf[number_to_move]), + (yy_n_chars), num_to_read ); + + YY_CURRENT_BUFFER_LVALUE->yy_n_chars = (yy_n_chars); + } + + if ( (yy_n_chars) == 0 ) + { + if ( number_to_move == YY_MORE_ADJ ) + { + ret_val = EOB_ACT_END_OF_FILE; + yyrestart(yyin ); + } + + else + { + ret_val = EOB_ACT_LAST_MATCH; + YY_CURRENT_BUFFER_LVALUE->yy_buffer_status = + YY_BUFFER_EOF_PENDING; + } + } + + else + ret_val = EOB_ACT_CONTINUE_SCAN; + + if ((int) ((yy_n_chars) + number_to_move) > YY_CURRENT_BUFFER_LVALUE->yy_buf_size) { + /* Extend the array by 50%, plus the number we really need. */ + int new_size = (yy_n_chars) + number_to_move + ((yy_n_chars) >> 1); + YY_CURRENT_BUFFER_LVALUE->yy_ch_buf = (char *) yyrealloc((void *) YY_CURRENT_BUFFER_LVALUE->yy_ch_buf,new_size ); + if ( ! YY_CURRENT_BUFFER_LVALUE->yy_ch_buf ) + YY_FATAL_ERROR( "out of dynamic memory in yy_get_next_buffer()" ); + } + + (yy_n_chars) += number_to_move; + YY_CURRENT_BUFFER_LVALUE->yy_ch_buf[(yy_n_chars)] = YY_END_OF_BUFFER_CHAR; + YY_CURRENT_BUFFER_LVALUE->yy_ch_buf[(yy_n_chars) + 1] = YY_END_OF_BUFFER_CHAR; + + (yytext_ptr) = &YY_CURRENT_BUFFER_LVALUE->yy_ch_buf[0]; + + return ret_val; +} + +/* yy_get_previous_state - get the state just before the EOB char was reached */ + + static yy_state_type yy_get_previous_state (void) +{ + yy_state_type yy_current_state; + char *yy_cp; + + yy_current_state = (yy_start); + + for ( yy_cp = (yytext_ptr) + YY_MORE_ADJ; yy_cp < (yy_c_buf_p); ++yy_cp ) + { + YY_CHAR yy_c = (*yy_cp ? yy_ec[YY_SC_TO_UI(*yy_cp)] : 1); + if ( yy_accept[yy_current_state] ) + { + (yy_last_accepting_state) = yy_current_state; + (yy_last_accepting_cpos) = yy_cp; + } + while ( yy_chk[yy_base[yy_current_state] + yy_c] != yy_current_state ) + { + yy_current_state = (int) yy_def[yy_current_state]; + if ( yy_current_state >= 185 ) + yy_c = yy_meta[(unsigned int) yy_c]; + } + yy_current_state = yy_nxt[yy_base[yy_current_state] + (unsigned int) yy_c]; + } + + return yy_current_state; +} + +/* yy_try_NUL_trans - try to make a transition on the NUL character + * + * synopsis + * next_state = yy_try_NUL_trans( current_state ); + */ + static yy_state_type yy_try_NUL_trans (yy_state_type yy_current_state ) +{ + int yy_is_jam; + char *yy_cp = (yy_c_buf_p); + + YY_CHAR yy_c = 1; + if ( yy_accept[yy_current_state] ) + { + (yy_last_accepting_state) = yy_current_state; + (yy_last_accepting_cpos) = yy_cp; + } + while ( yy_chk[yy_base[yy_current_state] + yy_c] != yy_current_state ) + { + yy_current_state = (int) yy_def[yy_current_state]; + if ( yy_current_state >= 185 ) + yy_c = yy_meta[(unsigned int) yy_c]; + } + yy_current_state = yy_nxt[yy_base[yy_current_state] + (unsigned int) yy_c]; + yy_is_jam = (yy_current_state == 184); + + return yy_is_jam ? 0 : yy_current_state; +} + +#ifndef YY_NO_UNPUT + + static void yyunput (int c, char * yy_bp ) +{ + char *yy_cp; + + yy_cp = (yy_c_buf_p); + + /* undo effects of setting up yytext */ + *yy_cp = (yy_hold_char); + + if ( yy_cp < YY_CURRENT_BUFFER_LVALUE->yy_ch_buf + 2 ) + { /* need to shift things up to make room */ + /* +2 for EOB chars. */ + yy_size_t number_to_move = (yy_n_chars) + 2; + char *dest = &YY_CURRENT_BUFFER_LVALUE->yy_ch_buf[ + YY_CURRENT_BUFFER_LVALUE->yy_buf_size + 2]; + char *source = + &YY_CURRENT_BUFFER_LVALUE->yy_ch_buf[number_to_move]; + + while ( source > YY_CURRENT_BUFFER_LVALUE->yy_ch_buf ) + *--dest = *--source; + + yy_cp += (int) (dest - source); + yy_bp += (int) (dest - source); + YY_CURRENT_BUFFER_LVALUE->yy_n_chars = + (yy_n_chars) = YY_CURRENT_BUFFER_LVALUE->yy_buf_size; + + if ( yy_cp < YY_CURRENT_BUFFER_LVALUE->yy_ch_buf + 2 ) + YY_FATAL_ERROR( "flex scanner push-back overflow" ); + } + + *--yy_cp = (char) c; + + (yytext_ptr) = yy_bp; + (yy_hold_char) = *yy_cp; + (yy_c_buf_p) = yy_cp; +} + +#endif + +#ifndef YY_NO_INPUT +#ifdef __cplusplus + static int yyinput (void) +#else + static int input (void) +#endif + +{ + int c; + + *(yy_c_buf_p) = (yy_hold_char); + + if ( *(yy_c_buf_p) == YY_END_OF_BUFFER_CHAR ) + { + /* yy_c_buf_p now points to the character we want to return. + * If this occurs *before* the EOB characters, then it's a + * valid NUL; if not, then we've hit the end of the buffer. + */ + if ( (yy_c_buf_p) < &YY_CURRENT_BUFFER_LVALUE->yy_ch_buf[(yy_n_chars)] ) + /* This was really a NUL. */ + *(yy_c_buf_p) = '\0'; + + else + { /* need more input */ + yy_size_t offset = (yy_c_buf_p) - (yytext_ptr); + ++(yy_c_buf_p); + + switch ( yy_get_next_buffer( ) ) + { + case EOB_ACT_LAST_MATCH: + /* This happens because yy_g_n_b() + * sees that we've accumulated a + * token and flags that we need to + * try matching the token before + * proceeding. But for input(), + * there's no matching to consider. + * So convert the EOB_ACT_LAST_MATCH + * to EOB_ACT_END_OF_FILE. + */ + + /* Reset buffer status. */ + yyrestart(yyin ); + + /*FALLTHROUGH*/ + + case EOB_ACT_END_OF_FILE: + { + if ( yywrap( ) ) + return EOF; + + if ( ! (yy_did_buffer_switch_on_eof) ) + YY_NEW_FILE; +#ifdef __cplusplus + return yyinput(); +#else + return input(); +#endif + } + + case EOB_ACT_CONTINUE_SCAN: + (yy_c_buf_p) = (yytext_ptr) + offset; + break; + } + } + } + + c = *(unsigned char *) (yy_c_buf_p); /* cast for 8-bit char's */ + *(yy_c_buf_p) = '\0'; /* preserve yytext */ + (yy_hold_char) = *++(yy_c_buf_p); + + return c; +} +#endif /* ifndef YY_NO_INPUT */ + +/** Immediately switch to a different input stream. + * @param input_file A readable stream. + * + * @note This function does not reset the start condition to @c INITIAL . + */ + void yyrestart (FILE * input_file ) +{ + + if ( ! YY_CURRENT_BUFFER ){ + yyensure_buffer_stack (); + YY_CURRENT_BUFFER_LVALUE = + yy_create_buffer(yyin,YY_BUF_SIZE ); + } + + yy_init_buffer(YY_CURRENT_BUFFER,input_file ); + yy_load_buffer_state( ); +} + +/** Switch to a different input buffer. + * @param new_buffer The new input buffer. + * + */ + void yy_switch_to_buffer (YY_BUFFER_STATE new_buffer ) +{ + + /* TODO. We should be able to replace this entire function body + * with + * yypop_buffer_state(); + * yypush_buffer_state(new_buffer); + */ + yyensure_buffer_stack (); + if ( YY_CURRENT_BUFFER == new_buffer ) + return; + + if ( YY_CURRENT_BUFFER ) + { + /* Flush out information for old buffer. */ + *(yy_c_buf_p) = (yy_hold_char); + YY_CURRENT_BUFFER_LVALUE->yy_buf_pos = (yy_c_buf_p); + YY_CURRENT_BUFFER_LVALUE->yy_n_chars = (yy_n_chars); + } + + YY_CURRENT_BUFFER_LVALUE = new_buffer; + yy_load_buffer_state( ); + + /* We don't actually know whether we did this switch during + * EOF (yywrap()) processing, but the only time this flag + * is looked at is after yywrap() is called, so it's safe + * to go ahead and always set it. + */ + (yy_did_buffer_switch_on_eof) = 1; +} + +static void yy_load_buffer_state (void) +{ + (yy_n_chars) = YY_CURRENT_BUFFER_LVALUE->yy_n_chars; + (yytext_ptr) = (yy_c_buf_p) = YY_CURRENT_BUFFER_LVALUE->yy_buf_pos; + yyin = YY_CURRENT_BUFFER_LVALUE->yy_input_file; + (yy_hold_char) = *(yy_c_buf_p); +} + +/** Allocate and initialize an input buffer state. + * @param file A readable stream. + * @param size The character buffer size in bytes. When in doubt, use @c YY_BUF_SIZE. + * + * @return the allocated buffer state. + */ + YY_BUFFER_STATE yy_create_buffer (FILE * file, int size ) +{ + YY_BUFFER_STATE b; + + b = (YY_BUFFER_STATE) yyalloc(sizeof( struct yy_buffer_state ) ); + if ( ! b ) + YY_FATAL_ERROR( "out of dynamic memory in yy_create_buffer()" ); + + b->yy_buf_size = (yy_size_t)size; + + /* yy_ch_buf has to be 2 characters longer than the size given because + * we need to put in 2 end-of-buffer characters. + */ + b->yy_ch_buf = (char *) yyalloc(b->yy_buf_size + 2 ); + if ( ! b->yy_ch_buf ) + YY_FATAL_ERROR( "out of dynamic memory in yy_create_buffer()" ); + + b->yy_is_our_buffer = 1; + + yy_init_buffer(b,file ); + + return b; +} + +/** Destroy the buffer. + * @param b a buffer created with yy_create_buffer() + * + */ + void yy_delete_buffer (YY_BUFFER_STATE b ) +{ + + if ( ! b ) + return; + + if ( b == YY_CURRENT_BUFFER ) /* Not sure if we should pop here. */ + YY_CURRENT_BUFFER_LVALUE = (YY_BUFFER_STATE) 0; + + if ( b->yy_is_our_buffer ) + yyfree((void *) b->yy_ch_buf ); + + yyfree((void *) b ); +} + +/* Initializes or reinitializes a buffer. + * This function is sometimes called more than once on the same buffer, + * such as during a yyrestart() or at EOF. + */ + static void yy_init_buffer (YY_BUFFER_STATE b, FILE * file ) + +{ + int oerrno = errno; + + yy_flush_buffer(b ); + + b->yy_input_file = file; + b->yy_fill_buffer = 1; + + /* If b is the current buffer, then yy_init_buffer was _probably_ + * called from yyrestart() or through yy_get_next_buffer. + * In that case, we don't want to reset the lineno or column. + */ + if (b != YY_CURRENT_BUFFER){ + b->yy_bs_lineno = 1; + b->yy_bs_column = 0; + } + + b->yy_is_interactive = file ? (isatty( fileno(file) ) > 0) : 0; + + errno = oerrno; +} + +/** Discard all buffered characters. On the next scan, YY_INPUT will be called. + * @param b the buffer state to be flushed, usually @c YY_CURRENT_BUFFER. + * + */ + void yy_flush_buffer (YY_BUFFER_STATE b ) +{ + if ( ! b ) + return; + + b->yy_n_chars = 0; + + /* We always need two end-of-buffer characters. The first causes + * a transition to the end-of-buffer state. The second causes + * a jam in that state. + */ + b->yy_ch_buf[0] = YY_END_OF_BUFFER_CHAR; + b->yy_ch_buf[1] = YY_END_OF_BUFFER_CHAR; + + b->yy_buf_pos = &b->yy_ch_buf[0]; + + b->yy_at_bol = 1; + b->yy_buffer_status = YY_BUFFER_NEW; + + if ( b == YY_CURRENT_BUFFER ) + yy_load_buffer_state( ); +} + +/** Pushes the new state onto the stack. The new state becomes + * the current state. This function will allocate the stack + * if necessary. + * @param new_buffer The new state. + * + */ +void yypush_buffer_state (YY_BUFFER_STATE new_buffer ) +{ + if (new_buffer == NULL) + return; + + yyensure_buffer_stack(); + + /* This block is copied from yy_switch_to_buffer. */ + if ( YY_CURRENT_BUFFER ) + { + /* Flush out information for old buffer. */ + *(yy_c_buf_p) = (yy_hold_char); + YY_CURRENT_BUFFER_LVALUE->yy_buf_pos = (yy_c_buf_p); + YY_CURRENT_BUFFER_LVALUE->yy_n_chars = (yy_n_chars); + } + + /* Only push if top exists. Otherwise, replace top. */ + if (YY_CURRENT_BUFFER) + (yy_buffer_stack_top)++; + YY_CURRENT_BUFFER_LVALUE = new_buffer; + + /* copied from yy_switch_to_buffer. */ + yy_load_buffer_state( ); + (yy_did_buffer_switch_on_eof) = 1; +} + +/** Removes and deletes the top of the stack, if present. + * The next element becomes the new top. + * + */ +void yypop_buffer_state (void) +{ + if (!YY_CURRENT_BUFFER) + return; + + yy_delete_buffer(YY_CURRENT_BUFFER ); + YY_CURRENT_BUFFER_LVALUE = NULL; + if ((yy_buffer_stack_top) > 0) + --(yy_buffer_stack_top); + + if (YY_CURRENT_BUFFER) { + yy_load_buffer_state( ); + (yy_did_buffer_switch_on_eof) = 1; + } +} + +/* Allocates the stack if it does not exist. + * Guarantees space for at least one push. + */ +static void yyensure_buffer_stack (void) +{ + yy_size_t num_to_alloc; + + if (!(yy_buffer_stack)) { + + /* First allocation is just for 2 elements, since we don't know if this + * scanner will even need a stack. We use 2 instead of 1 to avoid an + * immediate realloc on the next call. + */ + num_to_alloc = 1; /* After all that talk, this was set to 1 anyways... */ + (yy_buffer_stack) = (struct yy_buffer_state**)yyalloc + (num_to_alloc * sizeof(struct yy_buffer_state*) + ); + if ( ! (yy_buffer_stack) ) + YY_FATAL_ERROR( "out of dynamic memory in yyensure_buffer_stack()" ); + + memset((yy_buffer_stack), 0, num_to_alloc * sizeof(struct yy_buffer_state*)); + + (yy_buffer_stack_max) = num_to_alloc; + (yy_buffer_stack_top) = 0; + return; + } + + if ((yy_buffer_stack_top) >= ((yy_buffer_stack_max)) - 1){ + + /* Increase the buffer to prepare for a possible push. */ + yy_size_t grow_size = 8 /* arbitrary grow size */; + + num_to_alloc = (yy_buffer_stack_max) + grow_size; + (yy_buffer_stack) = (struct yy_buffer_state**)yyrealloc + ((yy_buffer_stack), + num_to_alloc * sizeof(struct yy_buffer_state*) + ); + if ( ! (yy_buffer_stack) ) + YY_FATAL_ERROR( "out of dynamic memory in yyensure_buffer_stack()" ); + + /* zero only the new slots.*/ + memset((yy_buffer_stack) + (yy_buffer_stack_max), 0, grow_size * sizeof(struct yy_buffer_state*)); + (yy_buffer_stack_max) = num_to_alloc; + } +} + +/** Setup the input buffer state to scan directly from a user-specified character buffer. + * @param base the character buffer + * @param size the size in bytes of the character buffer + * + * @return the newly allocated buffer state object. + */ +YY_BUFFER_STATE yy_scan_buffer (char * base, yy_size_t size ) +{ + YY_BUFFER_STATE b; + + if ( size < 2 || + base[size-2] != YY_END_OF_BUFFER_CHAR || + base[size-1] != YY_END_OF_BUFFER_CHAR ) + /* They forgot to leave room for the EOB's. */ + return 0; + + b = (YY_BUFFER_STATE) yyalloc(sizeof( struct yy_buffer_state ) ); + if ( ! b ) + YY_FATAL_ERROR( "out of dynamic memory in yy_scan_buffer()" ); + + b->yy_buf_size = size - 2; /* "- 2" to take care of EOB's */ + b->yy_buf_pos = b->yy_ch_buf = base; + b->yy_is_our_buffer = 0; + b->yy_input_file = 0; + b->yy_n_chars = b->yy_buf_size; + b->yy_is_interactive = 0; + b->yy_at_bol = 1; + b->yy_fill_buffer = 0; + b->yy_buffer_status = YY_BUFFER_NEW; + + yy_switch_to_buffer(b ); + + return b; +} + +/** Setup the input buffer state to scan a string. The next call to yylex() will + * scan from a @e copy of @a str. + * @param yystr a NUL-terminated string to scan + * + * @return the newly allocated buffer state object. + * @note If you want to scan bytes that may contain NUL values, then use + * yy_scan_bytes() instead. + */ +YY_BUFFER_STATE yy_scan_string (yyconst char * yystr ) +{ + + return yy_scan_bytes(yystr,strlen(yystr) ); +} + +/** Setup the input buffer state to scan the given bytes. The next call to yylex() will + * scan from a @e copy of @a bytes. + * @param yybytes the byte buffer to scan + * @param _yybytes_len the number of bytes in the buffer pointed to by @a bytes. + * + * @return the newly allocated buffer state object. + */ +YY_BUFFER_STATE yy_scan_bytes (yyconst char * yybytes, yy_size_t _yybytes_len ) +{ + YY_BUFFER_STATE b; + char *buf; + yy_size_t n; + yy_size_t i; + + /* Get memory for full buffer, including space for trailing EOB's. */ + n = _yybytes_len + 2; + buf = (char *) yyalloc(n ); + if ( ! buf ) + YY_FATAL_ERROR( "out of dynamic memory in yy_scan_bytes()" ); + + for ( i = 0; i < _yybytes_len; ++i ) + buf[i] = yybytes[i]; + + buf[_yybytes_len] = buf[_yybytes_len+1] = YY_END_OF_BUFFER_CHAR; + + b = yy_scan_buffer(buf,n ); + if ( ! b ) + YY_FATAL_ERROR( "bad buffer in yy_scan_bytes()" ); + + /* It's okay to grow etc. this buffer, and we should throw it + * away when we're done. + */ + b->yy_is_our_buffer = 1; + + return b; +} + +#ifndef YY_EXIT_FAILURE +#define YY_EXIT_FAILURE 2 +#endif + +static void yy_fatal_error (yyconst char* msg ) +{ + (void) fprintf( stderr, "%s\n", msg ); + exit( YY_EXIT_FAILURE ); +} + +/* Redefine yyless() so it works in section 3 code. */ + +#undef yyless +#define yyless(n) \ + do \ + { \ + /* Undo effects of setting up yytext. */ \ + int yyless_macro_arg = (n); \ + YY_LESS_LINENO(yyless_macro_arg);\ + yytext[yyleng] = (yy_hold_char); \ + (yy_c_buf_p) = yytext + yyless_macro_arg; \ + (yy_hold_char) = *(yy_c_buf_p); \ + *(yy_c_buf_p) = '\0'; \ + yyleng = yyless_macro_arg; \ + } \ + while ( 0 ) + +/* Accessor methods (get/set functions) to struct members. */ + +/** Get the current line number. + * + */ +int yyget_lineno (void) +{ + + return yylineno; +} + +/** Get the input stream. + * + */ +FILE *yyget_in (void) +{ + return yyin; +} + +/** Get the output stream. + * + */ +FILE *yyget_out (void) +{ + return yyout; +} + +/** Get the length of the current token. + * + */ +yy_size_t yyget_leng (void) +{ + return yyleng; +} + +/** Get the current token. + * + */ + +char *yyget_text (void) +{ + return yytext; +} + +/** Set the current line number. + * @param _line_number line number + * + */ +void yyset_lineno (int _line_number ) +{ + + yylineno = _line_number; +} + +/** Set the input stream. This does not discard the current + * input buffer. + * @param _in_str A readable stream. + * + * @see yy_switch_to_buffer + */ +void yyset_in (FILE * _in_str ) +{ + yyin = _in_str ; +} + +void yyset_out (FILE * _out_str ) +{ + yyout = _out_str ; +} + +int yyget_debug (void) +{ + return yy_flex_debug; +} + +void yyset_debug (int _bdebug ) +{ + yy_flex_debug = _bdebug ; +} + +static int yy_init_globals (void) +{ + /* Initialization is the same as for the non-reentrant scanner. + * This function is called from yylex_destroy(), so don't allocate here. + */ + + (yy_buffer_stack) = 0; + (yy_buffer_stack_top) = 0; + (yy_buffer_stack_max) = 0; + (yy_c_buf_p) = (char *) 0; + (yy_init) = 0; + (yy_start) = 0; + +/* Defined in main.c */ +#ifdef YY_STDINIT + yyin = stdin; + yyout = stdout; +#else + yyin = (FILE *) 0; + yyout = (FILE *) 0; +#endif + + /* For future reference: Set errno on error, since we are called by + * yylex_init() + */ + return 0; +} + +/* yylex_destroy is for both reentrant and non-reentrant scanners. */ +int yylex_destroy (void) +{ + + /* Pop the buffer stack, destroying each element. */ + while(YY_CURRENT_BUFFER){ + yy_delete_buffer(YY_CURRENT_BUFFER ); + YY_CURRENT_BUFFER_LVALUE = NULL; + yypop_buffer_state(); + } + + /* Destroy the stack itself. */ + yyfree((yy_buffer_stack) ); + (yy_buffer_stack) = NULL; + + /* Reset the globals. This is important in a non-reentrant scanner so the next time + * yylex() is called, initialization will occur. */ + yy_init_globals( ); + + return 0; +} + +/* + * Internal utility routines. + */ + +#ifndef yytext_ptr +static void yy_flex_strncpy (char* s1, yyconst char * s2, int n ) +{ + + int i; + for ( i = 0; i < n; ++i ) + s1[i] = s2[i]; +} +#endif + +#ifdef YY_NEED_STRLEN +static int yy_flex_strlen (yyconst char * s ) +{ + int n; + for ( n = 0; s[n]; ++n ) + ; + + return n; +} +#endif + +void *yyalloc (yy_size_t size ) +{ + return (void *) malloc( size ); +} + +void *yyrealloc (void * ptr, yy_size_t size ) +{ + + /* The cast to (char *) in the following accommodates both + * implementations that use char* generic pointers, and those + * that use void* generic pointers. It works with the latter + * because both ANSI C and C++ allow castless assignment from + * any pointer type to void*, and deal with argument conversions + * as though doing an assignment. + */ + return (void *) realloc( (char *) ptr, size ); +} + +void yyfree (void * ptr ) +{ + free( (char *) ptr ); /* see yyrealloc() for (char *) cast */ +} + +#define YYTABLES_NAME "yytables" + +#line 94 "tokens.l" + + + +int yywrap () +{ + return(1); +} + +void go2init() +{ + yy_init = 1; +} + diff --git a/src/interf/prf.cpp b/src/interf/prf.cpp new file mode 100644 index 0000000000000000000000000000000000000000..0ec73625561eca9538d7f8fd34428c00109fc8fb --- /dev/null +++ b/src/interf/prf.cpp @@ -0,0 +1,209 @@ +//====================================================================================// +// // +// Preferences Structure // +// // +//====================================================================================// +// This File: prf.cpp Language: C++ (xlC and CC) // +// Software: SIMULEAU // +// Error Codes: 6100 // +//====================================================================================// +// Creation: 12/apr/16 by: Leonardo.Brenner@lsis.org // +// Last Change: 12/apr/16 by: Leonardo.Brenner@lsis.org // +//====================================================================================// +#include "simuleau.h" + + //--------------------------------------------------------------------------// + // Constructor // + //--------------------------------------------------------------------------// +PRF::PRF() +{ + strcpy(file_name, "defaults"); + Defaults(); +} + //--------------------------------------------------------------------------// + // Destructor // + //--------------------------------------------------------------------------// +PRF::~PRF() +{ +} + //--------------------------------------------------------------------------// + // It puts the defaults values // + //--------------------------------------------------------------------------// +void PRF::Defaults() +{ + verbose = def_verbose; + max_time = def_time; + min_error = def_err; + thresh = def_thresh; + strcpy(length_unity, def_length_unity); + strcpy(time_unity, def_time_unity); +} + //--------------------------------------------------------------------------// + // It returns the file name // + //--------------------------------------------------------------------------// +char* PRF::Name() +{ + return(file_name); +} + + //--------------------------------------------------------------------------// + // It assigns a file name // + //--------------------------------------------------------------------------// +void PRF::Baptise(const simuleau_name file) +{ + strcpy(file_name, file); +} + + //--------------------------------------------------------------------------// + // It returns the current verbose mode // + //--------------------------------------------------------------------------// +int PRF::Verb() const +{ + return(verbose); +} + //--------------------------------------------------------------------------// + // It sets the verbose mode to 'm' // + //--------------------------------------------------------------------------// +void PRF::Verb(const int m) +{ + verbose = m; +} + //--------------------------------------------------------------------------// + // It returns the current verbose mode // + //--------------------------------------------------------------------------// +char* PRF::Sverb() +{ + switch (verbose) { + case 0 : return("level 0"); + case 1 : return("level 1"); + case 2 : return("level 1"); + default : Programming_Error("preference options must be updated", 6101) + } +} + //--------------------------------------------------------------------------// + // It returns the current maximum simulation time // + //--------------------------------------------------------------------------// +double PRF::Max_Time() const +{ + return(max_time); +} + //--------------------------------------------------------------------------// + // It sets the maximum simulation time to 't' // + //--------------------------------------------------------------------------// +void PRF::Max_Time(const double t) +{ + max_time = t; +} + //--------------------------------------------------------------------------// + // It returns the current minimum error // + //--------------------------------------------------------------------------// +double PRF::Min_Err() const +{ + return(min_error); +} + + //--------------------------------------------------------------------------// + // It returns the current minimum error for date computation // + //--------------------------------------------------------------------------// +double PRF::Min_Err_Date() const +{ + return(min_error/1000); +} + + //--------------------------------------------------------------------------// + // It sets the minimum error to 'e' // + //--------------------------------------------------------------------------// +void PRF::Min_Err(const double e) +{ + min_error = e; +} + //--------------------------------------------------------------------------// + // It returns the current threshold // + //--------------------------------------------------------------------------// +double PRF::Thrs() const +{ + return(thresh); +} + //--------------------------------------------------------------------------// + // It sets the threshold to 't' // + //--------------------------------------------------------------------------// +void PRF::Thrs(const double t) +{ + thresh = t; +} + + //--------------------------------------------------------------------------// + // It returns the current length unity // + //--------------------------------------------------------------------------// +char* PRF::Length_Unity() +{ + return(length_unity); +} + //--------------------------------------------------------------------------// + // It sets the length unity to 'lu' // + //--------------------------------------------------------------------------// +void PRF::Length_Unity(const simuleau_name lu) +{ + strcpy(length_unity, lu); +} + + //--------------------------------------------------------------------------// + // It returns the current time unity // + //--------------------------------------------------------------------------// +char* PRF::Time_Unity() +{ + return(time_unity); +} + //--------------------------------------------------------------------------// + // It sets the time unity to 'tu' // + //--------------------------------------------------------------------------// +void PRF::Time_Unity(const simuleau_name tu) +{ + strcpy(time_unity, tu); +} + + //--------------------------------------------------------------------------// + // Output on 'fout' file stream // + //--------------------------------------------------------------------------// +void PRF::Write() const +{ + ofstream fout; + + Open_File(file_name, prf_file, fout); + fout << verbose << "\n"; + fout << max_time << "\n"; + fout << min_error << "\n"; + fout << thresh << "\n"; + fout << length_unity << "\n"; + fout << time_unity << "\n"; + Close_File(file_name, prf_file, fout); +} + //--------------------------------------------------------------------------// + // Input from 'fin' file stream // + //--------------------------------------------------------------------------// +void PRF::Read(const simuleau_name file) +{ + ifstream fin; + + Open_File(file, prf_file, fin); + Baptise(file); + fin >> verbose; + fin >> max_time; + fin >> min_error; + fin >> thresh; + fin >> length_unity; + fin >> time_unity; + Close_File(file_name, prf_file, fin); +} + //--------------------------------------------------------------------------// + // Memory space used by 'this' (in memory units) // + //--------------------------------------------------------------------------// +int PRF::Mem_use() const +{ + return(max_simuleau_name+sizeof(bool)+3*sizeof(double)); +} + + //--------------------------------------------------------------------------// + // static variable: The User Preferences // + //--------------------------------------------------------------------------// +PRF PRF::prf = PRF(); diff --git a/src/interf/prf.h b/src/interf/prf.h new file mode 100644 index 0000000000000000000000000000000000000000..8d3c21ceae2405f76680ab97cb5ed82d9e6cfa88 --- /dev/null +++ b/src/interf/prf.h @@ -0,0 +1,69 @@ +//====================================================================================// +// // +// Preferences Structure // +// // +//====================================================================================// +// This File: prf.h Language: C++ (xlC and CC) // +// Software: SIMULEAU // +// Error Codes: 6100 // +//====================================================================================// +// Creation: 12/apr/16 by: Leonardo.Brenner@lsis.org // +// Last Change: 12/apr/16 by: Leonardo.Brenner@lsis.org // +//====================================================================================// +// This class is used to store the static variable 'PRF::prf' which contains most // +// of the user choices in Simuleau. // +//====================================================================================// +#ifndef PRF_H +#define PRF_H + +class PRF +{ +public: + PRF(); // Constructor + ~PRF(); // Destructor + void Defaults(); // It puts the defaults values + + char* Name(); // It returns the file name + void Baptise(const simuleau_name file); // It assigns a file name + + int Verb() const; // It returns the current verbose mode + void Verb(const int m); // It sets the verbose mode to 'm' + char* Sverb(); // string answer + + double Max_Time() const; // It returns the current maximum simulation time + void Max_Time(const double t); // It sets the maximum simulation time to 't' + + double Min_Err() const; // It returns the current minimum error + double Min_Err_Date() const; // It returns the current minimum error + void Min_Err(const double e); // It sets the minimum error to 'e' + + double Thrs() const; // It returns the current threshold + void Thrs(const double t); // It sets the threshold to 't' + + char* Length_Unity(); // It returns the current lenght unity + void Length_Unity(const simuleau_name lu); //It sets the lenght unity to 'lu' + + char* Time_Unity(); // It returns the current time unity + void Time_Unity(const simuleau_name tu); //It sets the time unity to 'tu' + + void Write() const; // Output on 'fout' file stream + void Read(const simuleau_name file); // Input from 'fin' file stream + int Mem_use() const; // Memory space used by 'this' (in bytes) + + //--------------------------------------------------------------------------// + // Static variable // + //--------------------------------------------------------------------------// + static PRF prf; + + //--------------------------------------------------------------------------// + // Data Structures // + //--------------------------------------------------------------------------// +private: simuleau_name file_name; // the file name of this structure + int verbose; // Verbose mode + double max_time; // Maximum simulation time + double min_error; // Minimum error + double thresh; // Threshold + simuleau_name length_unity; // Length unity + simuleau_name time_unity; // Time unity +}; +#endif // PRF_H diff --git a/src/interf/test b/src/interf/test new file mode 100644 index 0000000000000000000000000000000000000000..2abb9548ec960b0ea053d37eac9e1e3036a418ae --- /dev/null +++ b/src/interf/test @@ -0,0 +1,54 @@ +// comments + +model test; +length unity= km ; +time unity = h; + +network description +places + place P1 (discrete) + initial marking {1} + output arc T1 + output arc T2 (2) + + place p2 (continuous) + initial marking {2.5} + output arc T3 (1) + output arc t4 + + place pl (batch) + function (10,120, 200 ) + initial marking { (1, 1.2, 100) } +// output arc t5 +// output arc t6 (3) + + place pt (triangular) + function ( 120, 250, 10.4, 4000) + initial marking { (2.3, 1.0,50, 200) , + (3, 10, 120, 300) } + output arc t6 (3.2) + +transitions + transition T1 (discrete) + timing (5.1) + output arc P1 + output arc p2 (2) + + transition T2 (continuous) + flow (300.5) + output arc p2 + output arc pl + + transition t3 (batch) + flow (4000) + output arc pt + +controlled events // les evenements controlles pourrons aussi etre lu a partir d un fichier externe + ev1 = (flow, p1, 4000, 0.001); + ev2 = (speed, pt, 120, 0.002); + +time inspection // affiche l information d une place(caracteristiques+lots)/transition(flux) a l instant <time> + res1 = @ 1.001 ? pt; + res2 = # 1.02 * places + + diff --git a/src/interf/timer.cpp b/src/interf/timer.cpp new file mode 100644 index 0000000000000000000000000000000000000000..0753f96e6fa31f01f59baefe53e1668810a73ed7 --- /dev/null +++ b/src/interf/timer.cpp @@ -0,0 +1,103 @@ +// ======================================================================= // +// Class Timer : +// (c) copyright PAC++ 1994 +// date: 1994 +// ======================================================================= // + +#include <math.h> +extern "C" { +#include <sys/time.h> +#include <sys/resource.h> + // int getrusage (int, struct rusage*) ; *** removed for g++ compiler +} +#include <iostream> + +using namespace std; + +#include "timer.h" + + // Clear timer : +void Timer::clear() { ut = st = rt = 0 ; } + + // Start timer +void Timer::start() +{ + struct rusage tmp1 ; // to getrusage (sys+user times) + struct timeval tmp2 ; // to gettimeofday (real time) + getrusage (RUSAGE_SELF, &tmp1) ; + gettimeofday (&tmp2, 0) ; + + // user time + ut = (double) tmp1.ru_utime.tv_sec + + ((double) tmp1.ru_utime.tv_usec)/ (double)MSPSEC ; + // system time + st = (double) tmp1.ru_stime.tv_sec + + ((double) tmp1.ru_stime.tv_usec)/ (double)MSPSEC ; + // real time + rt = (double) tmp2.tv_sec + + ((double) tmp2.tv_usec)/ (double)MSPSEC ; +} + + // Stop timer +void Timer::stop() +{ + double uts = ut, sts = st , rts = rt ; + start() ; + ut -= uts ; st -= sts ; rt -= rts ; +} + + // Return a value to initialize random generator +long Timer::seed() +{ + struct timeval tp; + gettimeofday(&tp, 0) ; + return(tp.tv_usec); + return 1 ; +} + + // Output the value of the timer : +ostream& operator<<(ostream& o, const Timer& T) +{ + o << "user time: " << T.usertime() << '\n' ; + o << "sys. time: " << T.systime() << '\n' ; + o << "real time: " << T.realtime() << endl ; + return o ; +} + + // Some arithmetic operator : +Timer& Timer::operator = (const Timer & T) +{ + ut = T.ut ; st = T.st ; rt = T.rt ; + return *this ; +} + + // Computes and returns interval of time + // beteween *this and T +const Timer Timer::operator - (const Timer & T) const +{ + Timer Tmp ; + Tmp.ut = ut - T.ut ; + Tmp.st = st - T.st ; + Tmp.rt = rt - T.rt ; + return Tmp ; +} + +const Timer Timer::operator - () +{ + Timer Tmp ; + Tmp.ut = -ut ; + Tmp.st = -st ; + Tmp.rt = -rt ; + return Tmp ; +} + +const Timer Timer::operator + (const Timer & T) const +{ + Timer Tmp ; + Tmp.ut = ut + T.ut ; + Tmp.st = st + T.st ; + Tmp.rt = rt + T.rt ; + return Tmp ; +} + + diff --git a/src/interf/timer.h b/src/interf/timer.h new file mode 100644 index 0000000000000000000000000000000000000000..48805fd0fc37ca2e871d98454e634d01eb83a7fd --- /dev/null +++ b/src/interf/timer.h @@ -0,0 +1,56 @@ +#ifndef _TIMER_H_ +#define _TIMER_H_ +// ======================================================================= // +// Class Timer : +// (c) copyright PAC++ 1994 +// date: 1994 +// ======================================================================= // + +class Timer { +enum { + MSPSEC = 1000000 // microsecond per second +} ; +public : + + // Clear timer : + void clear() ; + + // Start timer + void start() ; + + // Stop timer + void stop() ; + + // total amount of second spent in user mode + double usertime() const { return ut ; } + + // total amount of second spent in system mode + double systime () const { return st ; } + + // real total amount of second spent. + double realtime () const { return rt ; } + + // retourne une petite graine + long seed() ; + + // Output the value of the timer : + friend ostream& operator<<(ostream& o, const Timer& T) ; + + // Some arithmetic operators to compute cumulative time : + Timer& operator = (const Timer & T) ; + const Timer operator - (const Timer & T) const ; + const Timer operator - () ; + const Timer operator + (const Timer & T) const ; + const Timer operator += (const Timer & T) { return *this = *this + T; } ; + const Timer operator -= (const Timer & T) { return *this = *this - T; } ; + + +private : + double ut ; // user time + double st ; // system time + double rt ; // real time +} ; + + + +#endif diff --git a/src/interf/tokens.l b/src/interf/tokens.l new file mode 100644 index 0000000000000000000000000000000000000000..7b0ccbe4a15493bc2bc6dc3912af3ff9e5490b20 --- /dev/null +++ b/src/interf/tokens.l @@ -0,0 +1,104 @@ +%{ +//====================================================================================// +// // +// Lexical Analyzer // +// // +//====================================================================================// +// This File: tokens.l Tool: lex // +// Software: SIMULEAU // +// Doc: // +//====================================================================================// +// Creation: 15/Apr/16 by: Leonardo.Brenner@lsis.org // +// Last Change: 15/Apr/16 by: Leonardo.Brenner@lsis.org // +//====================================================================================// +// This file has the definitions of the tokens that must to be recognized by the // +// grammar contained in the "glc.y" file. These definitions are used by LEX tool, // +// which is a generator of lexical parsers. // +// The lexical analyzer (scanner) is a function that reads an input stream and // +// returns the correspondents tokens. // +//====================================================================================// +#include "bpnfile.h" + +extern int yynerrs; // Variable of the YACC generator to count the number of errors. +extern int yylineno; + +//====================================================================================// +// Below are defined the R.E.(Regular Expressions) that defines the format of the // +// digits (symbols between 0 and 9, inclusively), integers, reals, exponents and // +// identifies. The symbol "+" indicate one or more occurrences, the symbol "*" // +// indicate zero or more occurrences and the symbol "?" indicate that the occurrence // +// is optional. // +//====================================================================================// + +%} + +digit [0-9] +integer {digit}+ +real {integer}"."{integer} +exponent ({integer}|{real})[Ee][+-]?{integer} +id [A-Za-z_][A-Za-z0-9_]* + +%% + +"//"[0-9A-Za-z\'\-\!\"\#\$\%\&\(\)\*\+\,\-\.\/:\;\<\>\=\?\@\\\]\[\}\{\^\_\~\| ]* +"arc" {return(TK_ARC);} +"batch" {return(TK_BATCH);} +"continuous" {return(TK_CONTINUOUS);} +"controlled" {return(TK_CONTROLLED);} +"description" {return(TK_DESCRIPTION);} +"discrete" {return(TK_DISCRETE);} +"events" {return(TK_EVENTS);} +"flow" {return(TK_FLOW);} +"function" {return(TK_FUNCTION);} +"initial" {return(TK_INITIAL);} +"inspection" {return(TK_INSPECTION);} +"length" {return(TK_LENGTH);} +"marking" {return(TK_MARKING);} +"model" {return(TK_MODEL);} +"network" {return(TK_NETWORK);} +"output" {return(TK_OUTPUT);} +"place" {return(TK_PLACE);} +"places" {return(TK_PLACES);} +"speed" {return(TK_SPEED);} +"steady" {return(TK_STEADY);} +"time" {return(TK_TIME);} +"timing" {return(TK_TIMING);} +"transition" {return(TK_TRANSITION);} +"transitions" {return(TK_TRANSITIONS);} +"triangular" {return(TK_TRIANGULAR);} +"unity" {return(TK_UNITY);} +{id} {return(TK_ID);} +{integer} {return(TK_INTEGER);} +{real} {return(TK_REAL);} +{exponent} {return(TK_EXPONENT);} +"@" {return(TK_AT);} +"#" {return(TK_EVERY);} +"?" {return(TK_PL_TR);} +"*" {return(TK_ALL);} +"{" {return(TK_LEFT_BRACKET);} +"}" {return(TK_RIGHT_BRACKET);} +"(" {return(TK_LEFT_PARENTHESIS);} +")" {return(TK_RIGHT_PARENTHESIS);} +"[" {return(TK_LEFT_SQUARE_BRACKET);} +"]" {return(TK_RIGHT_SQUARE_BRACKET);} +";" {return(TK_SEMICOLON);} +"," {return(TK_COMMA);} +"=" {return(TK_ATTRIB);} +":" {return(TK_COLON);} +[ \t]* {/* Ignore the blanks, tabulates and new line */} +[\n] {yylineno++;} +. { /* If neither token return, means that the input + stream has a lexical error */ + yynerrs++; + Lexical_Error(yynerrs, yylineno, yytext);} +%% + +int yywrap () +{ + return(1); +} + +void go2init() +{ + yy_init = 1; +} diff --git a/src/interf/y.output b/src/interf/y.output new file mode 100644 index 0000000000000000000000000000000000000000..f54a13877201ffda8b31c4c4af6165507e8727bb --- /dev/null +++ b/src/interf/y.output @@ -0,0 +1,2550 @@ +Terminals unused in grammar + + TK_LEFT_SQUARE_BRACKET + TK_RIGHT_SQUARE_BRACKET + TK_COLON + + +Grammar + + 0 $accept: start $end + + 1 start: blk_def blk_net blk_controlled_events blk_time_inspection + + 2 blk_def: blk_model blk_unity + + 3 $@1: %empty + + 4 blk_model: TK_MODEL TK_ID $@1 semi_colon + 5 | %empty + + 6 blk_unity: blk_lenght blk_time + + 7 $@2: %empty + + 8 blk_lenght: TK_LENGTH TK_UNITY TK_ATTRIB TK_ID $@2 semi_colon + 9 | %empty + + 10 $@3: %empty + + 11 blk_time: TK_TIME TK_UNITY TK_ATTRIB TK_ID $@3 semi_colon + 12 | %empty + + 13 semi_colon: TK_SEMICOLON + 14 | %empty + + 15 number: TK_REAL + 16 | TK_INTEGER + 17 | TK_EXPONENT + + 18 blk_net: TK_NETWORK TK_DESCRIPTION blk_places blk_transitions + + 19 $@4: %empty + + 20 blk_places: TK_PLACES $@4 blk_place + + 21 $@5: %empty + + 22 blk_transitions: TK_TRANSITIONS $@5 blk_transition + + 23 $@6: %empty + + 24 $@7: %empty + + 25 blk_place: TK_PLACE TK_ID $@6 TK_LEFT_PARENTHESIS blk_place_type TK_RIGHT_PARENTHESIS blk_function $@7 blk_initial_marking blk_steady_marking blk_place_arcs blk_place2 + + 26 blk_place2: blk_place + 27 | %empty + + 28 blk_place_type: TK_DISCRETE + 29 | TK_CONTINUOUS + 30 | TK_BATCH + 31 | TK_TRIANGULAR + + 32 $@8: %empty + + 33 $@9: %empty + + 34 $@10: %empty + + 35 $@11: %empty + + 36 blk_function: TK_FUNCTION $@8 TK_LEFT_PARENTHESIS number $@9 TK_COMMA number $@10 TK_COMMA number $@11 blk_triangular_place TK_RIGHT_PARENTHESIS + 37 | %empty + + 38 blk_triangular_place: TK_COMMA number + 39 | %empty + + 40 blk_initial_marking: TK_INITIAL TK_MARKING TK_LEFT_BRACKET blk_initial_marking_int TK_RIGHT_BRACKET + + 41 blk_initial_marking_int: number + 42 | blk_batch + + 43 $@12: %empty + + 44 $@13: %empty + + 45 $@14: %empty + + 46 $@15: %empty + + 47 blk_batch: TK_LEFT_PARENTHESIS number $@12 TK_COMMA number $@13 TK_COMMA number $@14 blk_triangular_batch TK_RIGHT_PARENTHESIS $@15 blk_batch2 + 48 | %empty + + 49 blk_batch2: TK_COMMA blk_batch + 50 | %empty + + 51 blk_triangular_batch: TK_COMMA number + 52 | %empty + + 53 blk_steady_marking: TK_STEADY TK_MARKING TK_LEFT_BRACKET blk_steady_marking_int TK_RIGHT_BRACKET + 54 | %empty + + 55 blk_steady_marking_int: number + 56 | blk_steady_batch + + 57 $@16: %empty + + 58 $@17: %empty + + 59 $@18: %empty + + 60 $@19: %empty + + 61 blk_steady_batch: TK_LEFT_PARENTHESIS number $@16 TK_COMMA number $@17 TK_COMMA number $@18 blk_steady_triangular_batch TK_RIGHT_PARENTHESIS $@19 blk_steady_batch2 + 62 | %empty + + 63 blk_steady_batch2: TK_COMMA blk_steady_batch + 64 | %empty + + 65 blk_steady_triangular_batch: TK_COMMA number + 66 | %empty + + 67 $@20: %empty + + 68 $@21: %empty + + 69 blk_place_arcs: TK_OUTPUT TK_ARC TK_ID $@20 blk_place_weight $@21 blk_place_arcs2 + 70 | %empty + + 71 blk_place_arcs2: blk_place_arcs + + 72 $@22: %empty + + 73 blk_place_weight: TK_LEFT_PARENTHESIS number $@22 TK_RIGHT_PARENTHESIS + 74 | %empty + + 75 $@23: %empty + + 76 $@24: %empty + + 77 $@25: %empty + + 78 blk_transition: TK_TRANSITION TK_ID $@23 TK_LEFT_PARENTHESIS blk_transition_type TK_RIGHT_PARENTHESIS blk_transition_function $@24 blk_steady_transition_function $@25 blk_transition_arcs blk_transition2 + + 79 blk_transition2: blk_transition + 80 | %empty + + 81 blk_transition_type: TK_DISCRETE + 82 | TK_CONTINUOUS + 83 | TK_BATCH + + 84 $@26: %empty + + 85 blk_transition_function: TK_TIMING TK_LEFT_PARENTHESIS number $@26 TK_RIGHT_PARENTHESIS + + 86 $@27: %empty + + 87 blk_transition_function: TK_FLOW TK_LEFT_PARENTHESIS number $@27 TK_RIGHT_PARENTHESIS + + 88 blk_steady_transition_function: TK_STEADY blk_steady_transition_function_int + 89 | %empty + + 90 $@28: %empty + + 91 blk_steady_transition_function_int: TK_TIMING TK_LEFT_PARENTHESIS number $@28 TK_RIGHT_PARENTHESIS + + 92 $@29: %empty + + 93 blk_steady_transition_function_int: TK_FLOW TK_LEFT_PARENTHESIS number $@29 TK_RIGHT_PARENTHESIS + + 94 $@30: %empty + + 95 $@31: %empty + + 96 blk_transition_arcs: TK_OUTPUT TK_ARC TK_ID $@30 blk_transition_weight $@31 blk_transition_arcs2 + 97 | %empty + + 98 blk_transition_arcs2: blk_transition_arcs + + 99 $@32: %empty + + 100 blk_transition_weight: TK_LEFT_PARENTHESIS number $@32 TK_RIGHT_PARENTHESIS + 101 | %empty + + 102 $@33: %empty + + 103 blk_controlled_events: TK_CONTROLLED TK_EVENTS $@33 controlled_events + 104 | %empty + + 105 $@34: %empty + + 106 $@35: %empty + + 107 $@36: %empty + + 108 $@37: %empty + + 109 $@38: %empty + + 110 controlled_events: TK_ID $@34 TK_ATTRIB TK_LEFT_PARENTHESIS controlled_events_type TK_COMMA TK_ID $@35 TK_COMMA number $@36 TK_COMMA number $@37 TK_RIGHT_PARENTHESIS semi_colon $@38 controlled_events2 + 111 | %empty + + 112 controlled_events2: controlled_events + + 113 controlled_events_type: TK_FLOW + 114 | TK_SPEED + + 115 $@39: %empty + + 116 blk_time_inspection: TK_TIME TK_INSPECTION $@39 time_inspection + 117 | %empty + + 118 $@40: %empty + + 119 $@41: %empty + + 120 $@42: %empty + + 121 $@43: %empty + + 122 time_inspection: TK_ID $@40 TK_ATTRIB blk_op_time number $@41 blk_op_pt $@42 semi_colon $@43 time_inspection2 + 123 | %empty + + 124 time_inspection2: time_inspection + + 125 blk_op_time: TK_AT + 126 | TK_EVERY + + 127 blk_op_pt: TK_PL_TR TK_ID + 128 | TK_ALL blk_pl_tr + + 129 blk_pl_tr: TK_PLACES + 130 | TK_TRANSITIONS + + +Terminals, with rules where they appear + + $end (0) 0 + error (256) + TK_ARC (258) 69 96 + TK_BATCH (259) 30 83 + TK_CONTINUOUS (260) 29 82 + TK_CONTROLLED (261) 103 + TK_DESCRIPTION (262) 18 + TK_DISCRETE (263) 28 81 + TK_EVENTS (264) 103 + TK_FLOW (265) 87 93 113 + TK_FUNCTION (266) 36 + TK_INITIAL (267) 40 + TK_INSPECTION (268) 116 + TK_LENGTH (269) 8 + TK_MARKING (270) 40 53 + TK_MODEL (271) 4 + TK_NETWORK (272) 18 + TK_OUTPUT (273) 69 96 + TK_PLACE (274) 25 + TK_PLACES (275) 20 129 + TK_SPEED (276) 114 + TK_STEADY (277) 53 88 + TK_TIME (278) 11 116 + TK_TIMING (279) 85 91 + TK_TRANSITION (280) 78 + TK_TRANSITIONS (281) 22 130 + TK_TRIANGULAR (282) 31 + TK_UNITY (283) 8 11 + TK_ID (284) 4 8 11 25 69 78 96 110 122 127 + TK_INTEGER (285) 16 + TK_REAL (286) 15 + TK_EXPONENT (287) 17 + TK_AT (288) 125 + TK_EVERY (289) 126 + TK_LEFT_BRACKET (290) 40 53 + TK_RIGHT_BRACKET (291) 40 53 + TK_PL_TR (292) 127 + TK_ALL (293) 128 + TK_LEFT_PARENTHESIS (294) 25 36 47 61 73 78 85 87 91 93 100 110 + TK_RIGHT_PARENTHESIS (295) 25 36 47 61 73 78 85 87 91 93 100 110 + TK_LEFT_SQUARE_BRACKET (296) + TK_RIGHT_SQUARE_BRACKET (297) + TK_SEMICOLON (298) 13 + TK_COMMA (299) 36 38 47 49 51 61 63 65 110 + TK_ATTRIB (300) 8 11 110 122 + TK_COLON (301) + + +Nonterminals, with rules where they appear + + $accept (47) + on left: 0 + start (48) + on left: 1 + on right: 0 + blk_def (49) + on left: 2 + on right: 1 + blk_model (50) + on left: 4 5 + on right: 2 + $@1 (51) + on left: 3 + on right: 4 + blk_unity (52) + on left: 6 + on right: 2 + blk_lenght (53) + on left: 8 9 + on right: 6 + $@2 (54) + on left: 7 + on right: 8 + blk_time (55) + on left: 11 12 + on right: 6 + $@3 (56) + on left: 10 + on right: 11 + semi_colon (57) + on left: 13 14 + on right: 4 8 11 110 122 + number (58) + on left: 15 16 17 + on right: 36 38 41 47 51 55 61 65 73 85 87 91 93 100 110 122 + blk_net (59) + on left: 18 + on right: 1 + blk_places (60) + on left: 20 + on right: 18 + $@4 (61) + on left: 19 + on right: 20 + blk_transitions (62) + on left: 22 + on right: 18 + $@5 (63) + on left: 21 + on right: 22 + blk_place (64) + on left: 25 + on right: 20 26 + $@6 (65) + on left: 23 + on right: 25 + $@7 (66) + on left: 24 + on right: 25 + blk_place2 (67) + on left: 26 27 + on right: 25 + blk_place_type (68) + on left: 28 29 30 31 + on right: 25 + blk_function (69) + on left: 36 37 + on right: 25 + $@8 (70) + on left: 32 + on right: 36 + $@9 (71) + on left: 33 + on right: 36 + $@10 (72) + on left: 34 + on right: 36 + $@11 (73) + on left: 35 + on right: 36 + blk_triangular_place (74) + on left: 38 39 + on right: 36 + blk_initial_marking (75) + on left: 40 + on right: 25 + blk_initial_marking_int (76) + on left: 41 42 + on right: 40 + blk_batch (77) + on left: 47 48 + on right: 42 49 + $@12 (78) + on left: 43 + on right: 47 + $@13 (79) + on left: 44 + on right: 47 + $@14 (80) + on left: 45 + on right: 47 + $@15 (81) + on left: 46 + on right: 47 + blk_batch2 (82) + on left: 49 50 + on right: 47 + blk_triangular_batch (83) + on left: 51 52 + on right: 47 + blk_steady_marking (84) + on left: 53 54 + on right: 25 + blk_steady_marking_int (85) + on left: 55 56 + on right: 53 + blk_steady_batch (86) + on left: 61 62 + on right: 56 63 + $@16 (87) + on left: 57 + on right: 61 + $@17 (88) + on left: 58 + on right: 61 + $@18 (89) + on left: 59 + on right: 61 + $@19 (90) + on left: 60 + on right: 61 + blk_steady_batch2 (91) + on left: 63 64 + on right: 61 + blk_steady_triangular_batch (92) + on left: 65 66 + on right: 61 + blk_place_arcs (93) + on left: 69 70 + on right: 25 71 + $@20 (94) + on left: 67 + on right: 69 + $@21 (95) + on left: 68 + on right: 69 + blk_place_arcs2 (96) + on left: 71 + on right: 69 + blk_place_weight (97) + on left: 73 74 + on right: 69 + $@22 (98) + on left: 72 + on right: 73 + blk_transition (99) + on left: 78 + on right: 22 79 + $@23 (100) + on left: 75 + on right: 78 + $@24 (101) + on left: 76 + on right: 78 + $@25 (102) + on left: 77 + on right: 78 + blk_transition2 (103) + on left: 79 80 + on right: 78 + blk_transition_type (104) + on left: 81 82 83 + on right: 78 + blk_transition_function (105) + on left: 85 87 + on right: 78 + $@26 (106) + on left: 84 + on right: 85 + $@27 (107) + on left: 86 + on right: 87 + blk_steady_transition_function (108) + on left: 88 89 + on right: 78 + blk_steady_transition_function_int (109) + on left: 91 93 + on right: 88 + $@28 (110) + on left: 90 + on right: 91 + $@29 (111) + on left: 92 + on right: 93 + blk_transition_arcs (112) + on left: 96 97 + on right: 78 98 + $@30 (113) + on left: 94 + on right: 96 + $@31 (114) + on left: 95 + on right: 96 + blk_transition_arcs2 (115) + on left: 98 + on right: 96 + blk_transition_weight (116) + on left: 100 101 + on right: 96 + $@32 (117) + on left: 99 + on right: 100 + blk_controlled_events (118) + on left: 103 104 + on right: 1 + $@33 (119) + on left: 102 + on right: 103 + controlled_events (120) + on left: 110 111 + on right: 103 112 + $@34 (121) + on left: 105 + on right: 110 + $@35 (122) + on left: 106 + on right: 110 + $@36 (123) + on left: 107 + on right: 110 + $@37 (124) + on left: 108 + on right: 110 + $@38 (125) + on left: 109 + on right: 110 + controlled_events2 (126) + on left: 112 + on right: 110 + controlled_events_type (127) + on left: 113 114 + on right: 110 + blk_time_inspection (128) + on left: 116 117 + on right: 1 + $@39 (129) + on left: 115 + on right: 116 + time_inspection (130) + on left: 122 123 + on right: 116 124 + $@40 (131) + on left: 118 + on right: 122 + $@41 (132) + on left: 119 + on right: 122 + $@42 (133) + on left: 120 + on right: 122 + $@43 (134) + on left: 121 + on right: 122 + time_inspection2 (135) + on left: 124 + on right: 122 + blk_op_time (136) + on left: 125 126 + on right: 122 + blk_op_pt (137) + on left: 127 128 + on right: 122 + blk_pl_tr (138) + on left: 129 130 + on right: 128 + + +State 0 + + 0 $accept: . start $end + + TK_MODEL shift, and go to state 1 + + $default reduce using rule 5 (blk_model) + + start go to state 2 + blk_def go to state 3 + blk_model go to state 4 + + +State 1 + + 4 blk_model: TK_MODEL . TK_ID $@1 semi_colon + + TK_ID shift, and go to state 5 + + +State 2 + + 0 $accept: start . $end + + $end shift, and go to state 6 + + +State 3 + + 1 start: blk_def . blk_net blk_controlled_events blk_time_inspection + + TK_NETWORK shift, and go to state 7 + + blk_net go to state 8 + + +State 4 + + 2 blk_def: blk_model . blk_unity + + TK_LENGTH shift, and go to state 9 + + $default reduce using rule 9 (blk_lenght) + + blk_unity go to state 10 + blk_lenght go to state 11 + + +State 5 + + 4 blk_model: TK_MODEL TK_ID . $@1 semi_colon + + $default reduce using rule 3 ($@1) + + $@1 go to state 12 + + +State 6 + + 0 $accept: start $end . + + $default accept + + +State 7 + + 18 blk_net: TK_NETWORK . TK_DESCRIPTION blk_places blk_transitions + + TK_DESCRIPTION shift, and go to state 13 + + +State 8 + + 1 start: blk_def blk_net . blk_controlled_events blk_time_inspection + + TK_CONTROLLED shift, and go to state 14 + + $default reduce using rule 104 (blk_controlled_events) + + blk_controlled_events go to state 15 + + +State 9 + + 8 blk_lenght: TK_LENGTH . TK_UNITY TK_ATTRIB TK_ID $@2 semi_colon + + TK_UNITY shift, and go to state 16 + + +State 10 + + 2 blk_def: blk_model blk_unity . + + $default reduce using rule 2 (blk_def) + + +State 11 + + 6 blk_unity: blk_lenght . blk_time + + TK_TIME shift, and go to state 17 + + $default reduce using rule 12 (blk_time) + + blk_time go to state 18 + + +State 12 + + 4 blk_model: TK_MODEL TK_ID $@1 . semi_colon + + TK_SEMICOLON shift, and go to state 19 + + $default reduce using rule 14 (semi_colon) + + semi_colon go to state 20 + + +State 13 + + 18 blk_net: TK_NETWORK TK_DESCRIPTION . blk_places blk_transitions + + TK_PLACES shift, and go to state 21 + + blk_places go to state 22 + + +State 14 + + 103 blk_controlled_events: TK_CONTROLLED . TK_EVENTS $@33 controlled_events + + TK_EVENTS shift, and go to state 23 + + +State 15 + + 1 start: blk_def blk_net blk_controlled_events . blk_time_inspection + + TK_TIME shift, and go to state 24 + + $default reduce using rule 117 (blk_time_inspection) + + blk_time_inspection go to state 25 + + +State 16 + + 8 blk_lenght: TK_LENGTH TK_UNITY . TK_ATTRIB TK_ID $@2 semi_colon + + TK_ATTRIB shift, and go to state 26 + + +State 17 + + 11 blk_time: TK_TIME . TK_UNITY TK_ATTRIB TK_ID $@3 semi_colon + + TK_UNITY shift, and go to state 27 + + +State 18 + + 6 blk_unity: blk_lenght blk_time . + + $default reduce using rule 6 (blk_unity) + + +State 19 + + 13 semi_colon: TK_SEMICOLON . + + $default reduce using rule 13 (semi_colon) + + +State 20 + + 4 blk_model: TK_MODEL TK_ID $@1 semi_colon . + + $default reduce using rule 4 (blk_model) + + +State 21 + + 20 blk_places: TK_PLACES . $@4 blk_place + + $default reduce using rule 19 ($@4) + + $@4 go to state 28 + + +State 22 + + 18 blk_net: TK_NETWORK TK_DESCRIPTION blk_places . blk_transitions + + TK_TRANSITIONS shift, and go to state 29 + + blk_transitions go to state 30 + + +State 23 + + 103 blk_controlled_events: TK_CONTROLLED TK_EVENTS . $@33 controlled_events + + $default reduce using rule 102 ($@33) + + $@33 go to state 31 + + +State 24 + + 116 blk_time_inspection: TK_TIME . TK_INSPECTION $@39 time_inspection + + TK_INSPECTION shift, and go to state 32 + + +State 25 + + 1 start: blk_def blk_net blk_controlled_events blk_time_inspection . + + $default reduce using rule 1 (start) + + +State 26 + + 8 blk_lenght: TK_LENGTH TK_UNITY TK_ATTRIB . TK_ID $@2 semi_colon + + TK_ID shift, and go to state 33 + + +State 27 + + 11 blk_time: TK_TIME TK_UNITY . TK_ATTRIB TK_ID $@3 semi_colon + + TK_ATTRIB shift, and go to state 34 + + +State 28 + + 20 blk_places: TK_PLACES $@4 . blk_place + + TK_PLACE shift, and go to state 35 + + blk_place go to state 36 + + +State 29 + + 22 blk_transitions: TK_TRANSITIONS . $@5 blk_transition + + $default reduce using rule 21 ($@5) + + $@5 go to state 37 + + +State 30 + + 18 blk_net: TK_NETWORK TK_DESCRIPTION blk_places blk_transitions . + + $default reduce using rule 18 (blk_net) + + +State 31 + + 103 blk_controlled_events: TK_CONTROLLED TK_EVENTS $@33 . controlled_events + + TK_ID shift, and go to state 38 + + $default reduce using rule 111 (controlled_events) + + controlled_events go to state 39 + + +State 32 + + 116 blk_time_inspection: TK_TIME TK_INSPECTION . $@39 time_inspection + + $default reduce using rule 115 ($@39) + + $@39 go to state 40 + + +State 33 + + 8 blk_lenght: TK_LENGTH TK_UNITY TK_ATTRIB TK_ID . $@2 semi_colon + + $default reduce using rule 7 ($@2) + + $@2 go to state 41 + + +State 34 + + 11 blk_time: TK_TIME TK_UNITY TK_ATTRIB . TK_ID $@3 semi_colon + + TK_ID shift, and go to state 42 + + +State 35 + + 25 blk_place: TK_PLACE . TK_ID $@6 TK_LEFT_PARENTHESIS blk_place_type TK_RIGHT_PARENTHESIS blk_function $@7 blk_initial_marking blk_steady_marking blk_place_arcs blk_place2 + + TK_ID shift, and go to state 43 + + +State 36 + + 20 blk_places: TK_PLACES $@4 blk_place . + + $default reduce using rule 20 (blk_places) + + +State 37 + + 22 blk_transitions: TK_TRANSITIONS $@5 . blk_transition + + TK_TRANSITION shift, and go to state 44 + + blk_transition go to state 45 + + +State 38 + + 110 controlled_events: TK_ID . $@34 TK_ATTRIB TK_LEFT_PARENTHESIS controlled_events_type TK_COMMA TK_ID $@35 TK_COMMA number $@36 TK_COMMA number $@37 TK_RIGHT_PARENTHESIS semi_colon $@38 controlled_events2 + + $default reduce using rule 105 ($@34) + + $@34 go to state 46 + + +State 39 + + 103 blk_controlled_events: TK_CONTROLLED TK_EVENTS $@33 controlled_events . + + $default reduce using rule 103 (blk_controlled_events) + + +State 40 + + 116 blk_time_inspection: TK_TIME TK_INSPECTION $@39 . time_inspection + + TK_ID shift, and go to state 47 + + $default reduce using rule 123 (time_inspection) + + time_inspection go to state 48 + + +State 41 + + 8 blk_lenght: TK_LENGTH TK_UNITY TK_ATTRIB TK_ID $@2 . semi_colon + + TK_SEMICOLON shift, and go to state 19 + + $default reduce using rule 14 (semi_colon) + + semi_colon go to state 49 + + +State 42 + + 11 blk_time: TK_TIME TK_UNITY TK_ATTRIB TK_ID . $@3 semi_colon + + $default reduce using rule 10 ($@3) + + $@3 go to state 50 + + +State 43 + + 25 blk_place: TK_PLACE TK_ID . $@6 TK_LEFT_PARENTHESIS blk_place_type TK_RIGHT_PARENTHESIS blk_function $@7 blk_initial_marking blk_steady_marking blk_place_arcs blk_place2 + + $default reduce using rule 23 ($@6) + + $@6 go to state 51 + + +State 44 + + 78 blk_transition: TK_TRANSITION . TK_ID $@23 TK_LEFT_PARENTHESIS blk_transition_type TK_RIGHT_PARENTHESIS blk_transition_function $@24 blk_steady_transition_function $@25 blk_transition_arcs blk_transition2 + + TK_ID shift, and go to state 52 + + +State 45 + + 22 blk_transitions: TK_TRANSITIONS $@5 blk_transition . + + $default reduce using rule 22 (blk_transitions) + + +State 46 + + 110 controlled_events: TK_ID $@34 . TK_ATTRIB TK_LEFT_PARENTHESIS controlled_events_type TK_COMMA TK_ID $@35 TK_COMMA number $@36 TK_COMMA number $@37 TK_RIGHT_PARENTHESIS semi_colon $@38 controlled_events2 + + TK_ATTRIB shift, and go to state 53 + + +State 47 + + 122 time_inspection: TK_ID . $@40 TK_ATTRIB blk_op_time number $@41 blk_op_pt $@42 semi_colon $@43 time_inspection2 + + $default reduce using rule 118 ($@40) + + $@40 go to state 54 + + +State 48 + + 116 blk_time_inspection: TK_TIME TK_INSPECTION $@39 time_inspection . + + $default reduce using rule 116 (blk_time_inspection) + + +State 49 + + 8 blk_lenght: TK_LENGTH TK_UNITY TK_ATTRIB TK_ID $@2 semi_colon . + + $default reduce using rule 8 (blk_lenght) + + +State 50 + + 11 blk_time: TK_TIME TK_UNITY TK_ATTRIB TK_ID $@3 . semi_colon + + TK_SEMICOLON shift, and go to state 19 + + $default reduce using rule 14 (semi_colon) + + semi_colon go to state 55 + + +State 51 + + 25 blk_place: TK_PLACE TK_ID $@6 . TK_LEFT_PARENTHESIS blk_place_type TK_RIGHT_PARENTHESIS blk_function $@7 blk_initial_marking blk_steady_marking blk_place_arcs blk_place2 + + TK_LEFT_PARENTHESIS shift, and go to state 56 + + +State 52 + + 78 blk_transition: TK_TRANSITION TK_ID . $@23 TK_LEFT_PARENTHESIS blk_transition_type TK_RIGHT_PARENTHESIS blk_transition_function $@24 blk_steady_transition_function $@25 blk_transition_arcs blk_transition2 + + $default reduce using rule 75 ($@23) + + $@23 go to state 57 + + +State 53 + + 110 controlled_events: TK_ID $@34 TK_ATTRIB . TK_LEFT_PARENTHESIS controlled_events_type TK_COMMA TK_ID $@35 TK_COMMA number $@36 TK_COMMA number $@37 TK_RIGHT_PARENTHESIS semi_colon $@38 controlled_events2 + + TK_LEFT_PARENTHESIS shift, and go to state 58 + + +State 54 + + 122 time_inspection: TK_ID $@40 . TK_ATTRIB blk_op_time number $@41 blk_op_pt $@42 semi_colon $@43 time_inspection2 + + TK_ATTRIB shift, and go to state 59 + + +State 55 + + 11 blk_time: TK_TIME TK_UNITY TK_ATTRIB TK_ID $@3 semi_colon . + + $default reduce using rule 11 (blk_time) + + +State 56 + + 25 blk_place: TK_PLACE TK_ID $@6 TK_LEFT_PARENTHESIS . blk_place_type TK_RIGHT_PARENTHESIS blk_function $@7 blk_initial_marking blk_steady_marking blk_place_arcs blk_place2 + + TK_BATCH shift, and go to state 60 + TK_CONTINUOUS shift, and go to state 61 + TK_DISCRETE shift, and go to state 62 + TK_TRIANGULAR shift, and go to state 63 + + blk_place_type go to state 64 + + +State 57 + + 78 blk_transition: TK_TRANSITION TK_ID $@23 . TK_LEFT_PARENTHESIS blk_transition_type TK_RIGHT_PARENTHESIS blk_transition_function $@24 blk_steady_transition_function $@25 blk_transition_arcs blk_transition2 + + TK_LEFT_PARENTHESIS shift, and go to state 65 + + +State 58 + + 110 controlled_events: TK_ID $@34 TK_ATTRIB TK_LEFT_PARENTHESIS . controlled_events_type TK_COMMA TK_ID $@35 TK_COMMA number $@36 TK_COMMA number $@37 TK_RIGHT_PARENTHESIS semi_colon $@38 controlled_events2 + + TK_FLOW shift, and go to state 66 + TK_SPEED shift, and go to state 67 + + controlled_events_type go to state 68 + + +State 59 + + 122 time_inspection: TK_ID $@40 TK_ATTRIB . blk_op_time number $@41 blk_op_pt $@42 semi_colon $@43 time_inspection2 + + TK_AT shift, and go to state 69 + TK_EVERY shift, and go to state 70 + + blk_op_time go to state 71 + + +State 60 + + 30 blk_place_type: TK_BATCH . + + $default reduce using rule 30 (blk_place_type) + + +State 61 + + 29 blk_place_type: TK_CONTINUOUS . + + $default reduce using rule 29 (blk_place_type) + + +State 62 + + 28 blk_place_type: TK_DISCRETE . + + $default reduce using rule 28 (blk_place_type) + + +State 63 + + 31 blk_place_type: TK_TRIANGULAR . + + $default reduce using rule 31 (blk_place_type) + + +State 64 + + 25 blk_place: TK_PLACE TK_ID $@6 TK_LEFT_PARENTHESIS blk_place_type . TK_RIGHT_PARENTHESIS blk_function $@7 blk_initial_marking blk_steady_marking blk_place_arcs blk_place2 + + TK_RIGHT_PARENTHESIS shift, and go to state 72 + + +State 65 + + 78 blk_transition: TK_TRANSITION TK_ID $@23 TK_LEFT_PARENTHESIS . blk_transition_type TK_RIGHT_PARENTHESIS blk_transition_function $@24 blk_steady_transition_function $@25 blk_transition_arcs blk_transition2 + + TK_BATCH shift, and go to state 73 + TK_CONTINUOUS shift, and go to state 74 + TK_DISCRETE shift, and go to state 75 + + blk_transition_type go to state 76 + + +State 66 + + 113 controlled_events_type: TK_FLOW . + + $default reduce using rule 113 (controlled_events_type) + + +State 67 + + 114 controlled_events_type: TK_SPEED . + + $default reduce using rule 114 (controlled_events_type) + + +State 68 + + 110 controlled_events: TK_ID $@34 TK_ATTRIB TK_LEFT_PARENTHESIS controlled_events_type . TK_COMMA TK_ID $@35 TK_COMMA number $@36 TK_COMMA number $@37 TK_RIGHT_PARENTHESIS semi_colon $@38 controlled_events2 + + TK_COMMA shift, and go to state 77 + + +State 69 + + 125 blk_op_time: TK_AT . + + $default reduce using rule 125 (blk_op_time) + + +State 70 + + 126 blk_op_time: TK_EVERY . + + $default reduce using rule 126 (blk_op_time) + + +State 71 + + 122 time_inspection: TK_ID $@40 TK_ATTRIB blk_op_time . number $@41 blk_op_pt $@42 semi_colon $@43 time_inspection2 + + TK_INTEGER shift, and go to state 78 + TK_REAL shift, and go to state 79 + TK_EXPONENT shift, and go to state 80 + + number go to state 81 + + +State 72 + + 25 blk_place: TK_PLACE TK_ID $@6 TK_LEFT_PARENTHESIS blk_place_type TK_RIGHT_PARENTHESIS . blk_function $@7 blk_initial_marking blk_steady_marking blk_place_arcs blk_place2 + + TK_FUNCTION shift, and go to state 82 + + $default reduce using rule 37 (blk_function) + + blk_function go to state 83 + + +State 73 + + 83 blk_transition_type: TK_BATCH . + + $default reduce using rule 83 (blk_transition_type) + + +State 74 + + 82 blk_transition_type: TK_CONTINUOUS . + + $default reduce using rule 82 (blk_transition_type) + + +State 75 + + 81 blk_transition_type: TK_DISCRETE . + + $default reduce using rule 81 (blk_transition_type) + + +State 76 + + 78 blk_transition: TK_TRANSITION TK_ID $@23 TK_LEFT_PARENTHESIS blk_transition_type . TK_RIGHT_PARENTHESIS blk_transition_function $@24 blk_steady_transition_function $@25 blk_transition_arcs blk_transition2 + + TK_RIGHT_PARENTHESIS shift, and go to state 84 + + +State 77 + + 110 controlled_events: TK_ID $@34 TK_ATTRIB TK_LEFT_PARENTHESIS controlled_events_type TK_COMMA . TK_ID $@35 TK_COMMA number $@36 TK_COMMA number $@37 TK_RIGHT_PARENTHESIS semi_colon $@38 controlled_events2 + + TK_ID shift, and go to state 85 + + +State 78 + + 16 number: TK_INTEGER . + + $default reduce using rule 16 (number) + + +State 79 + + 15 number: TK_REAL . + + $default reduce using rule 15 (number) + + +State 80 + + 17 number: TK_EXPONENT . + + $default reduce using rule 17 (number) + + +State 81 + + 122 time_inspection: TK_ID $@40 TK_ATTRIB blk_op_time number . $@41 blk_op_pt $@42 semi_colon $@43 time_inspection2 + + $default reduce using rule 119 ($@41) + + $@41 go to state 86 + + +State 82 + + 36 blk_function: TK_FUNCTION . $@8 TK_LEFT_PARENTHESIS number $@9 TK_COMMA number $@10 TK_COMMA number $@11 blk_triangular_place TK_RIGHT_PARENTHESIS + + $default reduce using rule 32 ($@8) + + $@8 go to state 87 + + +State 83 + + 25 blk_place: TK_PLACE TK_ID $@6 TK_LEFT_PARENTHESIS blk_place_type TK_RIGHT_PARENTHESIS blk_function . $@7 blk_initial_marking blk_steady_marking blk_place_arcs blk_place2 + + $default reduce using rule 24 ($@7) + + $@7 go to state 88 + + +State 84 + + 78 blk_transition: TK_TRANSITION TK_ID $@23 TK_LEFT_PARENTHESIS blk_transition_type TK_RIGHT_PARENTHESIS . blk_transition_function $@24 blk_steady_transition_function $@25 blk_transition_arcs blk_transition2 + + TK_FLOW shift, and go to state 89 + TK_TIMING shift, and go to state 90 + + blk_transition_function go to state 91 + + +State 85 + + 110 controlled_events: TK_ID $@34 TK_ATTRIB TK_LEFT_PARENTHESIS controlled_events_type TK_COMMA TK_ID . $@35 TK_COMMA number $@36 TK_COMMA number $@37 TK_RIGHT_PARENTHESIS semi_colon $@38 controlled_events2 + + $default reduce using rule 106 ($@35) + + $@35 go to state 92 + + +State 86 + + 122 time_inspection: TK_ID $@40 TK_ATTRIB blk_op_time number $@41 . blk_op_pt $@42 semi_colon $@43 time_inspection2 + + TK_PL_TR shift, and go to state 93 + TK_ALL shift, and go to state 94 + + blk_op_pt go to state 95 + + +State 87 + + 36 blk_function: TK_FUNCTION $@8 . TK_LEFT_PARENTHESIS number $@9 TK_COMMA number $@10 TK_COMMA number $@11 blk_triangular_place TK_RIGHT_PARENTHESIS + + TK_LEFT_PARENTHESIS shift, and go to state 96 + + +State 88 + + 25 blk_place: TK_PLACE TK_ID $@6 TK_LEFT_PARENTHESIS blk_place_type TK_RIGHT_PARENTHESIS blk_function $@7 . blk_initial_marking blk_steady_marking blk_place_arcs blk_place2 + + TK_INITIAL shift, and go to state 97 + + blk_initial_marking go to state 98 + + +State 89 + + 87 blk_transition_function: TK_FLOW . TK_LEFT_PARENTHESIS number $@27 TK_RIGHT_PARENTHESIS + + TK_LEFT_PARENTHESIS shift, and go to state 99 + + +State 90 + + 85 blk_transition_function: TK_TIMING . TK_LEFT_PARENTHESIS number $@26 TK_RIGHT_PARENTHESIS + + TK_LEFT_PARENTHESIS shift, and go to state 100 + + +State 91 + + 78 blk_transition: TK_TRANSITION TK_ID $@23 TK_LEFT_PARENTHESIS blk_transition_type TK_RIGHT_PARENTHESIS blk_transition_function . $@24 blk_steady_transition_function $@25 blk_transition_arcs blk_transition2 + + $default reduce using rule 76 ($@24) + + $@24 go to state 101 + + +State 92 + + 110 controlled_events: TK_ID $@34 TK_ATTRIB TK_LEFT_PARENTHESIS controlled_events_type TK_COMMA TK_ID $@35 . TK_COMMA number $@36 TK_COMMA number $@37 TK_RIGHT_PARENTHESIS semi_colon $@38 controlled_events2 + + TK_COMMA shift, and go to state 102 + + +State 93 + + 127 blk_op_pt: TK_PL_TR . TK_ID + + TK_ID shift, and go to state 103 + + +State 94 + + 128 blk_op_pt: TK_ALL . blk_pl_tr + + TK_PLACES shift, and go to state 104 + TK_TRANSITIONS shift, and go to state 105 + + blk_pl_tr go to state 106 + + +State 95 + + 122 time_inspection: TK_ID $@40 TK_ATTRIB blk_op_time number $@41 blk_op_pt . $@42 semi_colon $@43 time_inspection2 + + $default reduce using rule 120 ($@42) + + $@42 go to state 107 + + +State 96 + + 36 blk_function: TK_FUNCTION $@8 TK_LEFT_PARENTHESIS . number $@9 TK_COMMA number $@10 TK_COMMA number $@11 blk_triangular_place TK_RIGHT_PARENTHESIS + + TK_INTEGER shift, and go to state 78 + TK_REAL shift, and go to state 79 + TK_EXPONENT shift, and go to state 80 + + number go to state 108 + + +State 97 + + 40 blk_initial_marking: TK_INITIAL . TK_MARKING TK_LEFT_BRACKET blk_initial_marking_int TK_RIGHT_BRACKET + + TK_MARKING shift, and go to state 109 + + +State 98 + + 25 blk_place: TK_PLACE TK_ID $@6 TK_LEFT_PARENTHESIS blk_place_type TK_RIGHT_PARENTHESIS blk_function $@7 blk_initial_marking . blk_steady_marking blk_place_arcs blk_place2 + + TK_STEADY shift, and go to state 110 + + $default reduce using rule 54 (blk_steady_marking) + + blk_steady_marking go to state 111 + + +State 99 + + 87 blk_transition_function: TK_FLOW TK_LEFT_PARENTHESIS . number $@27 TK_RIGHT_PARENTHESIS + + TK_INTEGER shift, and go to state 78 + TK_REAL shift, and go to state 79 + TK_EXPONENT shift, and go to state 80 + + number go to state 112 + + +State 100 + + 85 blk_transition_function: TK_TIMING TK_LEFT_PARENTHESIS . number $@26 TK_RIGHT_PARENTHESIS + + TK_INTEGER shift, and go to state 78 + TK_REAL shift, and go to state 79 + TK_EXPONENT shift, and go to state 80 + + number go to state 113 + + +State 101 + + 78 blk_transition: TK_TRANSITION TK_ID $@23 TK_LEFT_PARENTHESIS blk_transition_type TK_RIGHT_PARENTHESIS blk_transition_function $@24 . blk_steady_transition_function $@25 blk_transition_arcs blk_transition2 + + TK_STEADY shift, and go to state 114 + + $default reduce using rule 89 (blk_steady_transition_function) + + blk_steady_transition_function go to state 115 + + +State 102 + + 110 controlled_events: TK_ID $@34 TK_ATTRIB TK_LEFT_PARENTHESIS controlled_events_type TK_COMMA TK_ID $@35 TK_COMMA . number $@36 TK_COMMA number $@37 TK_RIGHT_PARENTHESIS semi_colon $@38 controlled_events2 + + TK_INTEGER shift, and go to state 78 + TK_REAL shift, and go to state 79 + TK_EXPONENT shift, and go to state 80 + + number go to state 116 + + +State 103 + + 127 blk_op_pt: TK_PL_TR TK_ID . + + $default reduce using rule 127 (blk_op_pt) + + +State 104 + + 129 blk_pl_tr: TK_PLACES . + + $default reduce using rule 129 (blk_pl_tr) + + +State 105 + + 130 blk_pl_tr: TK_TRANSITIONS . + + $default reduce using rule 130 (blk_pl_tr) + + +State 106 + + 128 blk_op_pt: TK_ALL blk_pl_tr . + + $default reduce using rule 128 (blk_op_pt) + + +State 107 + + 122 time_inspection: TK_ID $@40 TK_ATTRIB blk_op_time number $@41 blk_op_pt $@42 . semi_colon $@43 time_inspection2 + + TK_SEMICOLON shift, and go to state 19 + + $default reduce using rule 14 (semi_colon) + + semi_colon go to state 117 + + +State 108 + + 36 blk_function: TK_FUNCTION $@8 TK_LEFT_PARENTHESIS number . $@9 TK_COMMA number $@10 TK_COMMA number $@11 blk_triangular_place TK_RIGHT_PARENTHESIS + + $default reduce using rule 33 ($@9) + + $@9 go to state 118 + + +State 109 + + 40 blk_initial_marking: TK_INITIAL TK_MARKING . TK_LEFT_BRACKET blk_initial_marking_int TK_RIGHT_BRACKET + + TK_LEFT_BRACKET shift, and go to state 119 + + +State 110 + + 53 blk_steady_marking: TK_STEADY . TK_MARKING TK_LEFT_BRACKET blk_steady_marking_int TK_RIGHT_BRACKET + + TK_MARKING shift, and go to state 120 + + +State 111 + + 25 blk_place: TK_PLACE TK_ID $@6 TK_LEFT_PARENTHESIS blk_place_type TK_RIGHT_PARENTHESIS blk_function $@7 blk_initial_marking blk_steady_marking . blk_place_arcs blk_place2 + + TK_OUTPUT shift, and go to state 121 + + $default reduce using rule 70 (blk_place_arcs) + + blk_place_arcs go to state 122 + + +State 112 + + 87 blk_transition_function: TK_FLOW TK_LEFT_PARENTHESIS number . $@27 TK_RIGHT_PARENTHESIS + + $default reduce using rule 86 ($@27) + + $@27 go to state 123 + + +State 113 + + 85 blk_transition_function: TK_TIMING TK_LEFT_PARENTHESIS number . $@26 TK_RIGHT_PARENTHESIS + + $default reduce using rule 84 ($@26) + + $@26 go to state 124 + + +State 114 + + 88 blk_steady_transition_function: TK_STEADY . blk_steady_transition_function_int + + TK_FLOW shift, and go to state 125 + TK_TIMING shift, and go to state 126 + + blk_steady_transition_function_int go to state 127 + + +State 115 + + 78 blk_transition: TK_TRANSITION TK_ID $@23 TK_LEFT_PARENTHESIS blk_transition_type TK_RIGHT_PARENTHESIS blk_transition_function $@24 blk_steady_transition_function . $@25 blk_transition_arcs blk_transition2 + + $default reduce using rule 77 ($@25) + + $@25 go to state 128 + + +State 116 + + 110 controlled_events: TK_ID $@34 TK_ATTRIB TK_LEFT_PARENTHESIS controlled_events_type TK_COMMA TK_ID $@35 TK_COMMA number . $@36 TK_COMMA number $@37 TK_RIGHT_PARENTHESIS semi_colon $@38 controlled_events2 + + $default reduce using rule 107 ($@36) + + $@36 go to state 129 + + +State 117 + + 122 time_inspection: TK_ID $@40 TK_ATTRIB blk_op_time number $@41 blk_op_pt $@42 semi_colon . $@43 time_inspection2 + + $default reduce using rule 121 ($@43) + + $@43 go to state 130 + + +State 118 + + 36 blk_function: TK_FUNCTION $@8 TK_LEFT_PARENTHESIS number $@9 . TK_COMMA number $@10 TK_COMMA number $@11 blk_triangular_place TK_RIGHT_PARENTHESIS + + TK_COMMA shift, and go to state 131 + + +State 119 + + 40 blk_initial_marking: TK_INITIAL TK_MARKING TK_LEFT_BRACKET . blk_initial_marking_int TK_RIGHT_BRACKET + + TK_INTEGER shift, and go to state 78 + TK_REAL shift, and go to state 79 + TK_EXPONENT shift, and go to state 80 + TK_LEFT_PARENTHESIS shift, and go to state 132 + + $default reduce using rule 48 (blk_batch) + + number go to state 133 + blk_initial_marking_int go to state 134 + blk_batch go to state 135 + + +State 120 + + 53 blk_steady_marking: TK_STEADY TK_MARKING . TK_LEFT_BRACKET blk_steady_marking_int TK_RIGHT_BRACKET + + TK_LEFT_BRACKET shift, and go to state 136 + + +State 121 + + 69 blk_place_arcs: TK_OUTPUT . TK_ARC TK_ID $@20 blk_place_weight $@21 blk_place_arcs2 + + TK_ARC shift, and go to state 137 + + +State 122 + + 25 blk_place: TK_PLACE TK_ID $@6 TK_LEFT_PARENTHESIS blk_place_type TK_RIGHT_PARENTHESIS blk_function $@7 blk_initial_marking blk_steady_marking blk_place_arcs . blk_place2 + + TK_PLACE shift, and go to state 35 + + $default reduce using rule 27 (blk_place2) + + blk_place go to state 138 + blk_place2 go to state 139 + + +State 123 + + 87 blk_transition_function: TK_FLOW TK_LEFT_PARENTHESIS number $@27 . TK_RIGHT_PARENTHESIS + + TK_RIGHT_PARENTHESIS shift, and go to state 140 + + +State 124 + + 85 blk_transition_function: TK_TIMING TK_LEFT_PARENTHESIS number $@26 . TK_RIGHT_PARENTHESIS + + TK_RIGHT_PARENTHESIS shift, and go to state 141 + + +State 125 + + 93 blk_steady_transition_function_int: TK_FLOW . TK_LEFT_PARENTHESIS number $@29 TK_RIGHT_PARENTHESIS + + TK_LEFT_PARENTHESIS shift, and go to state 142 + + +State 126 + + 91 blk_steady_transition_function_int: TK_TIMING . TK_LEFT_PARENTHESIS number $@28 TK_RIGHT_PARENTHESIS + + TK_LEFT_PARENTHESIS shift, and go to state 143 + + +State 127 + + 88 blk_steady_transition_function: TK_STEADY blk_steady_transition_function_int . + + $default reduce using rule 88 (blk_steady_transition_function) + + +State 128 + + 78 blk_transition: TK_TRANSITION TK_ID $@23 TK_LEFT_PARENTHESIS blk_transition_type TK_RIGHT_PARENTHESIS blk_transition_function $@24 blk_steady_transition_function $@25 . blk_transition_arcs blk_transition2 + + TK_OUTPUT shift, and go to state 144 + + $default reduce using rule 97 (blk_transition_arcs) + + blk_transition_arcs go to state 145 + + +State 129 + + 110 controlled_events: TK_ID $@34 TK_ATTRIB TK_LEFT_PARENTHESIS controlled_events_type TK_COMMA TK_ID $@35 TK_COMMA number $@36 . TK_COMMA number $@37 TK_RIGHT_PARENTHESIS semi_colon $@38 controlled_events2 + + TK_COMMA shift, and go to state 146 + + +State 130 + + 122 time_inspection: TK_ID $@40 TK_ATTRIB blk_op_time number $@41 blk_op_pt $@42 semi_colon $@43 . time_inspection2 + + TK_ID shift, and go to state 47 + + $default reduce using rule 123 (time_inspection) + + time_inspection go to state 147 + time_inspection2 go to state 148 + + +State 131 + + 36 blk_function: TK_FUNCTION $@8 TK_LEFT_PARENTHESIS number $@9 TK_COMMA . number $@10 TK_COMMA number $@11 blk_triangular_place TK_RIGHT_PARENTHESIS + + TK_INTEGER shift, and go to state 78 + TK_REAL shift, and go to state 79 + TK_EXPONENT shift, and go to state 80 + + number go to state 149 + + +State 132 + + 47 blk_batch: TK_LEFT_PARENTHESIS . number $@12 TK_COMMA number $@13 TK_COMMA number $@14 blk_triangular_batch TK_RIGHT_PARENTHESIS $@15 blk_batch2 + + TK_INTEGER shift, and go to state 78 + TK_REAL shift, and go to state 79 + TK_EXPONENT shift, and go to state 80 + + number go to state 150 + + +State 133 + + 41 blk_initial_marking_int: number . + + $default reduce using rule 41 (blk_initial_marking_int) + + +State 134 + + 40 blk_initial_marking: TK_INITIAL TK_MARKING TK_LEFT_BRACKET blk_initial_marking_int . TK_RIGHT_BRACKET + + TK_RIGHT_BRACKET shift, and go to state 151 + + +State 135 + + 42 blk_initial_marking_int: blk_batch . + + $default reduce using rule 42 (blk_initial_marking_int) + + +State 136 + + 53 blk_steady_marking: TK_STEADY TK_MARKING TK_LEFT_BRACKET . blk_steady_marking_int TK_RIGHT_BRACKET + + TK_INTEGER shift, and go to state 78 + TK_REAL shift, and go to state 79 + TK_EXPONENT shift, and go to state 80 + TK_LEFT_PARENTHESIS shift, and go to state 152 + + $default reduce using rule 62 (blk_steady_batch) + + number go to state 153 + blk_steady_marking_int go to state 154 + blk_steady_batch go to state 155 + + +State 137 + + 69 blk_place_arcs: TK_OUTPUT TK_ARC . TK_ID $@20 blk_place_weight $@21 blk_place_arcs2 + + TK_ID shift, and go to state 156 + + +State 138 + + 26 blk_place2: blk_place . + + $default reduce using rule 26 (blk_place2) + + +State 139 + + 25 blk_place: TK_PLACE TK_ID $@6 TK_LEFT_PARENTHESIS blk_place_type TK_RIGHT_PARENTHESIS blk_function $@7 blk_initial_marking blk_steady_marking blk_place_arcs blk_place2 . + + $default reduce using rule 25 (blk_place) + + +State 140 + + 87 blk_transition_function: TK_FLOW TK_LEFT_PARENTHESIS number $@27 TK_RIGHT_PARENTHESIS . + + $default reduce using rule 87 (blk_transition_function) + + +State 141 + + 85 blk_transition_function: TK_TIMING TK_LEFT_PARENTHESIS number $@26 TK_RIGHT_PARENTHESIS . + + $default reduce using rule 85 (blk_transition_function) + + +State 142 + + 93 blk_steady_transition_function_int: TK_FLOW TK_LEFT_PARENTHESIS . number $@29 TK_RIGHT_PARENTHESIS + + TK_INTEGER shift, and go to state 78 + TK_REAL shift, and go to state 79 + TK_EXPONENT shift, and go to state 80 + + number go to state 157 + + +State 143 + + 91 blk_steady_transition_function_int: TK_TIMING TK_LEFT_PARENTHESIS . number $@28 TK_RIGHT_PARENTHESIS + + TK_INTEGER shift, and go to state 78 + TK_REAL shift, and go to state 79 + TK_EXPONENT shift, and go to state 80 + + number go to state 158 + + +State 144 + + 96 blk_transition_arcs: TK_OUTPUT . TK_ARC TK_ID $@30 blk_transition_weight $@31 blk_transition_arcs2 + + TK_ARC shift, and go to state 159 + + +State 145 + + 78 blk_transition: TK_TRANSITION TK_ID $@23 TK_LEFT_PARENTHESIS blk_transition_type TK_RIGHT_PARENTHESIS blk_transition_function $@24 blk_steady_transition_function $@25 blk_transition_arcs . blk_transition2 + + TK_TRANSITION shift, and go to state 44 + + $default reduce using rule 80 (blk_transition2) + + blk_transition go to state 160 + blk_transition2 go to state 161 + + +State 146 + + 110 controlled_events: TK_ID $@34 TK_ATTRIB TK_LEFT_PARENTHESIS controlled_events_type TK_COMMA TK_ID $@35 TK_COMMA number $@36 TK_COMMA . number $@37 TK_RIGHT_PARENTHESIS semi_colon $@38 controlled_events2 + + TK_INTEGER shift, and go to state 78 + TK_REAL shift, and go to state 79 + TK_EXPONENT shift, and go to state 80 + + number go to state 162 + + +State 147 + + 124 time_inspection2: time_inspection . + + $default reduce using rule 124 (time_inspection2) + + +State 148 + + 122 time_inspection: TK_ID $@40 TK_ATTRIB blk_op_time number $@41 blk_op_pt $@42 semi_colon $@43 time_inspection2 . + + $default reduce using rule 122 (time_inspection) + + +State 149 + + 36 blk_function: TK_FUNCTION $@8 TK_LEFT_PARENTHESIS number $@9 TK_COMMA number . $@10 TK_COMMA number $@11 blk_triangular_place TK_RIGHT_PARENTHESIS + + $default reduce using rule 34 ($@10) + + $@10 go to state 163 + + +State 150 + + 47 blk_batch: TK_LEFT_PARENTHESIS number . $@12 TK_COMMA number $@13 TK_COMMA number $@14 blk_triangular_batch TK_RIGHT_PARENTHESIS $@15 blk_batch2 + + $default reduce using rule 43 ($@12) + + $@12 go to state 164 + + +State 151 + + 40 blk_initial_marking: TK_INITIAL TK_MARKING TK_LEFT_BRACKET blk_initial_marking_int TK_RIGHT_BRACKET . + + $default reduce using rule 40 (blk_initial_marking) + + +State 152 + + 61 blk_steady_batch: TK_LEFT_PARENTHESIS . number $@16 TK_COMMA number $@17 TK_COMMA number $@18 blk_steady_triangular_batch TK_RIGHT_PARENTHESIS $@19 blk_steady_batch2 + + TK_INTEGER shift, and go to state 78 + TK_REAL shift, and go to state 79 + TK_EXPONENT shift, and go to state 80 + + number go to state 165 + + +State 153 + + 55 blk_steady_marking_int: number . + + $default reduce using rule 55 (blk_steady_marking_int) + + +State 154 + + 53 blk_steady_marking: TK_STEADY TK_MARKING TK_LEFT_BRACKET blk_steady_marking_int . TK_RIGHT_BRACKET + + TK_RIGHT_BRACKET shift, and go to state 166 + + +State 155 + + 56 blk_steady_marking_int: blk_steady_batch . + + $default reduce using rule 56 (blk_steady_marking_int) + + +State 156 + + 69 blk_place_arcs: TK_OUTPUT TK_ARC TK_ID . $@20 blk_place_weight $@21 blk_place_arcs2 + + $default reduce using rule 67 ($@20) + + $@20 go to state 167 + + +State 157 + + 93 blk_steady_transition_function_int: TK_FLOW TK_LEFT_PARENTHESIS number . $@29 TK_RIGHT_PARENTHESIS + + $default reduce using rule 92 ($@29) + + $@29 go to state 168 + + +State 158 + + 91 blk_steady_transition_function_int: TK_TIMING TK_LEFT_PARENTHESIS number . $@28 TK_RIGHT_PARENTHESIS + + $default reduce using rule 90 ($@28) + + $@28 go to state 169 + + +State 159 + + 96 blk_transition_arcs: TK_OUTPUT TK_ARC . TK_ID $@30 blk_transition_weight $@31 blk_transition_arcs2 + + TK_ID shift, and go to state 170 + + +State 160 + + 79 blk_transition2: blk_transition . + + $default reduce using rule 79 (blk_transition2) + + +State 161 + + 78 blk_transition: TK_TRANSITION TK_ID $@23 TK_LEFT_PARENTHESIS blk_transition_type TK_RIGHT_PARENTHESIS blk_transition_function $@24 blk_steady_transition_function $@25 blk_transition_arcs blk_transition2 . + + $default reduce using rule 78 (blk_transition) + + +State 162 + + 110 controlled_events: TK_ID $@34 TK_ATTRIB TK_LEFT_PARENTHESIS controlled_events_type TK_COMMA TK_ID $@35 TK_COMMA number $@36 TK_COMMA number . $@37 TK_RIGHT_PARENTHESIS semi_colon $@38 controlled_events2 + + $default reduce using rule 108 ($@37) + + $@37 go to state 171 + + +State 163 + + 36 blk_function: TK_FUNCTION $@8 TK_LEFT_PARENTHESIS number $@9 TK_COMMA number $@10 . TK_COMMA number $@11 blk_triangular_place TK_RIGHT_PARENTHESIS + + TK_COMMA shift, and go to state 172 + + +State 164 + + 47 blk_batch: TK_LEFT_PARENTHESIS number $@12 . TK_COMMA number $@13 TK_COMMA number $@14 blk_triangular_batch TK_RIGHT_PARENTHESIS $@15 blk_batch2 + + TK_COMMA shift, and go to state 173 + + +State 165 + + 61 blk_steady_batch: TK_LEFT_PARENTHESIS number . $@16 TK_COMMA number $@17 TK_COMMA number $@18 blk_steady_triangular_batch TK_RIGHT_PARENTHESIS $@19 blk_steady_batch2 + + $default reduce using rule 57 ($@16) + + $@16 go to state 174 + + +State 166 + + 53 blk_steady_marking: TK_STEADY TK_MARKING TK_LEFT_BRACKET blk_steady_marking_int TK_RIGHT_BRACKET . + + $default reduce using rule 53 (blk_steady_marking) + + +State 167 + + 69 blk_place_arcs: TK_OUTPUT TK_ARC TK_ID $@20 . blk_place_weight $@21 blk_place_arcs2 + + TK_LEFT_PARENTHESIS shift, and go to state 175 + + $default reduce using rule 74 (blk_place_weight) + + blk_place_weight go to state 176 + + +State 168 + + 93 blk_steady_transition_function_int: TK_FLOW TK_LEFT_PARENTHESIS number $@29 . TK_RIGHT_PARENTHESIS + + TK_RIGHT_PARENTHESIS shift, and go to state 177 + + +State 169 + + 91 blk_steady_transition_function_int: TK_TIMING TK_LEFT_PARENTHESIS number $@28 . TK_RIGHT_PARENTHESIS + + TK_RIGHT_PARENTHESIS shift, and go to state 178 + + +State 170 + + 96 blk_transition_arcs: TK_OUTPUT TK_ARC TK_ID . $@30 blk_transition_weight $@31 blk_transition_arcs2 + + $default reduce using rule 94 ($@30) + + $@30 go to state 179 + + +State 171 + + 110 controlled_events: TK_ID $@34 TK_ATTRIB TK_LEFT_PARENTHESIS controlled_events_type TK_COMMA TK_ID $@35 TK_COMMA number $@36 TK_COMMA number $@37 . TK_RIGHT_PARENTHESIS semi_colon $@38 controlled_events2 + + TK_RIGHT_PARENTHESIS shift, and go to state 180 + + +State 172 + + 36 blk_function: TK_FUNCTION $@8 TK_LEFT_PARENTHESIS number $@9 TK_COMMA number $@10 TK_COMMA . number $@11 blk_triangular_place TK_RIGHT_PARENTHESIS + + TK_INTEGER shift, and go to state 78 + TK_REAL shift, and go to state 79 + TK_EXPONENT shift, and go to state 80 + + number go to state 181 + + +State 173 + + 47 blk_batch: TK_LEFT_PARENTHESIS number $@12 TK_COMMA . number $@13 TK_COMMA number $@14 blk_triangular_batch TK_RIGHT_PARENTHESIS $@15 blk_batch2 + + TK_INTEGER shift, and go to state 78 + TK_REAL shift, and go to state 79 + TK_EXPONENT shift, and go to state 80 + + number go to state 182 + + +State 174 + + 61 blk_steady_batch: TK_LEFT_PARENTHESIS number $@16 . TK_COMMA number $@17 TK_COMMA number $@18 blk_steady_triangular_batch TK_RIGHT_PARENTHESIS $@19 blk_steady_batch2 + + TK_COMMA shift, and go to state 183 + + +State 175 + + 73 blk_place_weight: TK_LEFT_PARENTHESIS . number $@22 TK_RIGHT_PARENTHESIS + + TK_INTEGER shift, and go to state 78 + TK_REAL shift, and go to state 79 + TK_EXPONENT shift, and go to state 80 + + number go to state 184 + + +State 176 + + 69 blk_place_arcs: TK_OUTPUT TK_ARC TK_ID $@20 blk_place_weight . $@21 blk_place_arcs2 + + $default reduce using rule 68 ($@21) + + $@21 go to state 185 + + +State 177 + + 93 blk_steady_transition_function_int: TK_FLOW TK_LEFT_PARENTHESIS number $@29 TK_RIGHT_PARENTHESIS . + + $default reduce using rule 93 (blk_steady_transition_function_int) + + +State 178 + + 91 blk_steady_transition_function_int: TK_TIMING TK_LEFT_PARENTHESIS number $@28 TK_RIGHT_PARENTHESIS . + + $default reduce using rule 91 (blk_steady_transition_function_int) + + +State 179 + + 96 blk_transition_arcs: TK_OUTPUT TK_ARC TK_ID $@30 . blk_transition_weight $@31 blk_transition_arcs2 + + TK_LEFT_PARENTHESIS shift, and go to state 186 + + $default reduce using rule 101 (blk_transition_weight) + + blk_transition_weight go to state 187 + + +State 180 + + 110 controlled_events: TK_ID $@34 TK_ATTRIB TK_LEFT_PARENTHESIS controlled_events_type TK_COMMA TK_ID $@35 TK_COMMA number $@36 TK_COMMA number $@37 TK_RIGHT_PARENTHESIS . semi_colon $@38 controlled_events2 + + TK_SEMICOLON shift, and go to state 19 + + $default reduce using rule 14 (semi_colon) + + semi_colon go to state 188 + + +State 181 + + 36 blk_function: TK_FUNCTION $@8 TK_LEFT_PARENTHESIS number $@9 TK_COMMA number $@10 TK_COMMA number . $@11 blk_triangular_place TK_RIGHT_PARENTHESIS + + $default reduce using rule 35 ($@11) + + $@11 go to state 189 + + +State 182 + + 47 blk_batch: TK_LEFT_PARENTHESIS number $@12 TK_COMMA number . $@13 TK_COMMA number $@14 blk_triangular_batch TK_RIGHT_PARENTHESIS $@15 blk_batch2 + + $default reduce using rule 44 ($@13) + + $@13 go to state 190 + + +State 183 + + 61 blk_steady_batch: TK_LEFT_PARENTHESIS number $@16 TK_COMMA . number $@17 TK_COMMA number $@18 blk_steady_triangular_batch TK_RIGHT_PARENTHESIS $@19 blk_steady_batch2 + + TK_INTEGER shift, and go to state 78 + TK_REAL shift, and go to state 79 + TK_EXPONENT shift, and go to state 80 + + number go to state 191 + + +State 184 + + 73 blk_place_weight: TK_LEFT_PARENTHESIS number . $@22 TK_RIGHT_PARENTHESIS + + $default reduce using rule 72 ($@22) + + $@22 go to state 192 + + +State 185 + + 69 blk_place_arcs: TK_OUTPUT TK_ARC TK_ID $@20 blk_place_weight $@21 . blk_place_arcs2 + + TK_OUTPUT shift, and go to state 121 + + $default reduce using rule 70 (blk_place_arcs) + + blk_place_arcs go to state 193 + blk_place_arcs2 go to state 194 + + +State 186 + + 100 blk_transition_weight: TK_LEFT_PARENTHESIS . number $@32 TK_RIGHT_PARENTHESIS + + TK_INTEGER shift, and go to state 78 + TK_REAL shift, and go to state 79 + TK_EXPONENT shift, and go to state 80 + + number go to state 195 + + +State 187 + + 96 blk_transition_arcs: TK_OUTPUT TK_ARC TK_ID $@30 blk_transition_weight . $@31 blk_transition_arcs2 + + $default reduce using rule 95 ($@31) + + $@31 go to state 196 + + +State 188 + + 110 controlled_events: TK_ID $@34 TK_ATTRIB TK_LEFT_PARENTHESIS controlled_events_type TK_COMMA TK_ID $@35 TK_COMMA number $@36 TK_COMMA number $@37 TK_RIGHT_PARENTHESIS semi_colon . $@38 controlled_events2 + + $default reduce using rule 109 ($@38) + + $@38 go to state 197 + + +State 189 + + 36 blk_function: TK_FUNCTION $@8 TK_LEFT_PARENTHESIS number $@9 TK_COMMA number $@10 TK_COMMA number $@11 . blk_triangular_place TK_RIGHT_PARENTHESIS + + TK_COMMA shift, and go to state 198 + + $default reduce using rule 39 (blk_triangular_place) + + blk_triangular_place go to state 199 + + +State 190 + + 47 blk_batch: TK_LEFT_PARENTHESIS number $@12 TK_COMMA number $@13 . TK_COMMA number $@14 blk_triangular_batch TK_RIGHT_PARENTHESIS $@15 blk_batch2 + + TK_COMMA shift, and go to state 200 + + +State 191 + + 61 blk_steady_batch: TK_LEFT_PARENTHESIS number $@16 TK_COMMA number . $@17 TK_COMMA number $@18 blk_steady_triangular_batch TK_RIGHT_PARENTHESIS $@19 blk_steady_batch2 + + $default reduce using rule 58 ($@17) + + $@17 go to state 201 + + +State 192 + + 73 blk_place_weight: TK_LEFT_PARENTHESIS number $@22 . TK_RIGHT_PARENTHESIS + + TK_RIGHT_PARENTHESIS shift, and go to state 202 + + +State 193 + + 71 blk_place_arcs2: blk_place_arcs . + + $default reduce using rule 71 (blk_place_arcs2) + + +State 194 + + 69 blk_place_arcs: TK_OUTPUT TK_ARC TK_ID $@20 blk_place_weight $@21 blk_place_arcs2 . + + $default reduce using rule 69 (blk_place_arcs) + + +State 195 + + 100 blk_transition_weight: TK_LEFT_PARENTHESIS number . $@32 TK_RIGHT_PARENTHESIS + + $default reduce using rule 99 ($@32) + + $@32 go to state 203 + + +State 196 + + 96 blk_transition_arcs: TK_OUTPUT TK_ARC TK_ID $@30 blk_transition_weight $@31 . blk_transition_arcs2 + + TK_OUTPUT shift, and go to state 144 + + $default reduce using rule 97 (blk_transition_arcs) + + blk_transition_arcs go to state 204 + blk_transition_arcs2 go to state 205 + + +State 197 + + 110 controlled_events: TK_ID $@34 TK_ATTRIB TK_LEFT_PARENTHESIS controlled_events_type TK_COMMA TK_ID $@35 TK_COMMA number $@36 TK_COMMA number $@37 TK_RIGHT_PARENTHESIS semi_colon $@38 . controlled_events2 + + TK_ID shift, and go to state 38 + + $default reduce using rule 111 (controlled_events) + + controlled_events go to state 206 + controlled_events2 go to state 207 + + +State 198 + + 38 blk_triangular_place: TK_COMMA . number + + TK_INTEGER shift, and go to state 78 + TK_REAL shift, and go to state 79 + TK_EXPONENT shift, and go to state 80 + + number go to state 208 + + +State 199 + + 36 blk_function: TK_FUNCTION $@8 TK_LEFT_PARENTHESIS number $@9 TK_COMMA number $@10 TK_COMMA number $@11 blk_triangular_place . TK_RIGHT_PARENTHESIS + + TK_RIGHT_PARENTHESIS shift, and go to state 209 + + +State 200 + + 47 blk_batch: TK_LEFT_PARENTHESIS number $@12 TK_COMMA number $@13 TK_COMMA . number $@14 blk_triangular_batch TK_RIGHT_PARENTHESIS $@15 blk_batch2 + + TK_INTEGER shift, and go to state 78 + TK_REAL shift, and go to state 79 + TK_EXPONENT shift, and go to state 80 + + number go to state 210 + + +State 201 + + 61 blk_steady_batch: TK_LEFT_PARENTHESIS number $@16 TK_COMMA number $@17 . TK_COMMA number $@18 blk_steady_triangular_batch TK_RIGHT_PARENTHESIS $@19 blk_steady_batch2 + + TK_COMMA shift, and go to state 211 + + +State 202 + + 73 blk_place_weight: TK_LEFT_PARENTHESIS number $@22 TK_RIGHT_PARENTHESIS . + + $default reduce using rule 73 (blk_place_weight) + + +State 203 + + 100 blk_transition_weight: TK_LEFT_PARENTHESIS number $@32 . TK_RIGHT_PARENTHESIS + + TK_RIGHT_PARENTHESIS shift, and go to state 212 + + +State 204 + + 98 blk_transition_arcs2: blk_transition_arcs . + + $default reduce using rule 98 (blk_transition_arcs2) + + +State 205 + + 96 blk_transition_arcs: TK_OUTPUT TK_ARC TK_ID $@30 blk_transition_weight $@31 blk_transition_arcs2 . + + $default reduce using rule 96 (blk_transition_arcs) + + +State 206 + + 112 controlled_events2: controlled_events . + + $default reduce using rule 112 (controlled_events2) + + +State 207 + + 110 controlled_events: TK_ID $@34 TK_ATTRIB TK_LEFT_PARENTHESIS controlled_events_type TK_COMMA TK_ID $@35 TK_COMMA number $@36 TK_COMMA number $@37 TK_RIGHT_PARENTHESIS semi_colon $@38 controlled_events2 . + + $default reduce using rule 110 (controlled_events) + + +State 208 + + 38 blk_triangular_place: TK_COMMA number . + + $default reduce using rule 38 (blk_triangular_place) + + +State 209 + + 36 blk_function: TK_FUNCTION $@8 TK_LEFT_PARENTHESIS number $@9 TK_COMMA number $@10 TK_COMMA number $@11 blk_triangular_place TK_RIGHT_PARENTHESIS . + + $default reduce using rule 36 (blk_function) + + +State 210 + + 47 blk_batch: TK_LEFT_PARENTHESIS number $@12 TK_COMMA number $@13 TK_COMMA number . $@14 blk_triangular_batch TK_RIGHT_PARENTHESIS $@15 blk_batch2 + + $default reduce using rule 45 ($@14) + + $@14 go to state 213 + + +State 211 + + 61 blk_steady_batch: TK_LEFT_PARENTHESIS number $@16 TK_COMMA number $@17 TK_COMMA . number $@18 blk_steady_triangular_batch TK_RIGHT_PARENTHESIS $@19 blk_steady_batch2 + + TK_INTEGER shift, and go to state 78 + TK_REAL shift, and go to state 79 + TK_EXPONENT shift, and go to state 80 + + number go to state 214 + + +State 212 + + 100 blk_transition_weight: TK_LEFT_PARENTHESIS number $@32 TK_RIGHT_PARENTHESIS . + + $default reduce using rule 100 (blk_transition_weight) + + +State 213 + + 47 blk_batch: TK_LEFT_PARENTHESIS number $@12 TK_COMMA number $@13 TK_COMMA number $@14 . blk_triangular_batch TK_RIGHT_PARENTHESIS $@15 blk_batch2 + + TK_COMMA shift, and go to state 215 + + $default reduce using rule 52 (blk_triangular_batch) + + blk_triangular_batch go to state 216 + + +State 214 + + 61 blk_steady_batch: TK_LEFT_PARENTHESIS number $@16 TK_COMMA number $@17 TK_COMMA number . $@18 blk_steady_triangular_batch TK_RIGHT_PARENTHESIS $@19 blk_steady_batch2 + + $default reduce using rule 59 ($@18) + + $@18 go to state 217 + + +State 215 + + 51 blk_triangular_batch: TK_COMMA . number + + TK_INTEGER shift, and go to state 78 + TK_REAL shift, and go to state 79 + TK_EXPONENT shift, and go to state 80 + + number go to state 218 + + +State 216 + + 47 blk_batch: TK_LEFT_PARENTHESIS number $@12 TK_COMMA number $@13 TK_COMMA number $@14 blk_triangular_batch . TK_RIGHT_PARENTHESIS $@15 blk_batch2 + + TK_RIGHT_PARENTHESIS shift, and go to state 219 + + +State 217 + + 61 blk_steady_batch: TK_LEFT_PARENTHESIS number $@16 TK_COMMA number $@17 TK_COMMA number $@18 . blk_steady_triangular_batch TK_RIGHT_PARENTHESIS $@19 blk_steady_batch2 + + TK_COMMA shift, and go to state 220 + + $default reduce using rule 66 (blk_steady_triangular_batch) + + blk_steady_triangular_batch go to state 221 + + +State 218 + + 51 blk_triangular_batch: TK_COMMA number . + + $default reduce using rule 51 (blk_triangular_batch) + + +State 219 + + 47 blk_batch: TK_LEFT_PARENTHESIS number $@12 TK_COMMA number $@13 TK_COMMA number $@14 blk_triangular_batch TK_RIGHT_PARENTHESIS . $@15 blk_batch2 + + $default reduce using rule 46 ($@15) + + $@15 go to state 222 + + +State 220 + + 65 blk_steady_triangular_batch: TK_COMMA . number + + TK_INTEGER shift, and go to state 78 + TK_REAL shift, and go to state 79 + TK_EXPONENT shift, and go to state 80 + + number go to state 223 + + +State 221 + + 61 blk_steady_batch: TK_LEFT_PARENTHESIS number $@16 TK_COMMA number $@17 TK_COMMA number $@18 blk_steady_triangular_batch . TK_RIGHT_PARENTHESIS $@19 blk_steady_batch2 + + TK_RIGHT_PARENTHESIS shift, and go to state 224 + + +State 222 + + 47 blk_batch: TK_LEFT_PARENTHESIS number $@12 TK_COMMA number $@13 TK_COMMA number $@14 blk_triangular_batch TK_RIGHT_PARENTHESIS $@15 . blk_batch2 + + TK_COMMA shift, and go to state 225 + + $default reduce using rule 50 (blk_batch2) + + blk_batch2 go to state 226 + + +State 223 + + 65 blk_steady_triangular_batch: TK_COMMA number . + + $default reduce using rule 65 (blk_steady_triangular_batch) + + +State 224 + + 61 blk_steady_batch: TK_LEFT_PARENTHESIS number $@16 TK_COMMA number $@17 TK_COMMA number $@18 blk_steady_triangular_batch TK_RIGHT_PARENTHESIS . $@19 blk_steady_batch2 + + $default reduce using rule 60 ($@19) + + $@19 go to state 227 + + +State 225 + + 49 blk_batch2: TK_COMMA . blk_batch + + TK_LEFT_PARENTHESIS shift, and go to state 132 + + $default reduce using rule 48 (blk_batch) + + blk_batch go to state 228 + + +State 226 + + 47 blk_batch: TK_LEFT_PARENTHESIS number $@12 TK_COMMA number $@13 TK_COMMA number $@14 blk_triangular_batch TK_RIGHT_PARENTHESIS $@15 blk_batch2 . + + $default reduce using rule 47 (blk_batch) + + +State 227 + + 61 blk_steady_batch: TK_LEFT_PARENTHESIS number $@16 TK_COMMA number $@17 TK_COMMA number $@18 blk_steady_triangular_batch TK_RIGHT_PARENTHESIS $@19 . blk_steady_batch2 + + TK_COMMA shift, and go to state 229 + + $default reduce using rule 64 (blk_steady_batch2) + + blk_steady_batch2 go to state 230 + + +State 228 + + 49 blk_batch2: TK_COMMA blk_batch . + + $default reduce using rule 49 (blk_batch2) + + +State 229 + + 63 blk_steady_batch2: TK_COMMA . blk_steady_batch + + TK_LEFT_PARENTHESIS shift, and go to state 152 + + $default reduce using rule 62 (blk_steady_batch) + + blk_steady_batch go to state 231 + + +State 230 + + 61 blk_steady_batch: TK_LEFT_PARENTHESIS number $@16 TK_COMMA number $@17 TK_COMMA number $@18 blk_steady_triangular_batch TK_RIGHT_PARENTHESIS $@19 blk_steady_batch2 . + + $default reduce using rule 61 (blk_steady_batch) + + +State 231 + + 63 blk_steady_batch2: TK_COMMA blk_steady_batch . + + $default reduce using rule 63 (blk_steady_batch2) diff --git a/src/interf/y.tab.cpp b/src/interf/y.tab.cpp new file mode 100644 index 0000000000000000000000000000000000000000..b91798b19c642d765deec7141c109d0803888a66 --- /dev/null +++ b/src/interf/y.tab.cpp @@ -0,0 +1,2642 @@ +/* A Bison parser, made by GNU Bison 3.5.1. */ + +/* Bison implementation for Yacc-like parsers in C + + Copyright (C) 1984, 1989-1990, 2000-2015, 2018-2020 Free Software Foundation, + Inc. + + This program is free software: you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation, either version 3 of the License, or + (at your option) any later version. + + This program is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with this program. If not, see <http://www.gnu.org/licenses/>. */ + +/* As a special exception, you may create a larger work that contains + part or all of the Bison parser skeleton and distribute that work + under terms of your choice, so long as that work isn't itself a + parser generator using the skeleton or a modified version thereof + as a parser skeleton. Alternatively, if you modify or redistribute + the parser skeleton itself, you may (at your option) remove this + special exception, which will cause the skeleton and the resulting + Bison output files to be licensed under the GNU General Public + License without this special exception. + + This special exception was added by the Free Software Foundation in + version 2.2 of Bison. */ + +/* C LALR(1) parser skeleton written by Richard Stallman, by + simplifying the original so-called "semantic" parser. */ + +/* All symbols defined below should begin with yy or YY, to avoid + infringing on user name space. This should be done even for local + variables, as they might otherwise be expanded by user macros. + There are some unavoidable exceptions within include files to + define necessary library symbols; they are noted "INFRINGES ON + USER NAME SPACE" below. */ + +/* Undocumented macros, especially those whose name start with YY_, + are private implementation details. Do not rely on them. */ + +/* Identify Bison output. */ +#define YYBISON 1 + +/* Bison version. */ +#define YYBISON_VERSION "3.5.1" + +/* Skeleton name. */ +#define YYSKELETON_NAME "yacc.c" + +/* Pure parsers. */ +#define YYPURE 0 + +/* Push parsers. */ +#define YYPUSH 0 + +/* Pull parsers. */ +#define YYPULL 1 + + + + +/* First part of user prologue. */ +#line 1 "src/interf/glc.y" + +//====================================================================================// +// // +// Parser and Semantic Analysis // +// // +//====================================================================================// +// This File: glc.y Tool: YACC // +// Software: SIMULEAU // +//====================================================================================// +// Creation: 15/apr/16 by: Leonardo.Brenner@lsis.org // +// Last Change: 15/apr/16 by: Leonardo.Brenner@lsis.org // +//====================================================================================// +// YACC is a general-purpose parser generator that converts a context-free grammar // +// a C program.In this module are make the actions to generate the internal SAN's // +// tables and the others functionalities of this textual interface for PEPS. // +//====================================================================================// +#include "bpnfile.h" +#include "simuleau.h" + +//====================================================================================// +// Global variables // +//====================================================================================// + +extern BPN *bpn; // Network structure +extern Schedule *schedule; // schedule structure + +int not_error = 1; +int is_integer = 1; + +int tour; // Set the times that the parser was called, the first to count the number + // of places, the number of transitions and others + +//====================================================================================// +// Variables // +//====================================================================================// + + int discreteplaces; // number of discrete places + int continuousplaces; // number of continuous places + int batchplaces; // number of batch places + int triangularplaces; // number of triangular batch places + + int currentdiscreteplace; // index of the current discrete place used to add place + int currentcontinuousplace; // index of the current continuous place + int currentbatchplace; // index of the current batch place + int currenttriangularplace; // index of the current triangular batch place + + int discretetransitions; // number of discrete transitions + int continuoustransitions; // number of continuous transitions + int batchtransitions; // number of batch transitions + + int currentdiscretetransition; // index of the current discrete place used to add place + int currentcontinuoustransition;// index of the current continuous place + int currentbatchtransition; // index of the current batch place + + place_id idplacenumber; // number of the place id + simuleau_name idplace; // name of the place id + place_type ptype; // place type + double pdensity; // place density + double pspeed; // place speed + double plength; // place length + double pflow; // place flow + + double bdensity; // batch density + double bspeed; // batch speed + double blength; // batch length + double bposition; // batch position + + trans_id idtransitionnumber; // number of the transition id + simuleau_name idtransition; // name of the transition id + trans_type ttype; // transition type + double ttime; // time of the discrete transitions + double tsteadytime; // steady time of the discrete transitions + double tflow; // flow of the continuous and batch transitions + double tsteadyflow; // steady flow of the continuous and batch transitions + + double arcweight; // arc weight + + simuleau_name idcevent; // name of the controlled event + ev_type cetype; // type of the controlled event + simuleau_name idnode; // name of the place or transition + double cedate; // controlled event date + double cevalue; // new value of the flow/speed + + simuleau_name idbreakpoint; // name of the breakpoint + breakpoint_type bptype; // type of the breakpoint (at (?) or every (*)) + double bpdate; // date or frequency + + +//====================================================================================// +// Parser variables // +//====================================================================================// + +extern int yynerrs; // Variable of the YACC generator to count the number of errors. +extern int yylineno; // Variable of the YACC generator to count the current line + +extern int yylex(void); // Get the next token +extern void yyrestart(FILE *input_file); +extern char *yytext; +extern FILE *yyin; // Input file + + +//====================================================================================// +// Function errors // +//====================================================================================// +// These functions analysis which error occurred and put the error into a message // +// more specific. // +//====================================================================================// + + +//==================================================================================== +// Function that YACC use to put syntatic message errors +//==================================================================================== +extern void yyerror(string s) +{ + yynerrs++; + not_error = 0; + Syntatic_Error(yynerrs, yylineno, s, yytext); +} + +//==================================================================================== +// Function to put semantic error messages +//==================================================================================== +void type_error(char* text, const char* error_number) +{ + yynerrs++; + not_error = 0; + Semantic_Error_YACC(yynerrs, yylineno, text, error_number); +} + + + +#line 202 "src/interf/y.tab.cpp" + +# ifndef YY_CAST +# ifdef __cplusplus +# define YY_CAST(Type, Val) static_cast<Type> (Val) +# define YY_REINTERPRET_CAST(Type, Val) reinterpret_cast<Type> (Val) +# else +# define YY_CAST(Type, Val) ((Type) (Val)) +# define YY_REINTERPRET_CAST(Type, Val) ((Type) (Val)) +# endif +# endif +# ifndef YY_NULLPTR +# if defined __cplusplus +# if 201103L <= __cplusplus +# define YY_NULLPTR nullptr +# else +# define YY_NULLPTR 0 +# endif +# else +# define YY_NULLPTR ((void*)0) +# endif +# endif + +/* Enabling verbose error messages. */ +#ifdef YYERROR_VERBOSE +# undef YYERROR_VERBOSE +# define YYERROR_VERBOSE 1 +#else +# define YYERROR_VERBOSE 0 +#endif + +/* Use api.header.include to #include this header + instead of duplicating it here. */ +#ifndef YY_YY_SRC_INTERF_Y_TAB_HPP_INCLUDED +# define YY_YY_SRC_INTERF_Y_TAB_HPP_INCLUDED +/* Debug traces. */ +#ifndef YYDEBUG +# define YYDEBUG 1 +#endif +#if YYDEBUG +extern int yydebug; +#endif + +/* Token type. */ +#ifndef YYTOKENTYPE +# define YYTOKENTYPE + enum yytokentype + { + TK_ARC = 258, + TK_BATCH = 259, + TK_CONTINUOUS = 260, + TK_CONTROLLED = 261, + TK_DESCRIPTION = 262, + TK_DISCRETE = 263, + TK_EVENTS = 264, + TK_FLOW = 265, + TK_FUNCTION = 266, + TK_INITIAL = 267, + TK_INSPECTION = 268, + TK_LENGTH = 269, + TK_MARKING = 270, + TK_MODEL = 271, + TK_NETWORK = 272, + TK_OUTPUT = 273, + TK_PLACE = 274, + TK_PLACES = 275, + TK_SPEED = 276, + TK_STEADY = 277, + TK_TIME = 278, + TK_TIMING = 279, + TK_TRANSITION = 280, + TK_TRANSITIONS = 281, + TK_TRIANGULAR = 282, + TK_UNITY = 283, + TK_ID = 284, + TK_INTEGER = 285, + TK_REAL = 286, + TK_EXPONENT = 287, + TK_AT = 288, + TK_EVERY = 289, + TK_LEFT_BRACKET = 290, + TK_RIGHT_BRACKET = 291, + TK_PL_TR = 292, + TK_ALL = 293, + TK_LEFT_PARENTHESIS = 294, + TK_RIGHT_PARENTHESIS = 295, + TK_LEFT_SQUARE_BRACKET = 296, + TK_RIGHT_SQUARE_BRACKET = 297, + TK_SEMICOLON = 298, + TK_COMMA = 299, + TK_ATTRIB = 300, + TK_COLON = 301 + }; +#endif +/* Tokens. */ +#define TK_ARC 258 +#define TK_BATCH 259 +#define TK_CONTINUOUS 260 +#define TK_CONTROLLED 261 +#define TK_DESCRIPTION 262 +#define TK_DISCRETE 263 +#define TK_EVENTS 264 +#define TK_FLOW 265 +#define TK_FUNCTION 266 +#define TK_INITIAL 267 +#define TK_INSPECTION 268 +#define TK_LENGTH 269 +#define TK_MARKING 270 +#define TK_MODEL 271 +#define TK_NETWORK 272 +#define TK_OUTPUT 273 +#define TK_PLACE 274 +#define TK_PLACES 275 +#define TK_SPEED 276 +#define TK_STEADY 277 +#define TK_TIME 278 +#define TK_TIMING 279 +#define TK_TRANSITION 280 +#define TK_TRANSITIONS 281 +#define TK_TRIANGULAR 282 +#define TK_UNITY 283 +#define TK_ID 284 +#define TK_INTEGER 285 +#define TK_REAL 286 +#define TK_EXPONENT 287 +#define TK_AT 288 +#define TK_EVERY 289 +#define TK_LEFT_BRACKET 290 +#define TK_RIGHT_BRACKET 291 +#define TK_PL_TR 292 +#define TK_ALL 293 +#define TK_LEFT_PARENTHESIS 294 +#define TK_RIGHT_PARENTHESIS 295 +#define TK_LEFT_SQUARE_BRACKET 296 +#define TK_RIGHT_SQUARE_BRACKET 297 +#define TK_SEMICOLON 298 +#define TK_COMMA 299 +#define TK_ATTRIB 300 +#define TK_COLON 301 + +/* Value type. */ +#if ! defined YYSTYPE && ! defined YYSTYPE_IS_DECLARED +typedef int YYSTYPE; +# define YYSTYPE_IS_TRIVIAL 1 +# define YYSTYPE_IS_DECLARED 1 +#endif + + +extern YYSTYPE yylval; + +int yyparse (void); + +#endif /* !YY_YY_SRC_INTERF_Y_TAB_HPP_INCLUDED */ + + + +#ifdef short +# undef short +#endif + +/* On compilers that do not define __PTRDIFF_MAX__ etc., make sure + <limits.h> and (if available) <stdint.h> are included + so that the code can choose integer types of a good width. */ + +#ifndef __PTRDIFF_MAX__ +# include <limits.h> /* INFRINGES ON USER NAME SPACE */ +# if defined __STDC_VERSION__ && 199901 <= __STDC_VERSION__ +# include <stdint.h> /* INFRINGES ON USER NAME SPACE */ +# define YY_STDINT_H +# endif +#endif + +/* Narrow types that promote to a signed type and that can represent a + signed or unsigned integer of at least N bits. In tables they can + save space and decrease cache pressure. Promoting to a signed type + helps avoid bugs in integer arithmetic. */ + +#ifdef __INT_LEAST8_MAX__ +typedef __INT_LEAST8_TYPE__ yytype_int8; +#elif defined YY_STDINT_H +typedef int_least8_t yytype_int8; +#else +typedef signed char yytype_int8; +#endif + +#ifdef __INT_LEAST16_MAX__ +typedef __INT_LEAST16_TYPE__ yytype_int16; +#elif defined YY_STDINT_H +typedef int_least16_t yytype_int16; +#else +typedef short yytype_int16; +#endif + +#if defined __UINT_LEAST8_MAX__ && __UINT_LEAST8_MAX__ <= __INT_MAX__ +typedef __UINT_LEAST8_TYPE__ yytype_uint8; +#elif (!defined __UINT_LEAST8_MAX__ && defined YY_STDINT_H \ + && UINT_LEAST8_MAX <= INT_MAX) +typedef uint_least8_t yytype_uint8; +#elif !defined __UINT_LEAST8_MAX__ && UCHAR_MAX <= INT_MAX +typedef unsigned char yytype_uint8; +#else +typedef short yytype_uint8; +#endif + +#if defined __UINT_LEAST16_MAX__ && __UINT_LEAST16_MAX__ <= __INT_MAX__ +typedef __UINT_LEAST16_TYPE__ yytype_uint16; +#elif (!defined __UINT_LEAST16_MAX__ && defined YY_STDINT_H \ + && UINT_LEAST16_MAX <= INT_MAX) +typedef uint_least16_t yytype_uint16; +#elif !defined __UINT_LEAST16_MAX__ && USHRT_MAX <= INT_MAX +typedef unsigned short yytype_uint16; +#else +typedef int yytype_uint16; +#endif + +#ifndef YYPTRDIFF_T +# if defined __PTRDIFF_TYPE__ && defined __PTRDIFF_MAX__ +# define YYPTRDIFF_T __PTRDIFF_TYPE__ +# define YYPTRDIFF_MAXIMUM __PTRDIFF_MAX__ +# elif defined PTRDIFF_MAX +# ifndef ptrdiff_t +# include <stddef.h> /* INFRINGES ON USER NAME SPACE */ +# endif +# define YYPTRDIFF_T ptrdiff_t +# define YYPTRDIFF_MAXIMUM PTRDIFF_MAX +# else +# define YYPTRDIFF_T long +# define YYPTRDIFF_MAXIMUM LONG_MAX +# endif +#endif + +#ifndef YYSIZE_T +# ifdef __SIZE_TYPE__ +# define YYSIZE_T __SIZE_TYPE__ +# elif defined size_t +# define YYSIZE_T size_t +# elif defined __STDC_VERSION__ && 199901 <= __STDC_VERSION__ +# include <stddef.h> /* INFRINGES ON USER NAME SPACE */ +# define YYSIZE_T size_t +# else +# define YYSIZE_T unsigned +# endif +#endif + +#define YYSIZE_MAXIMUM \ + YY_CAST (YYPTRDIFF_T, \ + (YYPTRDIFF_MAXIMUM < YY_CAST (YYSIZE_T, -1) \ + ? YYPTRDIFF_MAXIMUM \ + : YY_CAST (YYSIZE_T, -1))) + +#define YYSIZEOF(X) YY_CAST (YYPTRDIFF_T, sizeof (X)) + +/* Stored state numbers (used for stacks). */ +typedef yytype_uint8 yy_state_t; + +/* State numbers in computations. */ +typedef int yy_state_fast_t; + +#ifndef YY_ +# if defined YYENABLE_NLS && YYENABLE_NLS +# if ENABLE_NLS +# include <libintl.h> /* INFRINGES ON USER NAME SPACE */ +# define YY_(Msgid) dgettext ("bison-runtime", Msgid) +# endif +# endif +# ifndef YY_ +# define YY_(Msgid) Msgid +# endif +#endif + +#ifndef YY_ATTRIBUTE_PURE +# if defined __GNUC__ && 2 < __GNUC__ + (96 <= __GNUC_MINOR__) +# define YY_ATTRIBUTE_PURE __attribute__ ((__pure__)) +# else +# define YY_ATTRIBUTE_PURE +# endif +#endif + +#ifndef YY_ATTRIBUTE_UNUSED +# if defined __GNUC__ && 2 < __GNUC__ + (7 <= __GNUC_MINOR__) +# define YY_ATTRIBUTE_UNUSED __attribute__ ((__unused__)) +# else +# define YY_ATTRIBUTE_UNUSED +# endif +#endif + +/* Suppress unused-variable warnings by "using" E. */ +#if ! defined lint || defined __GNUC__ +# define YYUSE(E) ((void) (E)) +#else +# define YYUSE(E) /* empty */ +#endif + +#if defined __GNUC__ && ! defined __ICC && 407 <= __GNUC__ * 100 + __GNUC_MINOR__ +/* Suppress an incorrect diagnostic about yylval being uninitialized. */ +# define YY_IGNORE_MAYBE_UNINITIALIZED_BEGIN \ + _Pragma ("GCC diagnostic push") \ + _Pragma ("GCC diagnostic ignored \"-Wuninitialized\"") \ + _Pragma ("GCC diagnostic ignored \"-Wmaybe-uninitialized\"") +# define YY_IGNORE_MAYBE_UNINITIALIZED_END \ + _Pragma ("GCC diagnostic pop") +#else +# define YY_INITIAL_VALUE(Value) Value +#endif +#ifndef YY_IGNORE_MAYBE_UNINITIALIZED_BEGIN +# define YY_IGNORE_MAYBE_UNINITIALIZED_BEGIN +# define YY_IGNORE_MAYBE_UNINITIALIZED_END +#endif +#ifndef YY_INITIAL_VALUE +# define YY_INITIAL_VALUE(Value) /* Nothing. */ +#endif + +#if defined __cplusplus && defined __GNUC__ && ! defined __ICC && 6 <= __GNUC__ +# define YY_IGNORE_USELESS_CAST_BEGIN \ + _Pragma ("GCC diagnostic push") \ + _Pragma ("GCC diagnostic ignored \"-Wuseless-cast\"") +# define YY_IGNORE_USELESS_CAST_END \ + _Pragma ("GCC diagnostic pop") +#endif +#ifndef YY_IGNORE_USELESS_CAST_BEGIN +# define YY_IGNORE_USELESS_CAST_BEGIN +# define YY_IGNORE_USELESS_CAST_END +#endif + + +#define YY_ASSERT(E) ((void) (0 && (E))) + +#if ! defined yyoverflow || YYERROR_VERBOSE + +/* The parser invokes alloca or malloc; define the necessary symbols. */ + +# ifdef YYSTACK_USE_ALLOCA +# if YYSTACK_USE_ALLOCA +# ifdef __GNUC__ +# define YYSTACK_ALLOC __builtin_alloca +# elif defined __BUILTIN_VA_ARG_INCR +# include <alloca.h> /* INFRINGES ON USER NAME SPACE */ +# elif defined _AIX +# define YYSTACK_ALLOC __alloca +# elif defined _MSC_VER +# include <malloc.h> /* INFRINGES ON USER NAME SPACE */ +# define alloca _alloca +# else +# define YYSTACK_ALLOC alloca +# if ! defined _ALLOCA_H && ! defined EXIT_SUCCESS +# include <stdlib.h> /* INFRINGES ON USER NAME SPACE */ + /* Use EXIT_SUCCESS as a witness for stdlib.h. */ +# ifndef EXIT_SUCCESS +# define EXIT_SUCCESS 0 +# endif +# endif +# endif +# endif +# endif + +# ifdef YYSTACK_ALLOC + /* Pacify GCC's 'empty if-body' warning. */ +# define YYSTACK_FREE(Ptr) do { /* empty */; } while (0) +# ifndef YYSTACK_ALLOC_MAXIMUM + /* The OS might guarantee only one guard page at the bottom of the stack, + and a page size can be as small as 4096 bytes. So we cannot safely + invoke alloca (N) if N exceeds 4096. Use a slightly smaller number + to allow for a few compiler-allocated temporary stack slots. */ +# define YYSTACK_ALLOC_MAXIMUM 4032 /* reasonable circa 2006 */ +# endif +# else +# define YYSTACK_ALLOC YYMALLOC +# define YYSTACK_FREE YYFREE +# ifndef YYSTACK_ALLOC_MAXIMUM +# define YYSTACK_ALLOC_MAXIMUM YYSIZE_MAXIMUM +# endif +# if (defined __cplusplus && ! defined EXIT_SUCCESS \ + && ! ((defined YYMALLOC || defined malloc) \ + && (defined YYFREE || defined free))) +# include <stdlib.h> /* INFRINGES ON USER NAME SPACE */ +# ifndef EXIT_SUCCESS +# define EXIT_SUCCESS 0 +# endif +# endif +# ifndef YYMALLOC +# define YYMALLOC malloc +# if ! defined malloc && ! defined EXIT_SUCCESS +void *malloc (YYSIZE_T); /* INFRINGES ON USER NAME SPACE */ +# endif +# endif +# ifndef YYFREE +# define YYFREE free +# if ! defined free && ! defined EXIT_SUCCESS +void free (void *); /* INFRINGES ON USER NAME SPACE */ +# endif +# endif +# endif +#endif /* ! defined yyoverflow || YYERROR_VERBOSE */ + + +#if (! defined yyoverflow \ + && (! defined __cplusplus \ + || (defined YYSTYPE_IS_TRIVIAL && YYSTYPE_IS_TRIVIAL))) + +/* A type that is properly aligned for any stack member. */ +union yyalloc +{ + yy_state_t yyss_alloc; + YYSTYPE yyvs_alloc; +}; + +/* The size of the maximum gap between one aligned stack and the next. */ +# define YYSTACK_GAP_MAXIMUM (YYSIZEOF (union yyalloc) - 1) + +/* The size of an array large to enough to hold all stacks, each with + N elements. */ +# define YYSTACK_BYTES(N) \ + ((N) * (YYSIZEOF (yy_state_t) + YYSIZEOF (YYSTYPE)) \ + + YYSTACK_GAP_MAXIMUM) + +# define YYCOPY_NEEDED 1 + +/* Relocate STACK from its old location to the new one. The + local variables YYSIZE and YYSTACKSIZE give the old and new number of + elements in the stack, and YYPTR gives the new location of the + stack. Advance YYPTR to a properly aligned location for the next + stack. */ +# define YYSTACK_RELOCATE(Stack_alloc, Stack) \ + do \ + { \ + YYPTRDIFF_T yynewbytes; \ + YYCOPY (&yyptr->Stack_alloc, Stack, yysize); \ + Stack = &yyptr->Stack_alloc; \ + yynewbytes = yystacksize * YYSIZEOF (*Stack) + YYSTACK_GAP_MAXIMUM; \ + yyptr += yynewbytes / YYSIZEOF (*yyptr); \ + } \ + while (0) + +#endif + +#if defined YYCOPY_NEEDED && YYCOPY_NEEDED +/* Copy COUNT objects from SRC to DST. The source and destination do + not overlap. */ +# ifndef YYCOPY +# if defined __GNUC__ && 1 < __GNUC__ +# define YYCOPY(Dst, Src, Count) \ + __builtin_memcpy (Dst, Src, YY_CAST (YYSIZE_T, (Count)) * sizeof (*(Src))) +# else +# define YYCOPY(Dst, Src, Count) \ + do \ + { \ + YYPTRDIFF_T yyi; \ + for (yyi = 0; yyi < (Count); yyi++) \ + (Dst)[yyi] = (Src)[yyi]; \ + } \ + while (0) +# endif +# endif +#endif /* !YYCOPY_NEEDED */ + +/* YYFINAL -- State number of the termination state. */ +#define YYFINAL 6 +/* YYLAST -- Last index in YYTABLE. */ +#define YYLAST 147 + +/* YYNTOKENS -- Number of terminals. */ +#define YYNTOKENS 47 +/* YYNNTS -- Number of nonterminals. */ +#define YYNNTS 92 +/* YYNRULES -- Number of rules. */ +#define YYNRULES 131 +/* YYNSTATES -- Number of states. */ +#define YYNSTATES 232 + +#define YYUNDEFTOK 2 +#define YYMAXUTOK 301 + + +/* YYTRANSLATE(TOKEN-NUM) -- Symbol number corresponding to TOKEN-NUM + as returned by yylex, with out-of-bounds checking. */ +#define YYTRANSLATE(YYX) \ + (0 <= (YYX) && (YYX) <= YYMAXUTOK ? yytranslate[YYX] : YYUNDEFTOK) + +/* YYTRANSLATE[TOKEN-NUM] -- Symbol number corresponding to TOKEN-NUM + as returned by yylex. */ +static const yytype_int8 yytranslate[] = +{ + 0, 2, 2, 2, 2, 2, 2, 2, 2, 2, + 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, + 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, + 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, + 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, + 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, + 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, + 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, + 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, + 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, + 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, + 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, + 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, + 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, + 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, + 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, + 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, + 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, + 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, + 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, + 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, + 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, + 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, + 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, + 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, + 2, 2, 2, 2, 2, 2, 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 +}; + +#if YYDEBUG + /* YYRLINE[YYN] -- Source line where rule number YYN was defined. */ +static const yytype_int16 yyrline[] = +{ + 0, 155, 155, 163, 167, 167, 168, 172, 176, 176, + 177, 181, 181, 182, 186, 187, 191, 192, 193, 202, + 206, 206, 210, 210, 220, 227, 219, 252, 253, 257, + 258, 259, 260, 268, 271, 272, 273, 268, 274, 278, + 282, 292, 296, 314, 318, 318, 319, 320, 318, 337, + 341, 342, 346, 347, 355, 356, 360, 378, 382, 382, + 383, 384, 382, 401, 405, 406, 410, 411, 419, 420, + 419, 436, 440, 444, 444, 445, 456, 463, 467, 455, + 489, 490, 494, 495, 496, 500, 500, 501, 501, 505, + 506, 510, 510, 511, 511, 521, 522, 521, 533, 537, + 541, 541, 542, 550, 550, 551, 555, 555, 556, 556, + 557, 555, 596, 600, 604, 605, 613, 613, 614, 618, + 618, 618, 619, 618, 633, 637, 641, 642, 646, 647, + 651, 652 +}; +#endif + +#if YYDEBUG || YYERROR_VERBOSE || 0 +/* YYTNAME[SYMBOL-NUM] -- String name of the symbol SYMBOL-NUM. + First, the terminals, then, starting at YYNTOKENS, nonterminals. */ +static const char *const yytname[] = +{ + "$end", "error", "$undefined", "TK_ARC", "TK_BATCH", "TK_CONTINUOUS", + "TK_CONTROLLED", "TK_DESCRIPTION", "TK_DISCRETE", "TK_EVENTS", "TK_FLOW", + "TK_FUNCTION", "TK_INITIAL", "TK_INSPECTION", "TK_LENGTH", "TK_MARKING", + "TK_MODEL", "TK_NETWORK", "TK_OUTPUT", "TK_PLACE", "TK_PLACES", + "TK_SPEED", "TK_STEADY", "TK_TIME", "TK_TIMING", "TK_TRANSITION", + "TK_TRANSITIONS", "TK_TRIANGULAR", "TK_UNITY", "TK_ID", "TK_INTEGER", + "TK_REAL", "TK_EXPONENT", "TK_AT", "TK_EVERY", "TK_LEFT_BRACKET", + "TK_RIGHT_BRACKET", "TK_PL_TR", "TK_ALL", "TK_LEFT_PARENTHESIS", + "TK_RIGHT_PARENTHESIS", "TK_LEFT_SQUARE_BRACKET", + "TK_RIGHT_SQUARE_BRACKET", "TK_SEMICOLON", "TK_COMMA", "TK_ATTRIB", + "TK_COLON", "$accept", "start", "blk_def", "blk_model", "$@1", + "blk_unity", "blk_lenght", "$@2", "blk_time", "$@3", "semi_colon", + "number", "blk_net", "blk_places", "$@4", "blk_transitions", "$@5", + "blk_place", "$@6", "$@7", "blk_place2", "blk_place_type", + "blk_function", "$@8", "$@9", "$@10", "$@11", "blk_triangular_place", + "blk_initial_marking", "blk_initial_marking_int", "blk_batch", "$@12", + "$@13", "$@14", "$@15", "blk_batch2", "blk_triangular_batch", + "blk_steady_marking", "blk_steady_marking_int", "blk_steady_batch", + "$@16", "$@17", "$@18", "$@19", "blk_steady_batch2", + "blk_steady_triangular_batch", "blk_place_arcs", "$@20", "$@21", + "blk_place_arcs2", "blk_place_weight", "$@22", "blk_transition", "$@23", + "$@24", "$@25", "blk_transition2", "blk_transition_type", + "blk_transition_function", "$@26", "$@27", + "blk_steady_transition_function", "blk_steady_transition_function_int", + "$@28", "$@29", "blk_transition_arcs", "$@30", "$@31", + "blk_transition_arcs2", "blk_transition_weight", "$@32", + "blk_controlled_events", "$@33", "controlled_events", "$@34", "$@35", + "$@36", "$@37", "$@38", "controlled_events2", "controlled_events_type", + "blk_time_inspection", "$@39", "time_inspection", "$@40", "$@41", "$@42", + "$@43", "time_inspection2", "blk_op_time", "blk_op_pt", "blk_pl_tr", YY_NULLPTR +}; +#endif + +# ifdef YYPRINT +/* YYTOKNUM[NUM] -- (External) token number corresponding to the + (internal) symbol number NUM (which must be that of a token). */ +static const yytype_int16 yytoknum[] = +{ + 0, 256, 257, 258, 259, 260, 261, 262, 263, 264, + 265, 266, 267, 268, 269, 270, 271, 272, 273, 274, + 275, 276, 277, 278, 279, 280, 281, 282, 283, 284, + 285, 286, 287, 288, 289, 290, 291, 292, 293, 294, + 295, 296, 297, 298, 299, 300, 301 +}; +# endif + +#define YYPACT_NINF (-113) + +#define yypact_value_is_default(Yyn) \ + ((Yyn) == YYPACT_NINF) + +#define YYTABLE_NINF (-1) + +#define yytable_value_is_error(Yyn) \ + 0 + + /* YYPACT[STATE-NUM] -- Index in YYTABLE of the portion describing + STATE-NUM. */ +static const yytype_int8 yypact[] = +{ + -8, 10, 20, 11, 26, -113, -113, 38, 40, 21, + -113, 27, 9, 33, 45, 32, 13, 28, -113, -113, + -113, -113, 34, -113, 46, -113, 35, 16, 43, -113, + -113, 36, -113, -113, 39, 41, -113, 42, -113, -113, + 44, 9, -113, -113, 47, -113, 18, -113, -113, -113, + 9, 30, -113, 48, 29, -113, -2, 50, 0, 1, + -113, -113, -113, -113, 31, 14, -113, -113, 37, -113, + -113, 12, 61, -113, -113, -113, 52, 53, -113, -113, + -113, -113, -113, -113, 2, -113, -5, 51, 63, 54, + 55, -113, 56, 57, -9, -113, 12, 64, 62, 12, + 12, 73, 12, -113, -113, -113, -113, 9, -113, 66, + 68, 67, -113, -113, 3, -113, -113, -113, 58, -16, + 69, 93, 43, 59, 70, 72, 74, -113, 79, 65, + 44, 12, 12, -113, 71, -113, -1, 77, -113, -113, + -113, -113, 12, 12, 95, 42, 12, -113, -113, -113, + -113, -113, 12, -113, 76, -113, -113, -113, -113, 85, + -113, -113, -113, 75, 78, -113, -113, 82, 83, 84, + -113, 86, 12, 12, 87, 12, -113, -113, -113, 88, + 9, -113, -113, 12, -113, 67, 12, -113, -113, 89, + 90, -113, 92, -113, -113, -113, 79, 36, 12, 96, + 12, 91, -113, 97, -113, -113, -113, -113, -113, -113, + -113, 12, -113, 94, -113, 12, 100, 98, -113, -113, + 12, 101, 99, -113, -113, 105, -113, 102, -113, 106, + -113, -113 +}; + + /* YYDEFACT[STATE-NUM] -- Default reduction number in state STATE-NUM. + Performed when YYTABLE does not specify something else to do. Zero + means the default is an error. */ +static const yytype_uint8 yydefact[] = +{ + 6, 0, 0, 0, 10, 4, 1, 0, 105, 0, + 3, 13, 15, 0, 0, 118, 0, 0, 7, 14, + 5, 20, 0, 103, 0, 2, 0, 0, 0, 22, + 19, 112, 116, 8, 0, 0, 21, 0, 106, 104, + 124, 15, 11, 24, 0, 23, 0, 119, 117, 9, + 15, 0, 76, 0, 0, 12, 0, 0, 0, 0, + 31, 30, 29, 32, 0, 0, 114, 115, 0, 126, + 127, 0, 38, 84, 83, 82, 0, 0, 17, 16, + 18, 120, 33, 25, 0, 107, 0, 0, 0, 0, + 0, 77, 0, 0, 0, 121, 0, 0, 55, 0, + 0, 90, 0, 128, 130, 131, 129, 15, 34, 0, + 0, 71, 87, 85, 0, 78, 108, 122, 0, 49, + 0, 0, 28, 0, 0, 0, 0, 89, 98, 0, + 124, 0, 0, 42, 0, 43, 63, 0, 27, 26, + 88, 86, 0, 0, 0, 81, 0, 125, 123, 35, + 44, 41, 0, 56, 0, 57, 68, 93, 91, 0, + 80, 79, 109, 0, 0, 58, 54, 75, 0, 0, + 95, 0, 0, 0, 0, 0, 69, 94, 92, 102, + 15, 36, 45, 0, 73, 71, 0, 96, 110, 40, + 0, 59, 0, 72, 70, 100, 98, 112, 0, 0, + 0, 0, 74, 0, 99, 97, 113, 111, 39, 37, + 46, 0, 101, 53, 60, 0, 0, 67, 52, 47, + 0, 0, 51, 66, 61, 49, 48, 65, 50, 63, + 62, 64 +}; + + /* YYPGOTO[NTERM-NUM]. */ +static const yytype_int8 yypgoto[] = +{ + -113, -113, -113, -113, -113, -113, -113, -113, -113, -113, + -41, -95, -113, -113, -113, -113, -113, -14, -113, -113, + -113, -113, -113, -113, -113, -113, -113, -113, -113, -113, + -110, -113, -113, -113, -113, -113, -113, -113, -113, -112, + -113, -113, -113, -113, -113, -113, -67, -113, -113, -113, + -113, -113, -17, -113, -113, -113, -113, -113, -113, -113, + -113, -113, -113, -113, -113, -66, -113, -113, -113, -113, + -113, -113, -113, -68, -113, -113, -113, -113, -113, -113, + -113, -113, -113, 17, -113, -113, -113, -113, -113, -113, + -113, -113 +}; + + /* YYDEFGOTO[NTERM-NUM]. */ +static const yytype_int16 yydefgoto[] = +{ + -1, 2, 3, 4, 12, 10, 11, 41, 18, 50, + 20, 81, 8, 22, 28, 30, 37, 36, 51, 88, + 139, 64, 83, 87, 118, 163, 189, 199, 98, 134, + 135, 164, 190, 213, 222, 226, 216, 111, 154, 155, + 174, 201, 217, 227, 230, 221, 122, 167, 185, 194, + 176, 192, 45, 57, 101, 128, 161, 76, 91, 124, + 123, 115, 127, 169, 168, 145, 179, 196, 205, 187, + 203, 15, 31, 39, 46, 92, 129, 171, 197, 207, + 68, 25, 40, 48, 54, 86, 107, 130, 148, 71, + 95, 106 +}; + + /* YYTABLE[YYPACT[STATE-NUM]] -- What to do in state STATE-NUM. If + positive, shift that token. If negative, reduce the rule whose + number is the opposite. If YYTABLE_NINF, syntax error. */ +static const yytype_uint8 yytable[] = +{ + 49, 108, 60, 61, 112, 113, 62, 116, 1, 55, + 66, 104, 89, 125, 78, 79, 80, 105, 73, 74, + 6, 67, 75, 132, 133, 63, 90, 126, 7, 78, + 79, 80, 93, 94, 69, 70, 149, 150, 152, 5, + 9, 153, 78, 79, 80, 13, 14, 157, 158, 16, + 17, 162, 19, 21, 23, 24, 27, 165, 26, 32, + 29, 34, 35, 53, 33, 38, 117, 44, 42, 56, + 43, 72, 82, 47, 59, 97, 52, 181, 182, 109, + 184, 77, 85, 120, 110, 121, 103, 58, 191, 65, + 96, 195, 84, 99, 100, 114, 137, 144, 159, 140, + 102, 119, 131, 208, 136, 210, 156, 151, 138, 146, + 141, 142, 166, 143, 170, 228, 214, 231, 193, 172, + 218, 175, 173, 177, 178, 223, 180, 186, 160, 206, + 204, 183, 202, 198, 200, 211, 209, 212, 215, 188, + 219, 224, 220, 225, 132, 152, 229, 147 +}; + +static const yytype_uint8 yycheck[] = +{ + 41, 96, 4, 5, 99, 100, 8, 102, 16, 50, + 10, 20, 10, 10, 30, 31, 32, 26, 4, 5, + 0, 21, 8, 39, 119, 27, 24, 24, 17, 30, + 31, 32, 37, 38, 33, 34, 131, 132, 39, 29, + 14, 136, 30, 31, 32, 7, 6, 142, 143, 28, + 23, 146, 43, 20, 9, 23, 28, 152, 45, 13, + 26, 45, 19, 45, 29, 29, 107, 25, 29, 39, + 29, 40, 11, 29, 45, 12, 29, 172, 173, 15, + 175, 44, 29, 15, 22, 18, 29, 39, 183, 39, + 39, 186, 40, 39, 39, 22, 3, 18, 3, 40, + 44, 35, 44, 198, 35, 200, 29, 36, 122, 44, + 40, 39, 36, 39, 29, 225, 211, 229, 185, 44, + 215, 39, 44, 40, 40, 220, 40, 39, 145, 197, + 196, 44, 40, 44, 44, 44, 40, 40, 44, 180, + 40, 40, 44, 44, 39, 39, 44, 130 +}; + + /* YYSTOS[STATE-NUM] -- The (internal number of the) accessing + symbol of state STATE-NUM. */ +static const yytype_uint8 yystos[] = +{ + 0, 16, 48, 49, 50, 29, 0, 17, 59, 14, + 52, 53, 51, 7, 6, 118, 28, 23, 55, 43, + 57, 20, 60, 9, 23, 128, 45, 28, 61, 26, + 62, 119, 13, 29, 45, 19, 64, 63, 29, 120, + 129, 54, 29, 29, 25, 99, 121, 29, 130, 57, + 56, 65, 29, 45, 131, 57, 39, 100, 39, 45, + 4, 5, 8, 27, 68, 39, 10, 21, 127, 33, + 34, 136, 40, 4, 5, 8, 104, 44, 30, 31, + 32, 58, 11, 69, 40, 29, 132, 70, 66, 10, + 24, 105, 122, 37, 38, 137, 39, 12, 75, 39, + 39, 101, 44, 29, 20, 26, 138, 133, 58, 15, + 22, 84, 58, 58, 22, 108, 58, 57, 71, 35, + 15, 18, 93, 107, 106, 10, 24, 109, 102, 123, + 134, 44, 39, 58, 76, 77, 35, 3, 64, 67, + 40, 40, 39, 39, 18, 112, 44, 130, 135, 58, + 58, 36, 39, 58, 85, 86, 29, 58, 58, 3, + 99, 103, 58, 72, 78, 58, 36, 94, 111, 110, + 29, 124, 44, 44, 87, 39, 97, 40, 40, 113, + 40, 58, 58, 44, 58, 95, 39, 116, 57, 73, + 79, 58, 98, 93, 96, 58, 114, 125, 44, 74, + 44, 88, 40, 117, 112, 115, 120, 126, 58, 40, + 58, 44, 40, 80, 58, 44, 83, 89, 58, 40, + 44, 92, 81, 58, 40, 44, 82, 90, 77, 44, + 91, 86 +}; + + /* YYR1[YYN] -- Symbol number of symbol that rule YYN derives. */ +static const yytype_uint8 yyr1[] = +{ + 0, 47, 48, 49, 51, 50, 50, 52, 54, 53, + 53, 56, 55, 55, 57, 57, 58, 58, 58, 59, + 61, 60, 63, 62, 65, 66, 64, 67, 67, 68, + 68, 68, 68, 70, 71, 72, 73, 69, 69, 74, + 74, 75, 76, 76, 78, 79, 80, 81, 77, 77, + 82, 82, 83, 83, 84, 84, 85, 85, 87, 88, + 89, 90, 86, 86, 91, 91, 92, 92, 94, 95, + 93, 93, 96, 98, 97, 97, 100, 101, 102, 99, + 103, 103, 104, 104, 104, 106, 105, 107, 105, 108, + 108, 110, 109, 111, 109, 113, 114, 112, 112, 115, + 117, 116, 116, 119, 118, 118, 121, 122, 123, 124, + 125, 120, 120, 126, 127, 127, 129, 128, 128, 131, + 132, 133, 134, 130, 130, 135, 136, 136, 137, 137, + 138, 138 +}; + + /* YYR2[YYN] -- Number of symbols on the right hand side of rule YYN. */ +static const yytype_int8 yyr2[] = +{ + 0, 2, 4, 2, 0, 4, 0, 2, 0, 6, + 0, 0, 6, 0, 1, 0, 1, 1, 1, 4, + 0, 3, 0, 3, 0, 0, 12, 1, 0, 1, + 1, 1, 1, 0, 0, 0, 0, 13, 0, 2, + 0, 5, 1, 1, 0, 0, 0, 0, 13, 0, + 2, 0, 2, 0, 5, 0, 1, 1, 0, 0, + 0, 0, 13, 0, 2, 0, 2, 0, 0, 0, + 7, 0, 1, 0, 4, 0, 0, 0, 0, 12, + 1, 0, 1, 1, 1, 0, 5, 0, 5, 2, + 0, 0, 5, 0, 5, 0, 0, 7, 0, 1, + 0, 4, 0, 0, 4, 0, 0, 0, 0, 0, + 0, 18, 0, 1, 1, 1, 0, 4, 0, 0, + 0, 0, 0, 11, 0, 1, 1, 1, 2, 2, + 1, 1 +}; + + +#define yyerrok (yyerrstatus = 0) +#define yyclearin (yychar = YYEMPTY) +#define YYEMPTY (-2) +#define YYEOF 0 + +#define YYACCEPT goto yyacceptlab +#define YYABORT goto yyabortlab +#define YYERROR goto yyerrorlab + + +#define YYRECOVERING() (!!yyerrstatus) + +#define YYBACKUP(Token, Value) \ + do \ + if (yychar == YYEMPTY) \ + { \ + yychar = (Token); \ + yylval = (Value); \ + YYPOPSTACK (yylen); \ + yystate = *yyssp; \ + goto yybackup; \ + } \ + else \ + { \ + yyerror (YY_("syntax error: cannot back up")); \ + YYERROR; \ + } \ + while (0) + +/* Error token number */ +#define YYTERROR 1 +#define YYERRCODE 256 + + + +/* Enable debugging if requested. */ +#if YYDEBUG + +# ifndef YYFPRINTF +# include <stdio.h> /* INFRINGES ON USER NAME SPACE */ +# define YYFPRINTF fprintf +# endif + +# define YYDPRINTF(Args) \ +do { \ + if (yydebug) \ + YYFPRINTF Args; \ +} while (0) + +/* This macro is provided for backward compatibility. */ +#ifndef YY_LOCATION_PRINT +# define YY_LOCATION_PRINT(File, Loc) ((void) 0) +#endif + + +# define YY_SYMBOL_PRINT(Title, Type, Value, Location) \ +do { \ + if (yydebug) \ + { \ + YYFPRINTF (stderr, "%s ", Title); \ + yy_symbol_print (stderr, \ + Type, Value); \ + YYFPRINTF (stderr, "\n"); \ + } \ +} while (0) + + +/*-----------------------------------. +| Print this symbol's value on YYO. | +`-----------------------------------*/ + +static void +yy_symbol_value_print (FILE *yyo, int yytype, YYSTYPE const * const yyvaluep) +{ + FILE *yyoutput = yyo; + YYUSE (yyoutput); + if (!yyvaluep) + return; +# ifdef YYPRINT + if (yytype < YYNTOKENS) + YYPRINT (yyo, yytoknum[yytype], *yyvaluep); +# endif + YY_IGNORE_MAYBE_UNINITIALIZED_BEGIN + YYUSE (yytype); + YY_IGNORE_MAYBE_UNINITIALIZED_END +} + + +/*---------------------------. +| Print this symbol on YYO. | +`---------------------------*/ + +static void +yy_symbol_print (FILE *yyo, int yytype, YYSTYPE const * const yyvaluep) +{ + YYFPRINTF (yyo, "%s %s (", + yytype < YYNTOKENS ? "token" : "nterm", yytname[yytype]); + + yy_symbol_value_print (yyo, yytype, yyvaluep); + YYFPRINTF (yyo, ")"); +} + +/*------------------------------------------------------------------. +| yy_stack_print -- Print the state stack from its BOTTOM up to its | +| TOP (included). | +`------------------------------------------------------------------*/ + +static void +yy_stack_print (yy_state_t *yybottom, yy_state_t *yytop) +{ + YYFPRINTF (stderr, "Stack now"); + for (; yybottom <= yytop; yybottom++) + { + int yybot = *yybottom; + YYFPRINTF (stderr, " %d", yybot); + } + YYFPRINTF (stderr, "\n"); +} + +# define YY_STACK_PRINT(Bottom, Top) \ +do { \ + if (yydebug) \ + yy_stack_print ((Bottom), (Top)); \ +} while (0) + + +/*------------------------------------------------. +| Report that the YYRULE is going to be reduced. | +`------------------------------------------------*/ + +static void +yy_reduce_print (yy_state_t *yyssp, YYSTYPE *yyvsp, int yyrule) +{ + int yylno = yyrline[yyrule]; + int yynrhs = yyr2[yyrule]; + int yyi; + YYFPRINTF (stderr, "Reducing stack by rule %d (line %d):\n", + yyrule - 1, yylno); + /* The symbols being reduced. */ + for (yyi = 0; yyi < yynrhs; yyi++) + { + YYFPRINTF (stderr, " $%d = ", yyi + 1); + yy_symbol_print (stderr, + yystos[+yyssp[yyi + 1 - yynrhs]], + &yyvsp[(yyi + 1) - (yynrhs)] + ); + YYFPRINTF (stderr, "\n"); + } +} + +# define YY_REDUCE_PRINT(Rule) \ +do { \ + if (yydebug) \ + yy_reduce_print (yyssp, yyvsp, Rule); \ +} while (0) + +/* Nonzero means print parse trace. It is left uninitialized so that + multiple parsers can coexist. */ +int yydebug; +#else /* !YYDEBUG */ +# define YYDPRINTF(Args) +# define YY_SYMBOL_PRINT(Title, Type, Value, Location) +# define YY_STACK_PRINT(Bottom, Top) +# define YY_REDUCE_PRINT(Rule) +#endif /* !YYDEBUG */ + + +/* YYINITDEPTH -- initial size of the parser's stacks. */ +#ifndef YYINITDEPTH +# define YYINITDEPTH 200 +#endif + +/* YYMAXDEPTH -- maximum size the stacks can grow to (effective only + if the built-in stack extension method is used). + + Do not make this value too large; the results are undefined if + YYSTACK_ALLOC_MAXIMUM < YYSTACK_BYTES (YYMAXDEPTH) + evaluated with infinite-precision integer arithmetic. */ + +#ifndef YYMAXDEPTH +# define YYMAXDEPTH 10000 +#endif + + +#if YYERROR_VERBOSE + +# ifndef yystrlen +# if defined __GLIBC__ && defined _STRING_H +# define yystrlen(S) (YY_CAST (YYPTRDIFF_T, strlen (S))) +# else +/* Return the length of YYSTR. */ +static YYPTRDIFF_T +yystrlen (const char *yystr) +{ + YYPTRDIFF_T yylen; + for (yylen = 0; yystr[yylen]; yylen++) + continue; + return yylen; +} +# endif +# endif + +# ifndef yystpcpy +# if defined __GLIBC__ && defined _STRING_H && defined _GNU_SOURCE +# define yystpcpy stpcpy +# else +/* Copy YYSRC to YYDEST, returning the address of the terminating '\0' in + YYDEST. */ +static char * +yystpcpy (char *yydest, const char *yysrc) +{ + char *yyd = yydest; + const char *yys = yysrc; + + while ((*yyd++ = *yys++) != '\0') + continue; + + return yyd - 1; +} +# endif +# endif + +# ifndef yytnamerr +/* Copy to YYRES the contents of YYSTR after stripping away unnecessary + quotes and backslashes, so that it's suitable for yyerror. The + heuristic is that double-quoting is unnecessary unless the string + contains an apostrophe, a comma, or backslash (other than + backslash-backslash). YYSTR is taken from yytname. If YYRES is + null, do not copy; instead, return the length of what the result + would have been. */ +static YYPTRDIFF_T +yytnamerr (char *yyres, const char *yystr) +{ + if (*yystr == '"') + { + YYPTRDIFF_T yyn = 0; + char const *yyp = yystr; + + for (;;) + switch (*++yyp) + { + case '\'': + case ',': + goto do_not_strip_quotes; + + case '\\': + if (*++yyp != '\\') + goto do_not_strip_quotes; + else + goto append; + + append: + default: + if (yyres) + yyres[yyn] = *yyp; + yyn++; + break; + + case '"': + if (yyres) + yyres[yyn] = '\0'; + return yyn; + } + do_not_strip_quotes: ; + } + + if (yyres) + return yystpcpy (yyres, yystr) - yyres; + else + return yystrlen (yystr); +} +# endif + +/* Copy into *YYMSG, which is of size *YYMSG_ALLOC, an error message + about the unexpected token YYTOKEN for the state stack whose top is + YYSSP. + + Return 0 if *YYMSG was successfully written. Return 1 if *YYMSG is + not large enough to hold the message. In that case, also set + *YYMSG_ALLOC to the required number of bytes. Return 2 if the + required number of bytes is too large to store. */ +static int +yysyntax_error (YYPTRDIFF_T *yymsg_alloc, char **yymsg, + yy_state_t *yyssp, int yytoken) +{ + enum { YYERROR_VERBOSE_ARGS_MAXIMUM = 5 }; + /* Internationalized format string. */ + const char *yyformat = YY_NULLPTR; + /* Arguments of yyformat: reported tokens (one for the "unexpected", + one per "expected"). */ + char const *yyarg[YYERROR_VERBOSE_ARGS_MAXIMUM]; + /* Actual size of YYARG. */ + int yycount = 0; + /* Cumulated lengths of YYARG. */ + YYPTRDIFF_T yysize = 0; + + /* There are many possibilities here to consider: + - If this state is a consistent state with a default action, then + the only way this function was invoked is if the default action + is an error action. In that case, don't check for expected + tokens because there are none. + - The only way there can be no lookahead present (in yychar) is if + this state is a consistent state with a default action. Thus, + detecting the absence of a lookahead is sufficient to determine + that there is no unexpected or expected token to report. In that + case, just report a simple "syntax error". + - Don't assume there isn't a lookahead just because this state is a + consistent state with a default action. There might have been a + previous inconsistent state, consistent state with a non-default + action, or user semantic action that manipulated yychar. + - Of course, the expected token list depends on states to have + correct lookahead information, and it depends on the parser not + to perform extra reductions after fetching a lookahead from the + scanner and before detecting a syntax error. Thus, state merging + (from LALR or IELR) and default reductions corrupt the expected + token list. However, the list is correct for canonical LR with + one exception: it will still contain any token that will not be + accepted due to an error action in a later state. + */ + if (yytoken != YYEMPTY) + { + int yyn = yypact[+*yyssp]; + YYPTRDIFF_T yysize0 = yytnamerr (YY_NULLPTR, yytname[yytoken]); + yysize = yysize0; + yyarg[yycount++] = yytname[yytoken]; + if (!yypact_value_is_default (yyn)) + { + /* Start YYX at -YYN if negative to avoid negative indexes in + YYCHECK. In other words, skip the first -YYN actions for + this state because they are default actions. */ + int yyxbegin = yyn < 0 ? -yyn : 0; + /* Stay within bounds of both yycheck and yytname. */ + int yychecklim = YYLAST - yyn + 1; + int yyxend = yychecklim < YYNTOKENS ? yychecklim : YYNTOKENS; + int yyx; + + for (yyx = yyxbegin; yyx < yyxend; ++yyx) + if (yycheck[yyx + yyn] == yyx && yyx != YYTERROR + && !yytable_value_is_error (yytable[yyx + yyn])) + { + if (yycount == YYERROR_VERBOSE_ARGS_MAXIMUM) + { + yycount = 1; + yysize = yysize0; + break; + } + yyarg[yycount++] = yytname[yyx]; + { + YYPTRDIFF_T yysize1 + = yysize + yytnamerr (YY_NULLPTR, yytname[yyx]); + if (yysize <= yysize1 && yysize1 <= YYSTACK_ALLOC_MAXIMUM) + yysize = yysize1; + else + return 2; + } + } + } + } + + switch (yycount) + { +# define YYCASE_(N, S) \ + case N: \ + yyformat = S; \ + break + default: /* Avoid compiler warnings. */ + YYCASE_(0, YY_("syntax error")); + YYCASE_(1, YY_("syntax error, unexpected %s")); + YYCASE_(2, YY_("syntax error, unexpected %s, expecting %s")); + YYCASE_(3, YY_("syntax error, unexpected %s, expecting %s or %s")); + YYCASE_(4, YY_("syntax error, unexpected %s, expecting %s or %s or %s")); + YYCASE_(5, YY_("syntax error, unexpected %s, expecting %s or %s or %s or %s")); +# undef YYCASE_ + } + + { + /* Don't count the "%s"s in the final size, but reserve room for + the terminator. */ + YYPTRDIFF_T yysize1 = yysize + (yystrlen (yyformat) - 2 * yycount) + 1; + if (yysize <= yysize1 && yysize1 <= YYSTACK_ALLOC_MAXIMUM) + yysize = yysize1; + else + return 2; + } + + if (*yymsg_alloc < yysize) + { + *yymsg_alloc = 2 * yysize; + if (! (yysize <= *yymsg_alloc + && *yymsg_alloc <= YYSTACK_ALLOC_MAXIMUM)) + *yymsg_alloc = YYSTACK_ALLOC_MAXIMUM; + return 1; + } + + /* Avoid sprintf, as that infringes on the user's name space. + Don't have undefined behavior even if the translation + produced a string with the wrong number of "%s"s. */ + { + char *yyp = *yymsg; + int yyi = 0; + while ((*yyp = *yyformat) != '\0') + if (*yyp == '%' && yyformat[1] == 's' && yyi < yycount) + { + yyp += yytnamerr (yyp, yyarg[yyi++]); + yyformat += 2; + } + else + { + ++yyp; + ++yyformat; + } + } + return 0; +} +#endif /* YYERROR_VERBOSE */ + +/*-----------------------------------------------. +| Release the memory associated to this symbol. | +`-----------------------------------------------*/ + +static void +yydestruct (const char *yymsg, int yytype, YYSTYPE *yyvaluep) +{ + YYUSE (yyvaluep); + if (!yymsg) + yymsg = "Deleting"; + YY_SYMBOL_PRINT (yymsg, yytype, yyvaluep, yylocationp); + + YY_IGNORE_MAYBE_UNINITIALIZED_BEGIN + YYUSE (yytype); + YY_IGNORE_MAYBE_UNINITIALIZED_END +} + + + + +/* The lookahead symbol. */ +int yychar; + +/* The semantic value of the lookahead symbol. */ +YYSTYPE yylval; +/* Number of syntax errors so far. */ +int yynerrs; + + +/*----------. +| yyparse. | +`----------*/ + +int +yyparse (void) +{ + yy_state_fast_t yystate; + /* Number of tokens to shift before error messages enabled. */ + int yyerrstatus; + + /* The stacks and their tools: + 'yyss': related to states. + 'yyvs': related to semantic values. + + Refer to the stacks through separate pointers, to allow yyoverflow + to reallocate them elsewhere. */ + + /* The state stack. */ + yy_state_t yyssa[YYINITDEPTH]; + yy_state_t *yyss; + yy_state_t *yyssp; + + /* The semantic value stack. */ + YYSTYPE yyvsa[YYINITDEPTH]; + YYSTYPE *yyvs; + YYSTYPE *yyvsp; + + YYPTRDIFF_T yystacksize; + + int yyn; + int yyresult; + /* Lookahead token as an internal (translated) token number. */ + int yytoken = 0; + /* The variables used to return semantic value and location from the + action routines. */ + YYSTYPE yyval; + +#if YYERROR_VERBOSE + /* Buffer for error messages, and its allocated size. */ + char yymsgbuf[128]; + char *yymsg = yymsgbuf; + YYPTRDIFF_T yymsg_alloc = sizeof yymsgbuf; +#endif + +#define YYPOPSTACK(N) (yyvsp -= (N), yyssp -= (N)) + + /* The number of symbols on the RHS of the reduced rule. + Keep to zero when no symbol should be popped. */ + int yylen = 0; + + yyssp = yyss = yyssa; + yyvsp = yyvs = yyvsa; + yystacksize = YYINITDEPTH; + + YYDPRINTF ((stderr, "Starting parse\n")); + + yystate = 0; + yyerrstatus = 0; + yynerrs = 0; + yychar = YYEMPTY; /* Cause a token to be read. */ + goto yysetstate; + + +/*------------------------------------------------------------. +| yynewstate -- push a new state, which is found in yystate. | +`------------------------------------------------------------*/ +yynewstate: + /* In all cases, when you get here, the value and location stacks + have just been pushed. So pushing a state here evens the stacks. */ + yyssp++; + + +/*--------------------------------------------------------------------. +| yysetstate -- set current state (the top of the stack) to yystate. | +`--------------------------------------------------------------------*/ +yysetstate: + YYDPRINTF ((stderr, "Entering state %d\n", yystate)); + YY_ASSERT (0 <= yystate && yystate < YYNSTATES); + YY_IGNORE_USELESS_CAST_BEGIN + *yyssp = YY_CAST (yy_state_t, yystate); + YY_IGNORE_USELESS_CAST_END + + if (yyss + yystacksize - 1 <= yyssp) +#if !defined yyoverflow && !defined YYSTACK_RELOCATE + goto yyexhaustedlab; +#else + { + /* Get the current used size of the three stacks, in elements. */ + YYPTRDIFF_T yysize = yyssp - yyss + 1; + +# if defined yyoverflow + { + /* Give user a chance to reallocate the stack. Use copies of + these so that the &'s don't force the real ones into + memory. */ + yy_state_t *yyss1 = yyss; + YYSTYPE *yyvs1 = yyvs; + + /* Each stack pointer address is followed by the size of the + data in use in that stack, in bytes. This used to be a + conditional around just the two extra args, but that might + be undefined if yyoverflow is a macro. */ + yyoverflow (YY_("memory exhausted"), + &yyss1, yysize * YYSIZEOF (*yyssp), + &yyvs1, yysize * YYSIZEOF (*yyvsp), + &yystacksize); + yyss = yyss1; + yyvs = yyvs1; + } +# else /* defined YYSTACK_RELOCATE */ + /* Extend the stack our own way. */ + if (YYMAXDEPTH <= yystacksize) + goto yyexhaustedlab; + yystacksize *= 2; + if (YYMAXDEPTH < yystacksize) + yystacksize = YYMAXDEPTH; + + { + yy_state_t *yyss1 = yyss; + union yyalloc *yyptr = + YY_CAST (union yyalloc *, + YYSTACK_ALLOC (YY_CAST (YYSIZE_T, YYSTACK_BYTES (yystacksize)))); + if (! yyptr) + goto yyexhaustedlab; + YYSTACK_RELOCATE (yyss_alloc, yyss); + YYSTACK_RELOCATE (yyvs_alloc, yyvs); +# undef YYSTACK_RELOCATE + if (yyss1 != yyssa) + YYSTACK_FREE (yyss1); + } +# endif + + yyssp = yyss + yysize - 1; + yyvsp = yyvs + yysize - 1; + + YY_IGNORE_USELESS_CAST_BEGIN + YYDPRINTF ((stderr, "Stack size increased to %ld\n", + YY_CAST (long, yystacksize))); + YY_IGNORE_USELESS_CAST_END + + if (yyss + yystacksize - 1 <= yyssp) + YYABORT; + } +#endif /* !defined yyoverflow && !defined YYSTACK_RELOCATE */ + + if (yystate == YYFINAL) + YYACCEPT; + + goto yybackup; + + +/*-----------. +| yybackup. | +`-----------*/ +yybackup: + /* Do appropriate processing given the current state. Read a + lookahead token if we need one and don't already have one. */ + + /* First try to decide what to do without reference to lookahead token. */ + yyn = yypact[yystate]; + if (yypact_value_is_default (yyn)) + goto yydefault; + + /* Not known => get a lookahead token if don't already have one. */ + + /* YYCHAR is either YYEMPTY or YYEOF or a valid lookahead symbol. */ + if (yychar == YYEMPTY) + { + YYDPRINTF ((stderr, "Reading a token: ")); + yychar = yylex (); + } + + if (yychar <= YYEOF) + { + yychar = yytoken = YYEOF; + YYDPRINTF ((stderr, "Now at end of input.\n")); + } + else + { + yytoken = YYTRANSLATE (yychar); + YY_SYMBOL_PRINT ("Next token is", yytoken, &yylval, &yylloc); + } + + /* If the proper action on seeing token YYTOKEN is to reduce or to + detect an error, take that action. */ + yyn += yytoken; + if (yyn < 0 || YYLAST < yyn || yycheck[yyn] != yytoken) + goto yydefault; + yyn = yytable[yyn]; + if (yyn <= 0) + { + if (yytable_value_is_error (yyn)) + goto yyerrlab; + yyn = -yyn; + goto yyreduce; + } + + /* Count tokens shifted since error; after three, turn off error + status. */ + if (yyerrstatus) + yyerrstatus--; + + /* Shift the lookahead token. */ + YY_SYMBOL_PRINT ("Shifting", yytoken, &yylval, &yylloc); + yystate = yyn; + YY_IGNORE_MAYBE_UNINITIALIZED_BEGIN + *++yyvsp = yylval; + YY_IGNORE_MAYBE_UNINITIALIZED_END + + /* Discard the shifted token. */ + yychar = YYEMPTY; + goto yynewstate; + + +/*-----------------------------------------------------------. +| yydefault -- do the default action for the current state. | +`-----------------------------------------------------------*/ +yydefault: + yyn = yydefact[yystate]; + if (yyn == 0) + goto yyerrlab; + goto yyreduce; + + +/*-----------------------------. +| yyreduce -- do a reduction. | +`-----------------------------*/ +yyreduce: + /* yyn is the number of a rule to reduce with. */ + yylen = yyr2[yyn]; + + /* If YYLEN is nonzero, implement the default value of the action: + '$$ = $1'. + + Otherwise, the following line sets YYVAL to garbage. + This behavior is undocumented and Bison + users should not rely upon it. Assigning to YYVAL + unconditionally makes the parser a bit smaller, and it avoids a + GCC warning that YYVAL may be used uninitialized. */ + yyval = yyvsp[1-yylen]; + + + YY_REDUCE_PRINT (yyn); + switch (yyn) + { + case 4: +#line 167 "src/interf/glc.y" + {if (tour == 1) bpn->PutName(yytext);} +#line 1694 "src/interf/y.tab.cpp" + break; + + case 8: +#line 176 "src/interf/glc.y" + {PRF::prf.Length_Unity(yytext);} +#line 1700 "src/interf/y.tab.cpp" + break; + + case 11: +#line 181 "src/interf/glc.y" + {PRF::prf.Time_Unity(yytext);} +#line 1706 "src/interf/y.tab.cpp" + break; + + case 16: +#line 191 "src/interf/glc.y" + { is_integer = 0; } +#line 1712 "src/interf/y.tab.cpp" + break; + + case 17: +#line 192 "src/interf/glc.y" + { is_integer = 1; } +#line 1718 "src/interf/y.tab.cpp" + break; + + case 18: +#line 193 "src/interf/glc.y" + { is_integer = 0; } +#line 1724 "src/interf/y.tab.cpp" + break; + + case 20: +#line 206 "src/interf/glc.y" + { cout << "Compiling places\n";} +#line 1730 "src/interf/y.tab.cpp" + break; + + case 22: +#line 210 "src/interf/glc.y" + { cout << "Compiling transitions\n";} +#line 1736 "src/interf/y.tab.cpp" + break; + + case 24: +#line 220 "src/interf/glc.y" + { strcpy(idplace,yytext); + if (tour == 1) { + if (bpn->VerifyName(idplace)) + type_error(idplace, Parser_00); + } + } +#line 1747 "src/interf/y.tab.cpp" + break; + + case 25: +#line 227 "src/interf/glc.y" + { if (tour == 1) { + Place *newp; + switch (ptype) { + case Discrete_pl : newp = new DiscretePlace(idplace); + bpn->AddPlace(currentdiscreteplace, newp); + currentdiscreteplace++; + break; + case Continuous_pl : newp = new ContinuousPlace(idplace); + bpn->AddPlace(currentcontinuousplace, newp); + currentcontinuousplace++; + break; + case Batch_pl : newp = new BatchPlace(idplace, pspeed, pdensity, plength); + bpn->AddPlace(currentbatchplace, newp); + currentbatchplace++; + break; + case Triangular_pl : newp = new TriangularBatchPlace(idplace, pspeed, pdensity, plength, pflow); + bpn->AddPlace(currenttriangularplace, newp); + currenttriangularplace++; + break; + } + } + } +#line 1774 "src/interf/y.tab.cpp" + break; + + case 29: +#line 257 "src/interf/glc.y" + { discreteplaces++; ptype = Discrete_pl; } +#line 1780 "src/interf/y.tab.cpp" + break; + + case 30: +#line 258 "src/interf/glc.y" + { continuousplaces++; ptype = Continuous_pl; } +#line 1786 "src/interf/y.tab.cpp" + break; + + case 31: +#line 259 "src/interf/glc.y" + { batchplaces++; ptype = Batch_pl; } +#line 1792 "src/interf/y.tab.cpp" + break; + + case 32: +#line 260 "src/interf/glc.y" + { triangularplaces++; ptype = Triangular_pl;} +#line 1798 "src/interf/y.tab.cpp" + break; + + case 33: +#line 268 "src/interf/glc.y" + { if ((ptype != Batch_pl) && (ptype != Triangular_pl)) { + type_error(yytext, Parser_100); + } + } +#line 1807 "src/interf/y.tab.cpp" + break; + + case 34: +#line 271 "src/interf/glc.y" + { pspeed = atof(yytext); } +#line 1813 "src/interf/y.tab.cpp" + break; + + case 35: +#line 272 "src/interf/glc.y" + { pdensity = atof(yytext); } +#line 1819 "src/interf/y.tab.cpp" + break; + + case 36: +#line 273 "src/interf/glc.y" + { plength = atof(yytext); } +#line 1825 "src/interf/y.tab.cpp" + break; + + case 39: +#line 278 "src/interf/glc.y" + { if (ptype != Triangular_pl) { + type_error(yytext, Parser_101); + } + pflow = atof(yytext); } +#line 1834 "src/interf/y.tab.cpp" + break; + + case 40: +#line 282 "src/interf/glc.y" + { if (ptype == Triangular_pl) { + yyerror(Parser_102); + } + } +#line 1843 "src/interf/y.tab.cpp" + break; + + case 42: +#line 297 "src/interf/glc.y" + { if (tour == 1){ + switch (ptype) { + case Discrete_pl : if (!is_integer){ + type_error(yytext, Parser_104); + } + else{ + bpn->SetInitialMarking((currentdiscreteplace-1), atoi(yytext)); + } + break; + case Continuous_pl : bpn->SetInitialMarking((currentcontinuousplace-1), atof(yytext)); + break; + case Batch_pl : + case Triangular_pl : type_error(yytext, Parser_103); + break; + } + } + } +#line 1865 "src/interf/y.tab.cpp" + break; + + case 44: +#line 318 "src/interf/glc.y" + { blength = atof(yytext); } +#line 1871 "src/interf/y.tab.cpp" + break; + + case 45: +#line 318 "src/interf/glc.y" + { bdensity = atof(yytext); } +#line 1877 "src/interf/y.tab.cpp" + break; + + case 46: +#line 319 "src/interf/glc.y" + { bposition = atof(yytext); } +#line 1883 "src/interf/y.tab.cpp" + break; + + case 47: +#line 320 "src/interf/glc.y" + { if (tour == 1){ + Batch *newb; + ControllableBatch *newcb; + switch (ptype) { + case Discrete_pl : type_error(yytext, Parser_104); + break; + case Continuous_pl : type_error(yytext, Parser_105); + break; + case Batch_pl : newb = new Batch(blength, bdensity, bposition); + bpn->AddBatchToInitialMarking((currentbatchplace-1), *newb); + break; + case Triangular_pl : newcb = new ControllableBatch(blength, bdensity, bposition, bspeed); + bpn->AddTriangularToInitialMarking((currenttriangularplace-1), *newcb); + break; + } + } + } +#line 1905 "src/interf/y.tab.cpp" + break; + + case 52: +#line 346 "src/interf/glc.y" + { bspeed = atof(yytext); } +#line 1911 "src/interf/y.tab.cpp" + break; + + case 53: +#line 347 "src/interf/glc.y" + { bspeed = -1;} +#line 1917 "src/interf/y.tab.cpp" + break; + + case 56: +#line 361 "src/interf/glc.y" + { if (tour == 1){ + switch (ptype) { + case Discrete_pl : if (!is_integer){ + type_error(yytext, Parser_104); + } + else{ + bpn->SetSteadyMarking((currentdiscreteplace-1), atoi(yytext)); + } + break; + case Continuous_pl : bpn->SetSteadyMarking((currentcontinuousplace-1), atof(yytext)); + break; + case Batch_pl : + case Triangular_pl : type_error(yytext, Parser_103); + break; + } + } + } +#line 1939 "src/interf/y.tab.cpp" + break; + + case 58: +#line 382 "src/interf/glc.y" + { blength = atof(yytext); } +#line 1945 "src/interf/y.tab.cpp" + break; + + case 59: +#line 382 "src/interf/glc.y" + { bdensity = atof(yytext); } +#line 1951 "src/interf/y.tab.cpp" + break; + + case 60: +#line 383 "src/interf/glc.y" + { bposition = atof(yytext); } +#line 1957 "src/interf/y.tab.cpp" + break; + + case 61: +#line 384 "src/interf/glc.y" + { if (tour == 1){ + Batch *newb; + ControllableBatch *newcb; + switch (ptype) { + case Discrete_pl : type_error(yytext, Parser_104); + break; + case Continuous_pl : type_error(yytext, Parser_105); + break; + case Batch_pl : newb = new Batch(blength, bdensity, bposition); + bpn->AddBatchToSteadyMarking((currentbatchplace-1), *newb); + break; + case Triangular_pl : newcb = new ControllableBatch(blength, bdensity, bposition, bspeed); + bpn->AddTriangularToSteadyMarking((currenttriangularplace-1), *newcb); + break; + } + } + } +#line 1979 "src/interf/y.tab.cpp" + break; + + case 66: +#line 410 "src/interf/glc.y" + { bspeed = atof(yytext); } +#line 1985 "src/interf/y.tab.cpp" + break; + + case 67: +#line 411 "src/interf/glc.y" + { bspeed = -1;} +#line 1991 "src/interf/y.tab.cpp" + break; + + case 68: +#line 419 "src/interf/glc.y" + { strcpy (idtransition, yytext); } +#line 1997 "src/interf/y.tab.cpp" + break; + + case 69: +#line 420 "src/interf/glc.y" + { if (tour == 2){ + idplacenumber = bpn->GetPlacePosition(idplace); + idtransitionnumber = bpn->GetTransitionPosition(idtransition); + if (idtransitionnumber < 0){ + type_error(idtransition, Parser_106); + } + else{ + if ((bpn->GetTransitionType(idtransition) == Discrete_tr) && !((bpn->GetPlaceType(idplace) == Discrete_pl) || (bpn->GetPlaceType(idplace) == Continuous_pl))){ + type_error(idtransition, Parser_108); + } + else{ + bpn->AddPlaceOutputArc(idplacenumber, idtransitionnumber, arcweight); + } + } + } + } +#line 2018 "src/interf/y.tab.cpp" + break; + + case 73: +#line 444 "src/interf/glc.y" + { arcweight = atof(yytext); } +#line 2024 "src/interf/y.tab.cpp" + break; + + case 75: +#line 445 "src/interf/glc.y" + {arcweight = 1.0;} +#line 2030 "src/interf/y.tab.cpp" + break; + + case 76: +#line 456 "src/interf/glc.y" + { strcpy(idtransition,yytext); + if (tour == 1) { + if (bpn->VerifyName(idtransition)) + type_error(idtransition, Parser_01); + } + } +#line 2041 "src/interf/y.tab.cpp" + break; + + case 77: +#line 463 "src/interf/glc.y" + { tsteadytime = 0.0; + tsteadyflow = 0.0; + } +#line 2049 "src/interf/y.tab.cpp" + break; + + case 78: +#line 467 "src/interf/glc.y" + { if (tour == 1) { + Transition *newt; + switch (ttype) { + case Discrete_tr : newt = new DiscreteTransition(idtransition, ttime, tsteadytime); + bpn->AddTransition(currentdiscretetransition, newt); + currentdiscretetransition++; + break; + case Continuous_tr : newt = new ContinuousTransition(idtransition, tflow, tsteadyflow); + bpn->AddTransition(currentcontinuoustransition, newt); + currentcontinuoustransition++; + break; + case Batch_tr : newt = new BatchTransition(idtransition, tflow, tsteadyflow); + bpn->AddTransition(currentbatchtransition, newt); + currentbatchtransition++; + break; + } + } + } +#line 2072 "src/interf/y.tab.cpp" + break; + + case 82: +#line 494 "src/interf/glc.y" + {discretetransitions++; ttype = Discrete_tr; } +#line 2078 "src/interf/y.tab.cpp" + break; + + case 83: +#line 495 "src/interf/glc.y" + {continuoustransitions++; ttype = Continuous_tr; } +#line 2084 "src/interf/y.tab.cpp" + break; + + case 84: +#line 496 "src/interf/glc.y" + {batchtransitions++; ttype = Batch_tr; } +#line 2090 "src/interf/y.tab.cpp" + break; + + case 85: +#line 500 "src/interf/glc.y" + { ttime = atof(yytext); } +#line 2096 "src/interf/y.tab.cpp" + break; + + case 87: +#line 501 "src/interf/glc.y" + { tflow = atof(yytext); } +#line 2102 "src/interf/y.tab.cpp" + break; + + case 91: +#line 510 "src/interf/glc.y" + { tsteadytime = atof(yytext); } +#line 2108 "src/interf/y.tab.cpp" + break; + + case 93: +#line 511 "src/interf/glc.y" + { tsteadyflow = atof(yytext); } +#line 2114 "src/interf/y.tab.cpp" + break; + + case 95: +#line 521 "src/interf/glc.y" + { strcpy (idplace, yytext); } +#line 2120 "src/interf/y.tab.cpp" + break; + + case 96: +#line 522 "src/interf/glc.y" + { if (tour == 2){ + idtransitionnumber = bpn->GetTransitionPosition(idtransition); + idplacenumber = bpn->GetPlacePosition(idplace); + if (idplacenumber < 0){ + type_error(idplace, Parser_107); + } + else{ + bpn->AddTransitionOutputArc(idtransitionnumber, idplacenumber, arcweight); + } + } + } +#line 2136 "src/interf/y.tab.cpp" + break; + + case 100: +#line 541 "src/interf/glc.y" + { arcweight = atof(yytext); } +#line 2142 "src/interf/y.tab.cpp" + break; + + case 102: +#line 542 "src/interf/glc.y" + {arcweight = 1.0;} +#line 2148 "src/interf/y.tab.cpp" + break; + + case 103: +#line 550 "src/interf/glc.y" + { cout << "Compiling controlled events\n";} +#line 2154 "src/interf/y.tab.cpp" + break; + + case 106: +#line 555 "src/interf/glc.y" + { strcpy(idcevent,yytext); } +#line 2160 "src/interf/y.tab.cpp" + break; + + case 107: +#line 555 "src/interf/glc.y" + { strcpy(idnode, yytext); } +#line 2166 "src/interf/y.tab.cpp" + break; + + case 108: +#line 556 "src/interf/glc.y" + { cevalue = atof(yytext); } +#line 2172 "src/interf/y.tab.cpp" + break; + + case 109: +#line 556 "src/interf/glc.y" + { cedate = atof(yytext); } +#line 2178 "src/interf/y.tab.cpp" + break; + + case 110: +#line 557 "src/interf/glc.y" + { + if (tour == 1){ + Node *evnode = bpn->GetNode(idnode); + ControlledEvent *ev; + if (evnode){ + switch (cetype){ + case Trans_flow_ce : if (bpn->GetTransitionPosition(idnode) == -1){ + type_error(idnode, Parser_110); + } + else{ + if (bpn->GetTransitionType(idnode) == Discrete_tr) { + type_error(idnode, Parser_113); + } + else{ + ev = new ControlledEvent(idnode, *evnode, cedate, Trans_flow_ce, cevalue, idcevent); + schedule->AddControlledEvent(*ev, Trans_flow_ce); + } + } + break; + case Place_speed_ce : if (bpn->GetPlacePosition(idnode) == -1){ + type_error(idnode, Parser_111); + } + else{ + if (bpn->GetPlaceType(idnode) != Triangular_pl) { + type_error(idnode, Parser_112); + } + else{ + ev = new ControlledEvent(idnode, *evnode, cedate, Place_speed_ce, cevalue, idcevent); + schedule->AddControlledEvent(*ev, Place_speed_ce); + } + } + break; + } + } + else{ + type_error(idnode, Parser_109); + } + } + } +#line 2222 "src/interf/y.tab.cpp" + break; + + case 114: +#line 604 "src/interf/glc.y" + { cetype = Trans_flow_ce; } +#line 2228 "src/interf/y.tab.cpp" + break; + + case 115: +#line 605 "src/interf/glc.y" + {cetype = Place_speed_ce; } +#line 2234 "src/interf/y.tab.cpp" + break; + + case 116: +#line 613 "src/interf/glc.y" + { cout << "Compiling inspection points\n";} +#line 2240 "src/interf/y.tab.cpp" + break; + + case 119: +#line 618 "src/interf/glc.y" + { strcpy(idbreakpoint,yytext); } +#line 2246 "src/interf/y.tab.cpp" + break; + + case 120: +#line 618 "src/interf/glc.y" + { bpdate = atof(yytext); } +#line 2252 "src/interf/y.tab.cpp" + break; + + case 121: +#line 618 "src/interf/glc.y" + { strcpy(idnode, yytext); } +#line 2258 "src/interf/y.tab.cpp" + break; + + case 122: +#line 619 "src/interf/glc.y" + { + if (tour == 1){ + Node *bpnode = bpn->GetNode(idnode); + Breakpoint *bp; + if ((bpnode) || (!strcmp(idnode, "places")) || (!strcmp(idnode, "transitions"))){ + bp = new Breakpoint(idnode, *bpnode, bpdate, bptype, idbreakpoint); + schedule->AddBreakpoint(*bp); + } + else{ + type_error(idnode, Parser_109); + } + } + } +#line 2276 "src/interf/y.tab.cpp" + break; + + case 126: +#line 641 "src/interf/glc.y" + { bptype = at_bp; } +#line 2282 "src/interf/y.tab.cpp" + break; + + case 127: +#line 642 "src/interf/glc.y" + { bptype = every_bp; } +#line 2288 "src/interf/y.tab.cpp" + break; + + +#line 2292 "src/interf/y.tab.cpp" + + default: break; + } + /* User semantic actions sometimes alter yychar, and that requires + that yytoken be updated with the new translation. We take the + approach of translating immediately before every use of yytoken. + One alternative is translating here after every semantic action, + but that translation would be missed if the semantic action invokes + YYABORT, YYACCEPT, or YYERROR immediately after altering yychar or + if it invokes YYBACKUP. In the case of YYABORT or YYACCEPT, an + incorrect destructor might then be invoked immediately. In the + case of YYERROR or YYBACKUP, subsequent parser actions might lead + to an incorrect destructor call or verbose syntax error message + before the lookahead is translated. */ + YY_SYMBOL_PRINT ("-> $$ =", yyr1[yyn], &yyval, &yyloc); + + YYPOPSTACK (yylen); + yylen = 0; + YY_STACK_PRINT (yyss, yyssp); + + *++yyvsp = yyval; + + /* Now 'shift' the result of the reduction. Determine what state + that goes to, based on the state we popped back to and the rule + number reduced by. */ + { + const int yylhs = yyr1[yyn] - YYNTOKENS; + const int yyi = yypgoto[yylhs] + *yyssp; + yystate = (0 <= yyi && yyi <= YYLAST && yycheck[yyi] == *yyssp + ? yytable[yyi] + : yydefgoto[yylhs]); + } + + goto yynewstate; + + +/*--------------------------------------. +| yyerrlab -- here on detecting error. | +`--------------------------------------*/ +yyerrlab: + /* Make sure we have latest lookahead translation. See comments at + user semantic actions for why this is necessary. */ + yytoken = yychar == YYEMPTY ? YYEMPTY : YYTRANSLATE (yychar); + + /* If not already recovering from an error, report this error. */ + if (!yyerrstatus) + { + ++yynerrs; +#if ! YYERROR_VERBOSE + yyerror (YY_("syntax error")); +#else +# define YYSYNTAX_ERROR yysyntax_error (&yymsg_alloc, &yymsg, \ + yyssp, yytoken) + { + char const *yymsgp = YY_("syntax error"); + int yysyntax_error_status; + yysyntax_error_status = YYSYNTAX_ERROR; + if (yysyntax_error_status == 0) + yymsgp = yymsg; + else if (yysyntax_error_status == 1) + { + if (yymsg != yymsgbuf) + YYSTACK_FREE (yymsg); + yymsg = YY_CAST (char *, YYSTACK_ALLOC (YY_CAST (YYSIZE_T, yymsg_alloc))); + if (!yymsg) + { + yymsg = yymsgbuf; + yymsg_alloc = sizeof yymsgbuf; + yysyntax_error_status = 2; + } + else + { + yysyntax_error_status = YYSYNTAX_ERROR; + yymsgp = yymsg; + } + } + yyerror (yymsgp); + if (yysyntax_error_status == 2) + goto yyexhaustedlab; + } +# undef YYSYNTAX_ERROR +#endif + } + + + + if (yyerrstatus == 3) + { + /* If just tried and failed to reuse lookahead token after an + error, discard it. */ + + if (yychar <= YYEOF) + { + /* Return failure if at end of input. */ + if (yychar == YYEOF) + YYABORT; + } + else + { + yydestruct ("Error: discarding", + yytoken, &yylval); + yychar = YYEMPTY; + } + } + + /* Else will try to reuse lookahead token after shifting the error + token. */ + goto yyerrlab1; + + +/*---------------------------------------------------. +| yyerrorlab -- error raised explicitly by YYERROR. | +`---------------------------------------------------*/ +yyerrorlab: + /* Pacify compilers when the user code never invokes YYERROR and the + label yyerrorlab therefore never appears in user code. */ + if (0) + YYERROR; + + /* Do not reclaim the symbols of the rule whose action triggered + this YYERROR. */ + YYPOPSTACK (yylen); + yylen = 0; + YY_STACK_PRINT (yyss, yyssp); + yystate = *yyssp; + goto yyerrlab1; + + +/*-------------------------------------------------------------. +| yyerrlab1 -- common code for both syntax error and YYERROR. | +`-------------------------------------------------------------*/ +yyerrlab1: + yyerrstatus = 3; /* Each real token shifted decrements this. */ + + for (;;) + { + yyn = yypact[yystate]; + if (!yypact_value_is_default (yyn)) + { + yyn += YYTERROR; + if (0 <= yyn && yyn <= YYLAST && yycheck[yyn] == YYTERROR) + { + yyn = yytable[yyn]; + if (0 < yyn) + break; + } + } + + /* Pop the current state because it cannot handle the error token. */ + if (yyssp == yyss) + YYABORT; + + + yydestruct ("Error: popping", + yystos[yystate], yyvsp); + YYPOPSTACK (1); + yystate = *yyssp; + YY_STACK_PRINT (yyss, yyssp); + } + + YY_IGNORE_MAYBE_UNINITIALIZED_BEGIN + *++yyvsp = yylval; + YY_IGNORE_MAYBE_UNINITIALIZED_END + + + /* Shift the error token. */ + YY_SYMBOL_PRINT ("Shifting", yystos[yyn], yyvsp, yylsp); + + yystate = yyn; + goto yynewstate; + + +/*-------------------------------------. +| yyacceptlab -- YYACCEPT comes here. | +`-------------------------------------*/ +yyacceptlab: + yyresult = 0; + goto yyreturn; + + +/*-----------------------------------. +| yyabortlab -- YYABORT comes here. | +`-----------------------------------*/ +yyabortlab: + yyresult = 1; + goto yyreturn; + + +#if !defined yyoverflow || YYERROR_VERBOSE +/*-------------------------------------------------. +| yyexhaustedlab -- memory exhaustion comes here. | +`-------------------------------------------------*/ +yyexhaustedlab: + yyerror (YY_("memory exhausted")); + yyresult = 2; + /* Fall through. */ +#endif + + +/*-----------------------------------------------------. +| yyreturn -- parsing is finished, return the result. | +`-----------------------------------------------------*/ +yyreturn: + if (yychar != YYEMPTY) + { + /* Make sure we have latest lookahead translation. See comments at + user semantic actions for why this is necessary. */ + yytoken = YYTRANSLATE (yychar); + yydestruct ("Cleanup: discarding lookahead", + yytoken, &yylval); + } + /* Do not reclaim the symbols of the rule whose action triggered + this YYABORT or YYACCEPT. */ + YYPOPSTACK (yylen); + YY_STACK_PRINT (yyss, yyssp); + while (yyssp != yyss) + { + yydestruct ("Cleanup: popping", + yystos[+*yyssp], yyvsp); + YYPOPSTACK (1); + } +#ifndef yyoverflow + if (yyss != yyssa) + YYSTACK_FREE (yyss); +#endif +#if YYERROR_VERBOSE + if (yymsg != yymsgbuf) + YYSTACK_FREE (yymsg); +#endif + return yyresult; +} +#line 655 "src/interf/glc.y" + + + +void Init_Variables() +{ + yylineno = 0; + + //current place/transition + currentdiscreteplace = 0; + currentcontinuousplace = discreteplaces; + currentbatchplace = continuousplaces + discreteplaces; + currenttriangularplace = batchplaces + continuousplaces + discreteplaces; + + currentdiscretetransition = 0; + currentcontinuoustransition = discretetransitions; + currentbatchtransition = continuoustransitions + discretetransitions; +} + + +//int main(int argv, char *argc[]) +void Compile_Network(const simuleau_name bpn_level_name, const simuleau_name str_level_name) +{ + int totalplaces; + int totaltransitions; + ofstream fstr; + simuleau_name bpn_file; + + + strcpy(bpn_file, bpn_level_name); strcat(bpn_file,".bpn"); + + + //first tour: semantical analysis and number of places and transitions + tour = 0; + //counters + discreteplaces = 0; + continuousplaces = 0; + batchplaces = 0; + triangularplaces = 0; + + discretetransitions = 0; + continuoustransitions = 0; + batchtransitions = 0; + + Init_Variables(); + yyin = fopen(bpn_file, "r"); + cout << "Start model compilation\n\n"; + + cout << "First turn\n" + << "==========\n"; + cout << "Creating places and transitions structures\n"; + cout << "Creating controlled events schedule\n"; + yyparse(); + fclose(yyin); + + totalplaces = discreteplaces + continuousplaces + batchplaces + triangularplaces; + totaltransitions = discretetransitions + continuoustransitions + batchtransitions; + + if (bpn!=NULL) + delete bpn; + bpn = new BPN(totalplaces, totaltransitions); + + if (schedule!=NULL) + delete schedule; + schedule = new Schedule; + + // places initialisation + bpn->NumberOfDiscretePlaces(discreteplaces); + bpn->NumberOfContinuousPlaces(continuousplaces); + bpn->NumberOfBatchPlaces(batchplaces); + bpn->NumberOfTriangularBatchPlaces(triangularplaces); + + // transitions initialisation + bpn->NumberOfDiscreteTransitions(discretetransitions); + bpn->NumberOfContinuousTransitions(continuoustransitions); + bpn->NumberOfBatchTransitions(batchtransitions); + + + // second tour + if(!not_error){ + exit (EXIT_FAILURE); + } + + cout << "\nSecond turn\n" + << "===========\n"; + cout << "Initialising places and transitions parameters\n"; + tour++; + Init_Variables(); + yyin = fopen(bpn_file, "r"); + yyrestart(yyin); + yyparse(); + fclose(yyin); + + + // thrid tour + if(!not_error){ + exit (EXIT_FAILURE); + } + + cout << "\nThrid turn\n" + << "==========\n"; + cout << "Initialising places and transitions arcs\n"; + tour++; + bpn->AllocArcs(); + Init_Variables(); + yyin = fopen(bpn_file, "r"); + yyrestart(yyin); + yyparse(); + fclose(yyin); + bpn->AddNodeLinks(); + if(!not_error){ + exit (EXIT_FAILURE); + } + + cout << endl << bpn->GetName() << " model created\n"; + + Open_File(str_level_name, str_file, fstr); + bpn->Print(fstr); + Close_File(str_level_name, str_file, fstr); +} diff --git a/src/interf/y.tab.h b/src/interf/y.tab.h new file mode 100644 index 0000000000000000000000000000000000000000..7421cb10ed3e86f0baf082aa98d2021f47d07713 --- /dev/null +++ b/src/interf/y.tab.h @@ -0,0 +1,152 @@ +/* A Bison parser, made by GNU Bison 3.0.4. */ + +/* Bison interface for Yacc-like parsers in C + + Copyright (C) 1984, 1989-1990, 2000-2015 Free Software Foundation, Inc. + + This program is free software: you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation, either version 3 of the License, or + (at your option) any later version. + + This program is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with this program. If not, see <http://www.gnu.org/licenses/>. */ + +/* As a special exception, you may create a larger work that contains + part or all of the Bison parser skeleton and distribute that work + under terms of your choice, so long as that work isn't itself a + parser generator using the skeleton or a modified version thereof + as a parser skeleton. Alternatively, if you modify or redistribute + the parser skeleton itself, you may (at your option) remove this + special exception, which will cause the skeleton and the resulting + Bison output files to be licensed under the GNU General Public + License without this special exception. + + This special exception was added by the Free Software Foundation in + version 2.2 of Bison. */ + +#ifndef YY_YY_Y_TAB_HPP_INCLUDED +# define YY_YY_Y_TAB_HPP_INCLUDED +/* Debug traces. */ +#ifndef YYDEBUG +# define YYDEBUG 1 +#endif +#if YYDEBUG +extern int yydebug; +#endif + +/* Token type. */ +#ifndef YYTOKENTYPE +# define YYTOKENTYPE + enum yytokentype + { + TK_ARC = 258, + TK_BATCH = 259, + TK_CONTINUOUS = 260, + TK_CONTROLLED = 261, + TK_DESCRIPTION = 262, + TK_DISCRETE = 263, + TK_EVENTS = 264, + TK_FLOW = 265, + TK_FUNCTION = 266, + TK_INITIAL = 267, + TK_INSPECTION = 268, + TK_LENGTH = 269, + TK_MARKING = 270, + TK_MODEL = 271, + TK_NETWORK = 272, + TK_OUTPUT = 273, + TK_PLACE = 274, + TK_PLACES = 275, + TK_SPEED = 276, + TK_STEADY = 277, + TK_TIME = 278, + TK_TIMING = 279, + TK_TRANSITION = 280, + TK_TRANSITIONS = 281, + TK_TRIANGULAR = 282, + TK_UNITY = 283, + TK_ID = 284, + TK_INTEGER = 285, + TK_REAL = 286, + TK_EXPONENT = 287, + TK_AT = 288, + TK_EVERY = 289, + TK_LEFT_BRACKET = 290, + TK_RIGHT_BRACKET = 291, + TK_PL_TR = 292, + TK_ALL = 293, + TK_LEFT_PARENTHESIS = 294, + TK_RIGHT_PARENTHESIS = 295, + TK_LEFT_SQUARE_BRACKET = 296, + TK_RIGHT_SQUARE_BRACKET = 297, + TK_SEMICOLON = 298, + TK_COMMA = 299, + TK_ATTRIB = 300, + TK_COLON = 301 + }; +#endif +/* Tokens. */ +#define TK_ARC 258 +#define TK_BATCH 259 +#define TK_CONTINUOUS 260 +#define TK_CONTROLLED 261 +#define TK_DESCRIPTION 262 +#define TK_DISCRETE 263 +#define TK_EVENTS 264 +#define TK_FLOW 265 +#define TK_FUNCTION 266 +#define TK_INITIAL 267 +#define TK_INSPECTION 268 +#define TK_LENGTH 269 +#define TK_MARKING 270 +#define TK_MODEL 271 +#define TK_NETWORK 272 +#define TK_OUTPUT 273 +#define TK_PLACE 274 +#define TK_PLACES 275 +#define TK_SPEED 276 +#define TK_STEADY 277 +#define TK_TIME 278 +#define TK_TIMING 279 +#define TK_TRANSITION 280 +#define TK_TRANSITIONS 281 +#define TK_TRIANGULAR 282 +#define TK_UNITY 283 +#define TK_ID 284 +#define TK_INTEGER 285 +#define TK_REAL 286 +#define TK_EXPONENT 287 +#define TK_AT 288 +#define TK_EVERY 289 +#define TK_LEFT_BRACKET 290 +#define TK_RIGHT_BRACKET 291 +#define TK_PL_TR 292 +#define TK_ALL 293 +#define TK_LEFT_PARENTHESIS 294 +#define TK_RIGHT_PARENTHESIS 295 +#define TK_LEFT_SQUARE_BRACKET 296 +#define TK_RIGHT_SQUARE_BRACKET 297 +#define TK_SEMICOLON 298 +#define TK_COMMA 299 +#define TK_ATTRIB 300 +#define TK_COLON 301 + +/* Value type. */ +#if ! defined YYSTYPE && ! defined YYSTYPE_IS_DECLARED +typedef int YYSTYPE; +# define YYSTYPE_IS_TRIVIAL 1 +# define YYSTYPE_IS_DECLARED 1 +#endif + + +extern YYSTYPE yylval; + +int yyparse (void); + +#endif /* !YY_YY_Y_TAB_HPP_INCLUDED */ diff --git a/src/interf/y.tab.hpp b/src/interf/y.tab.hpp new file mode 100644 index 0000000000000000000000000000000000000000..0acf8e53adcef7dd735b7d80f40705d6bad188ae --- /dev/null +++ b/src/interf/y.tab.hpp @@ -0,0 +1,156 @@ +/* A Bison parser, made by GNU Bison 3.5.1. */ + +/* Bison interface for Yacc-like parsers in C + + Copyright (C) 1984, 1989-1990, 2000-2015, 2018-2020 Free Software Foundation, + Inc. + + This program is free software: you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation, either version 3 of the License, or + (at your option) any later version. + + This program is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with this program. If not, see <http://www.gnu.org/licenses/>. */ + +/* As a special exception, you may create a larger work that contains + part or all of the Bison parser skeleton and distribute that work + under terms of your choice, so long as that work isn't itself a + parser generator using the skeleton or a modified version thereof + as a parser skeleton. Alternatively, if you modify or redistribute + the parser skeleton itself, you may (at your option) remove this + special exception, which will cause the skeleton and the resulting + Bison output files to be licensed under the GNU General Public + License without this special exception. + + This special exception was added by the Free Software Foundation in + version 2.2 of Bison. */ + +/* Undocumented macros, especially those whose name start with YY_, + are private implementation details. Do not rely on them. */ + +#ifndef YY_YY_SRC_INTERF_Y_TAB_HPP_INCLUDED +# define YY_YY_SRC_INTERF_Y_TAB_HPP_INCLUDED +/* Debug traces. */ +#ifndef YYDEBUG +# define YYDEBUG 1 +#endif +#if YYDEBUG +extern int yydebug; +#endif + +/* Token type. */ +#ifndef YYTOKENTYPE +# define YYTOKENTYPE + enum yytokentype + { + TK_ARC = 258, + TK_BATCH = 259, + TK_CONTINUOUS = 260, + TK_CONTROLLED = 261, + TK_DESCRIPTION = 262, + TK_DISCRETE = 263, + TK_EVENTS = 264, + TK_FLOW = 265, + TK_FUNCTION = 266, + TK_INITIAL = 267, + TK_INSPECTION = 268, + TK_LENGTH = 269, + TK_MARKING = 270, + TK_MODEL = 271, + TK_NETWORK = 272, + TK_OUTPUT = 273, + TK_PLACE = 274, + TK_PLACES = 275, + TK_SPEED = 276, + TK_STEADY = 277, + TK_TIME = 278, + TK_TIMING = 279, + TK_TRANSITION = 280, + TK_TRANSITIONS = 281, + TK_TRIANGULAR = 282, + TK_UNITY = 283, + TK_ID = 284, + TK_INTEGER = 285, + TK_REAL = 286, + TK_EXPONENT = 287, + TK_AT = 288, + TK_EVERY = 289, + TK_LEFT_BRACKET = 290, + TK_RIGHT_BRACKET = 291, + TK_PL_TR = 292, + TK_ALL = 293, + TK_LEFT_PARENTHESIS = 294, + TK_RIGHT_PARENTHESIS = 295, + TK_LEFT_SQUARE_BRACKET = 296, + TK_RIGHT_SQUARE_BRACKET = 297, + TK_SEMICOLON = 298, + TK_COMMA = 299, + TK_ATTRIB = 300, + TK_COLON = 301 + }; +#endif +/* Tokens. */ +#define TK_ARC 258 +#define TK_BATCH 259 +#define TK_CONTINUOUS 260 +#define TK_CONTROLLED 261 +#define TK_DESCRIPTION 262 +#define TK_DISCRETE 263 +#define TK_EVENTS 264 +#define TK_FLOW 265 +#define TK_FUNCTION 266 +#define TK_INITIAL 267 +#define TK_INSPECTION 268 +#define TK_LENGTH 269 +#define TK_MARKING 270 +#define TK_MODEL 271 +#define TK_NETWORK 272 +#define TK_OUTPUT 273 +#define TK_PLACE 274 +#define TK_PLACES 275 +#define TK_SPEED 276 +#define TK_STEADY 277 +#define TK_TIME 278 +#define TK_TIMING 279 +#define TK_TRANSITION 280 +#define TK_TRANSITIONS 281 +#define TK_TRIANGULAR 282 +#define TK_UNITY 283 +#define TK_ID 284 +#define TK_INTEGER 285 +#define TK_REAL 286 +#define TK_EXPONENT 287 +#define TK_AT 288 +#define TK_EVERY 289 +#define TK_LEFT_BRACKET 290 +#define TK_RIGHT_BRACKET 291 +#define TK_PL_TR 292 +#define TK_ALL 293 +#define TK_LEFT_PARENTHESIS 294 +#define TK_RIGHT_PARENTHESIS 295 +#define TK_LEFT_SQUARE_BRACKET 296 +#define TK_RIGHT_SQUARE_BRACKET 297 +#define TK_SEMICOLON 298 +#define TK_COMMA 299 +#define TK_ATTRIB 300 +#define TK_COLON 301 + +/* Value type. */ +#if ! defined YYSTYPE && ! defined YYSTYPE_IS_DECLARED +typedef int YYSTYPE; +# define YYSTYPE_IS_TRIVIAL 1 +# define YYSTYPE_IS_DECLARED 1 +#endif + + +extern YYSTYPE yylval; + +int yyparse (void); + +#endif /* !YY_YY_SRC_INTERF_Y_TAB_HPP_INCLUDED */ diff --git a/src/simul/breakpoint.cpp b/src/simul/breakpoint.cpp new file mode 100644 index 0000000000000000000000000000000000000000..2e567951f8f0ab10090e2b18a0d201fd2653af68 --- /dev/null +++ b/src/simul/breakpoint.cpp @@ -0,0 +1,170 @@ +//====================================================================================// +// // +// Breakpoint class // +// // +//====================================================================================// +// This File: breakpoint.cpp Language: C++ (xlC and CC) // +// Software: SIMULEAU // +//====================================================================================// +// Creation: 27/septembre/17 by: Leonardo.Brenner@lsis.org // +// Last Change: 27/septembre/17 by: Leonardo.Brenner@lsis.org // +//====================================================================================// +#include "simuleau.h" + +//------------------------------------------------------------------------------ +//------------------------------------------------------------------------------ +// Methods of the Breakpoint class +//------------------------------------------------------------------------------ +//------------------------------------------------------------------------------ + +//------------------------------------------------------------------------------ +// Constructor +//------------------------------------------------------------------------------ +Breakpoint::Breakpoint() +{ + //ctor +} + +//------------------------------------------------------------------------------ +// Initialized constructor +//------------------------------------------------------------------------------ +Breakpoint::Breakpoint(simuleau_name _idnode, Node& _node, double _date_frequency, breakpoint_type _type, simuleau_name _name) +{ + node = &_node; + strcpy(idnode, _idnode); + strcpy(name, _name); + type = _type; + + if (type == at_bp) { + date = _date_frequency; + } + else{ + date = 0.0; + frequency = _date_frequency; + } +} + +//------------------------------------------------------------------------------ +// Destructor +//------------------------------------------------------------------------------ +Breakpoint::~Breakpoint() +{ + //dtor +} + +//------------------------------------------------------------------------------ +// Copy +//------------------------------------------------------------------------------ +void Breakpoint::Copy(const Breakpoint &_breakpoint) +{ + date = _breakpoint.date; + node = _breakpoint.node; + type = _breakpoint.type; + frequency = _breakpoint.frequency; + + strcpy(name, _breakpoint.name); + strcpy(idnode, _breakpoint.idnode); +} + +//------------------------------------------------------------------------------ +// It returns breakpoint name +//------------------------------------------------------------------------------ +char* Breakpoint::GetName() +{ + return (name); +} + +//------------------------------------------------------------------------------ +// It returns breakpoint node id +// places represents all places and transitions represents all transitions +//------------------------------------------------------------------------------ +char* Breakpoint::GetNodeId() +{ + return (idnode); +} + +//------------------------------------------------------------------------------ +// Return the node related to the breakpoint +//------------------------------------------------------------------------------ +Node* Breakpoint::GetNode(BPN *_bpn) +{ + node = _bpn->GetNode(idnode); + return (node); +} + +//------------------------------------------------------------------------------ +// Return the breakpoint date +//------------------------------------------------------------------------------ +double Breakpoint::GetDate(double currentdate) +{ + + if (type == at_bp) + return (date); + else{ + date = (((int) currentdate/frequency) + 1) * frequency; + return (date); + } +} + +//------------------------------------------------------------------------------ +// Return the breakpoint type +// at_bp for pontual breakpoint +// every_bp for recurent breakpoint +//------------------------------------------------------------------------------ +breakpoint_type Breakpoint::GetType() +{ + return (type); +} + +//------------------------------------------------------------------------------ +// Return the textual breakpoint description +//------------------------------------------------------------------------------ +char* Breakpoint::GetDescription() +{ + switch (type) + { + case at_bp: return("Breakpoint at a specific date"); + case every_bp: return("Recurent breakpoint"); + } +} + + +//------------------------------------------------------------------------------ +// Print +//------------------------------------------------------------------------------ +void Breakpoint::Print(ostream &fout) +{ + fout << "Breakpoint Name: " << name << endl; + fout << "Node Name: " << idnode << endl; + if (type == at_bp){ + fout << "Date: " << date << endl; + } + else{ + fout << "Frequency: " << frequency << endl; + } + fout << "Type: " << GetDescription() << endl; +} + +//------------------------------------------------------------------------------ +// Print +//------------------------------------------------------------------------------ +void Breakpoint::PrintPlaceTransition(BPN *_bpn, ostream &fout) +{ + Node *bpnode; + + fout << "Breakpoint Name: " << name << endl; + + if (!strcmp(idnode,"places")){ // print all places + _bpn->WritePlaces(fout); + return; + } + + if (!strcmp(idnode,"transitions")){ // print all transitions + _bpn->WriteFlows(fout); + return; + } + + //print just one place or transition + bpnode = GetNode(_bpn); + bpnode->Print(fout); +} diff --git a/src/simul/breakpoint.h b/src/simul/breakpoint.h new file mode 100644 index 0000000000000000000000000000000000000000..8b8da458eff3340e4c91ac2b7193898da4e7fa57 --- /dev/null +++ b/src/simul/breakpoint.h @@ -0,0 +1,54 @@ +//====================================================================================// +// // +// Breakpoint class // +// // +//====================================================================================// +// This File: breakpoint.h Language: C++ (xlC and CC) // +// Software: SIMULEAU // +//====================================================================================// +// Creation: 27/septembre/17 by: Leonardo.Brenner@lsis.org // +// Last Change: 27/septembre/17 by: Leonardo.Brenner@lsis.org // +//====================================================================================// +#ifndef BREAKPOINT_H +#define BREAKPOINT_H + +//====================================================================================// +// Generic breakpoint class // +//====================================================================================// +// Breakpoint class implements breakpoint to inspect the state of places and // +// transitions at date where it have no events. // +//====================================================================================// +class Breakpoint +{ + public: + Breakpoint(); + Breakpoint(simuleau_name _idnode, Node& _node, double _date_frequency, breakpoint_type _type, simuleau_name _name); + ~Breakpoint(); + + void Copy(const Breakpoint &_breakpoint); + + //output functions + char* GetName(); + char* GetNodeId(); + Node* GetNode(BPN *_bpn); + double GetDate(double currentdate); + breakpoint_type GetType(); + char* GetDescription(); + + // print functions + void Print(ostream &fout); + void PrintPlaceTransition(BPN *_bpn, ostream &fout); + + protected: + Node *node; + simuleau_name idnode; + simuleau_name name; + double date; + double frequency; + breakpoint_type type; + + private: +}; + + +#endif // BREAKPOINT_H diff --git a/src/simul/event.cpp b/src/simul/event.cpp new file mode 100644 index 0000000000000000000000000000000000000000..945d9da25d5c4060a24acd423010a29fb105b3fe --- /dev/null +++ b/src/simul/event.cpp @@ -0,0 +1,222 @@ +//====================================================================================// +// // +// Event class // +// // +//====================================================================================// +// This File: event.cpp Language: C++ (xlC and CC) // +// Software: SIMULEAU // +//====================================================================================// +// Creation: 07/may/16 by: Leonardo.Brenner@lsis.org // +// Last Change: 07/may/16 by: Leonardo.Brenner@lsis.org // +//====================================================================================// +#include "simuleau.h" + +//------------------------------------------------------------------------------ +//------------------------------------------------------------------------------ +// Methods of the Event class +//------------------------------------------------------------------------------ +//------------------------------------------------------------------------------ + +//------------------------------------------------------------------------------ +// Constructor +//------------------------------------------------------------------------------ +Event::Event() +{ + //ctor +} + +//------------------------------------------------------------------------------ +// Initialized constructor +//------------------------------------------------------------------------------ +Event::Event(Node &_node, double _date, ev_type _type) +{ + node = &_node; + date = _date; + type = _type; +} + +//------------------------------------------------------------------------------ +// Destructor +//------------------------------------------------------------------------------ +Event::~Event() +{ + //dtor +} + +//------------------------------------------------------------------------------ +// Copy +//------------------------------------------------------------------------------ +void Event::Copy(const Event &_event) +{ + date = _event.date; + node = _event.node; + type = _event.type; +} + +//------------------------------------------------------------------------------ +// Return the event date +//------------------------------------------------------------------------------ +double Event::GetDate() +{ + return (date); +} + +//------------------------------------------------------------------------------ +// Return the event type +//------------------------------------------------------------------------------ +ev_type Event::GetType() +{ + return (type); +} + +//------------------------------------------------------------------------------ +// Return the node related to the event +//------------------------------------------------------------------------------ +Node* Event::GetNode() +{ + return (node); +} + +//------------------------------------------------------------------------------ +// Return the textual event description +//------------------------------------------------------------------------------ +char* Event::GetDescription() +{ + switch (type) + { + case Discr_trans_fires: return("Discrete transition is fired"); + case Cont_place_empty: return("Continuous place becomes empty"); + case Discr_trans_enabled: return("Discrete transition becomes enable"); + case Becomes_output_batch:return("Batch becomes an output batch"); + case Destr_output_batch: return("Destruction of an output batch"); + case Batch_becomes_dense: return("Batch becomes dense"); + case Two_batches_meet: return("Two batches meet"); + case Batch_meets_output_batch: return("A batch meets an output batch"); + case Output_batch_decongestion: return("Decongestion of the output batch"); + case Batch_decongestion: return("Decongestion of a batch in contact ahead"); + case Batch_becomes_free: return("Full decongestion of a batch alone"); + case Place_steady_quan: return("Place reaches steady marking quantity"); + case Remaining_becomes_freesteadyquan: return("Remaining quantity passed by an input transition becomes free steady quantity"); + } +} + +//------------------------------------------------------------------------------ +// Print +//------------------------------------------------------------------------------ +void Event::Print(ostream &fout) +{ + fout << "Date: " << date << endl; + node->Print(fout); +} + +//------------------------------------------------------------------------------ +//------------------------------------------------------------------------------ +// Methods of the Controlled Event class +//------------------------------------------------------------------------------ +//------------------------------------------------------------------------------ + +//------------------------------------------------------------------------------ +// Constructor +//------------------------------------------------------------------------------ +ControlledEvent::ControlledEvent() +{ + +} + +//------------------------------------------------------------------------------ +// Initialized constructor +//------------------------------------------------------------------------------ +ControlledEvent::ControlledEvent(Node& _node, double _date, ev_type _type, double _value, simuleau_name _name):Event(_node, _date, _type) +{ + value = _value; + strcpy(name, _name); +} + +//------------------------------------------------------------------------------ +// Initialized constructor +//------------------------------------------------------------------------------ +ControlledEvent::ControlledEvent(simuleau_name _idnode, Node& _node, double _date, ev_type _type, double _value, simuleau_name _name):Event(_node, _date, _type) +{ + value = _value; + strcpy(name, _name); + strcpy(idnode, _idnode); +} + +//------------------------------------------------------------------------------ +// Destructor +//------------------------------------------------------------------------------ +ControlledEvent::~ControlledEvent() +{ + +} + +//------------------------------------------------------------------------------ +// Copy +//------------------------------------------------------------------------------ +void ControlledEvent::Copy(const ControlledEvent &_event) +{ + date = _event.date; + node = _event.node; + type = _event.type; + + strcpy(name, _event.name); + strcpy(idnode, _event.idnode); + value = _event.value; +} + +//------------------------------------------------------------------------------ +// It returns controlled event name +//------------------------------------------------------------------------------ +char* ControlledEvent::GetName() +{ + return (name); +} + +//------------------------------------------------------------------------------ +// It returns controlled event value +//------------------------------------------------------------------------------ +double ControlledEvent::GetValue() +{ + return (value); +} + +//------------------------------------------------------------------------------ +// Return the node related to the event +//------------------------------------------------------------------------------ +Node* ControlledEvent::GetNode(BPN *_bpn) +{ + node = _bpn->GetNode(idnode); + return (node); +} + +//------------------------------------------------------------------------------ +// It returns controlled event node id +//------------------------------------------------------------------------------ +char* ControlledEvent::GetNodeId() +{ + return (idnode); +} + +//------------------------------------------------------------------------------ +// Return the textual event description +//------------------------------------------------------------------------------ +char* ControlledEvent::GetDescription() +{ + switch (type) + { + case Trans_flow_ce: return("Transition maximum flow changes"); + case Place_speed_ce: return("Place maximum speed changes"); + } +} + +//------------------------------------------------------------------------------ +// Print +//------------------------------------------------------------------------------ +void ControlledEvent::Print(ostream &fout) +{ + fout << "Event Name: " << name << endl; + fout << "Node Name: " << idnode << endl; + fout << "Date: " << date << endl; + fout << "Type: " << GetDescription() << endl; + fout << "Value: " << value << endl; +} diff --git a/src/simul/event.h b/src/simul/event.h new file mode 100644 index 0000000000000000000000000000000000000000..317378a3a9519332b24ba8657b354f4a8d460ee2 --- /dev/null +++ b/src/simul/event.h @@ -0,0 +1,89 @@ +//====================================================================================// +// // +// Event class // +// // +//====================================================================================// +// This File: event.h Language: C++ (xlC and CC) // +// Software: SIMULEAU // +//====================================================================================// +// Creation: 07/may/16 by: Leonardo.Brenner@lsis.org // +// Last Change: 07/may/16 by: Leonardo.Brenner@lsis.org // +//====================================================================================// +#ifndef EVENT_H +#define EVENT_H + +//====================================================================================// +// Generic event class // +//====================================================================================// +// Event class implements a generic event that will be used to implement all types // +// of events in the schedule class. // +//====================================================================================// +class Event +{ + public: + Event(); + Event(Node &_node, double _date, ev_type _type); + virtual ~Event(); + + void Copy(const Event &_event); + + //output functions + double GetDate(); + ev_type GetType(); + Node* GetNode(); + virtual char* GetDescription(); + + // print functions + virtual void Print(ostream &fout); + + protected: + Node *node; + double date; + ev_type type; + + private: +}; + + + +//====================================================================================// +// Controlled event class // +//====================================================================================// +// Controlled event class implements the storage of external controlled events // +// readed from the input bpn file these events modify the flow or speed of transitions// +// or places. // +//====================================================================================// +class ControlledEvent : public Event +{ + public: + ControlledEvent(); + ControlledEvent(Node &_node, double _date, ev_type _type, double _value, simuleau_name _name); + ControlledEvent(simuleau_name _idnode, Node& _node, double _date, ev_type _type, double _value, simuleau_name _name); + + virtual ~ControlledEvent(); + + void Copy(const ControlledEvent &_event); + + //output functions + char* GetName(); + double GetValue(); + Node* GetNode(BPN *_bpn); + char* GetNodeId(); + char* GetDescription(); + + // print functions + void Print(ostream &fout); + + protected: + double value; + simuleau_name idnode; + simuleau_name name; + + private: +}; + + + + + +#endif // EVENT_H diff --git a/src/simul/schedule.cpp b/src/simul/schedule.cpp new file mode 100644 index 0000000000000000000000000000000000000000..146d29b0d764e0fdfe0320afba6ff52709c84848 --- /dev/null +++ b/src/simul/schedule.cpp @@ -0,0 +1,967 @@ +//====================================================================================// +// // +// Schedule class // +// // +//====================================================================================// +// This File: schedule.cpp Language: C++ (xlC and CC) // +// Software: SIMULEAU // +//====================================================================================// +// Creation: 08/may/16 by: Leonardo.Brenner@lsis.org // +// Last Change: 24/jan/20 by: Leonardo.Brenner@lsis.org // +//====================================================================================// +#include "simuleau.h" + + +//------------------------------------------------------------------------------ +// Constructor +//------------------------------------------------------------------------------ +Schedule::Schedule() +{ + dtf = new list<Event>; // Discrete Transition is Fired + dtf->clear(); + cpe = new list<Event>; // Continuous Place becomes Empty + cpe->clear(); + dte = new list<Event>; // Discrete Transition becomes Enable + dte->clear(); + bob = new list<Event>; // Batch becomes an Output Batch + bob->clear(); + dob = new list<Event>; // Destruction of an Output Batch + dob->clear(); + bbd = new list<Event>; // Batch Becomes Dense + bbd->clear(); + tbm = new list<Event>; // Two Batches Meet + tbm->clear(); + bmob = new list<Event>; // A batch meets an output batch + bmob->clear(); + obd = new list<Event>; // Decongestion of the output batch + obd->clear(); + bd = new list<Event>; // Decongestion of a batch in contact head + bd->clear(); + bbf = new list<Event>; // Full decongestion of a batch alone + bbf->clear(); + psq = new list<Event>; // Place reaches Steady marking Quantity + psq->clear(); + rbf = new list<Event>; // Remaining quantity entered by an input transition becomes equal to free steady marking quantity. + rbf->clear(); + + + tfce = new list<ControlledEvent>; // Transition maximum Flow changes + tfce->clear(); + psce = new list<ControlledEvent>; // Place maximum Speed changes + psce->clear(); + + breakpoint = new list<Breakpoint>; + breakpoint->clear(); + + nextevents = new list<Event>; + nextevents->clear(); + + nextcontrolledevents = new list<ControlledEvent>; + nextcontrolledevents->clear(); + + nextbreakpoints = new list<Breakpoint>; + nextbreakpoints->clear(); +} + +//------------------------------------------------------------------------------ +// Destructor +//------------------------------------------------------------------------------ +Schedule::~Schedule() +{ + if (dtf) + delete dtf; + if (cpe) + delete cpe; + if (dte) + delete dte; + if (bob) + delete bob; + if (dob) + delete dob; + if (bbd) + delete bbd; + if (tbm) + delete tbm; + if (bmob) + delete bmob; + if (obd) + delete obd; + if (bd) + delete bd; + if (bbd) + delete bbf; + if (psq) + delete psq; + if (rbf) + delete rbf; + + + if (tfce) + delete tfce; + if (psce) + delete psce; + + if (breakpoint) + delete breakpoint; + + if (nextevents) + delete nextevents; + + if (nextcontrolledevents) + delete nextcontrolledevents; + + if (nextbreakpoints) + delete nextbreakpoints; +} + + +//------------------------------------------------------------------------------ +// Copy +//------------------------------------------------------------------------------ +void Schedule::Copy(const Schedule *_schedule) +{ + dtf->clear(); + for (list<Event>::iterator it=_schedule->dtf->begin(); it!=_schedule->dtf->end(); ++it) { + Event *newevent = new Event; + newevent->Copy(*it); + dtf->push_back(*newevent); + } + + cpe->clear(); + for (list<Event>::iterator it=_schedule->cpe->begin(); it!=_schedule->cpe->end(); ++it) { + Event *newevent = new Event; + newevent->Copy(*it); + cpe->push_back(*newevent); + } + + dte->clear(); + for (list<Event>::iterator it=_schedule->dte->begin(); it!=_schedule->dte->end(); ++it) { + Event *newevent = new Event; + newevent->Copy(*it); + dte->push_back(*newevent); + } + + bob->clear(); + for (list<Event>::iterator it=_schedule->bob->begin(); it!=_schedule->bob->end(); ++it) { + Event *newevent = new Event; + newevent->Copy(*it); + bob->push_back(*newevent); + } + + dob->clear(); + for (list<Event>::iterator it=_schedule->dob->begin(); it!=_schedule->dob->end(); ++it) { + Event *newevent = new Event; + newevent->Copy(*it); + dob->push_back(*newevent); + } + + bbd->clear(); + for (list<Event>::iterator it=_schedule->bbd->begin(); it!=_schedule->bbd->end(); ++it) { + Event *newevent = new Event; + newevent->Copy(*it); + bbd->push_back(*newevent); + } + + tbm->clear(); + for (list<Event>::iterator it=_schedule->tbm->begin(); it!=_schedule->tbm->end(); ++it) { + Event *newevent = new Event; + newevent->Copy(*it); + tbm->push_back(*newevent); + } + + bmob->clear(); + for (list<Event>::iterator it=_schedule->bmob->begin(); it!=_schedule->bmob->end(); ++it) { + Event *newevent = new Event; + newevent->Copy(*it); + bmob->push_back(*newevent); + } + + obd->clear(); + for (list<Event>::iterator it=_schedule->obd->begin(); it!=_schedule->obd->end(); ++it) { + Event *newevent = new Event; + newevent->Copy(*it); + obd->push_back(*newevent); + } + + bd->clear(); + for (list<Event>::iterator it=_schedule->bd->begin(); it!=_schedule->bd->end(); ++it) { + Event *newevent = new Event; + newevent->Copy(*it); + bd->push_back(*newevent); + } + + bbf->clear(); + for (list<Event>::iterator it=_schedule->bbf->begin(); it!=_schedule->bbf->end(); ++it) { + Event *newevent = new Event; + newevent->Copy(*it); + bbf->push_back(*newevent); + } + + psq->clear(); + for (list<Event>::iterator it=_schedule->psq->begin(); it!=_schedule->psq->end(); ++it) { + Event *newevent = new Event; + newevent->Copy(*it); + psq->push_back(*newevent); + } + + rbf->clear(); + for (list<Event>::iterator it=_schedule->rbf->begin(); it!=_schedule->rbf->end(); ++it) { + Event *newevent = new Event; + newevent->Copy(*it); + rbf->push_back(*newevent); + } + + + + + tfce->clear(); + for (list<ControlledEvent>::iterator it=_schedule->tfce->begin(); it!=_schedule->tfce->end(); ++it) { + ControlledEvent *newevent = new ControlledEvent; + newevent->Copy(*it); + tfce->push_back(*newevent); + } + + psce->clear(); + for (list<ControlledEvent>::iterator it=_schedule->psce->begin(); it!=_schedule->psce->end(); ++it) { + ControlledEvent *newevent = new ControlledEvent; + newevent->Copy(*it); + psce->push_back(*newevent); + } + + breakpoint->clear(); + for (list<Breakpoint>::iterator it=_schedule->breakpoint->begin(); it!=_schedule->breakpoint->end(); ++it) { + Breakpoint *newbreakpoint = new Breakpoint; + newbreakpoint->Copy(*it); + breakpoint->push_back(*newbreakpoint); + } + + nextevents->clear(); + for (list<Event>::iterator it=_schedule->nextevents->begin(); it!=_schedule->nextevents->end(); ++it) { + Event *newevent = new Event; + newevent->Copy(*it); + nextevents->push_back(*newevent); + } + + nextcontrolledevents->clear(); + for (list<ControlledEvent>::iterator it=_schedule->nextcontrolledevents->begin(); it!=_schedule->nextcontrolledevents->end(); ++it) { + ControlledEvent *newevent = new ControlledEvent; + newevent->Copy(*it); + nextcontrolledevents->push_back(*newevent); + } + + nextbreakpoints->clear(); + for (list<Breakpoint>::iterator it=_schedule->nextbreakpoints->begin(); it!=_schedule->nextbreakpoints->end(); ++it) { + Breakpoint *newbreakpoint = new Breakpoint; + newbreakpoint->Copy(*it); + nextbreakpoints->push_back(*newbreakpoint); + } +} + +//------------------------------------------------------------------------------ +// Add a new event +//------------------------------------------------------------------------------ +void Schedule::AddEvent(Event& e, ev_type type) +{ + switch(type){ + case Discr_trans_fires: dtf->push_back(e); + break; + case Cont_place_empty: cpe->push_back(e); + break; + case Discr_trans_enabled: dte->push_back(e); + break; + case Becomes_output_batch:bob->push_back(e); + break; + case Destr_output_batch: dob->push_back(e); + break; + case Batch_becomes_dense: bbd->push_back(e); + break; + case Two_batches_meet: tbm->push_back(e); + break; + case Batch_meets_output_batch: bmob->push_back(e); + break; + case Output_batch_decongestion: obd->push_back(e); + break; + case Batch_decongestion: bd->push_back(e); + break; + case Batch_becomes_free: bbf->push_back(e); + break; + case Place_steady_quan: psq->push_back(e); // place reaches steady marking quantity + break; + case Remaining_becomes_freesteadyquan: rbf->push_back(e); //Remaining marking quantity entered by an input transition becomes free steady quantity. + break; + } +} + +//------------------------------------------------------------------------------ +// Add a new controlled external event from the input bpn file +//------------------------------------------------------------------------------ +void Schedule::AddControlledEvent(ControlledEvent& ce, ev_type type) +{ + switch(type){ + case Trans_flow_ce: tfce->push_back(ce); + break; + case Place_speed_ce: psce->push_back(ce); + break; + } +} + +//------------------------------------------------------------------------------ +// Add a new breakpoint from the input bpn file +//------------------------------------------------------------------------------ +void Schedule::AddBreakpoint(Breakpoint& bp) +{ + breakpoint->push_back(bp); +} + +//------------------------------------------------------------------------------ +// Add a new controlled external event from the input bpn file +//------------------------------------------------------------------------------ +char* Schedule::GetEventDescription(ev_type type) +{ + switch (type) + { + case Discr_trans_fires: return("Discrete transition is fired"); + case Cont_place_empty: return("Continuous place becomes empty"); + case Discr_trans_enabled: return("Discrete transition becomes enable"); + case Becomes_output_batch:return("Batch becomes an output batch"); + case Destr_output_batch: return("Destruction of an output batch"); + case Batch_becomes_dense: return("Batch becomes dense"); + case Two_batches_meet: return("Two batches meet"); + case Batch_meets_output_batch: return("A batch meets an output batch"); + case Output_batch_decongestion: return("Decongestion of the output batch"); + case Batch_decongestion: return("Decongestion of a batch in contact ahead"); + case Batch_becomes_free: return("Full decongestion of a batch alone"); + case Place_steady_quan: return("Place reaches steady marking quantity"); + case Trans_flow_ce: return("Transition maximum flow changes"); + case Place_speed_ce: return("Place maximum speed changes"); + case Remaining_becomes_freesteadyquan: return("Remaining quantity passed by an input transition becomes free steady quantity"); + } +} + +//------------------------------------------------------------------------------ +// Add a new controlled external event from the input bpn file +//------------------------------------------------------------------------------ +char* Schedule::GetBreakpointDescription(breakpoint_type type) +{ + switch (type) + { + case at_bp: return("Breakpoint at a specific date"); + case every_bp: return("Recurent breakpoint"); + } +} + +//------------------------------------------------------------------------------ +// Returns true if the schedule doesn't have more events to proceed +//------------------------------------------------------------------------------ +int Schedule::IsEmpty() +{ + if (nextevents->empty() && nextcontrolledevents->empty() && nextbreakpoints->empty()) + return (1); + else + return (0); +} + +//------------------------------------------------------------------------------ +// This fonction delete all controlled event that are before the current date +//------------------------------------------------------------------------------ +void Schedule::Clean(list<ControlledEvent> *cevl, double _currentdate) +{ + int numerofcontrolledevents = cevl->size(); + + for (int i=0; i<numerofcontrolledevents; i++){ + ControlledEvent *ce = new ControlledEvent; + *ce = cevl->front(); + cevl->pop_front(); + double eventdate = ce->GetDate(); + + if (eventdate <= _currentdate){ + continue; + } + else{ + cevl->push_back(*ce); + } + } +} + +//------------------------------------------------------------------------------ +// This fonction delete all controlled event +//------------------------------------------------------------------------------ +void Schedule::CleanAll() +{ + int numerofcontrolledevents = tfce->size(); + + for (int i=0; i<numerofcontrolledevents; i++){ + ControlledEvent *ce = new ControlledEvent; + *ce = tfce->front(); + tfce->pop_front(); + } + + numerofcontrolledevents = psce->size(); + + for (int i=0; i<numerofcontrolledevents; i++){ + ControlledEvent *ce = new ControlledEvent; + *ce = tfce->front(); + psce->pop_front(); + } +} + +//------------------------------------------------------------------------------ +// Print +//------------------------------------------------------------------------------ +void Schedule::PrintEvents(ostream &fout) +{ + cout << "Discrete transition is fired: " << dtf->size() << endl; + for (list<Event>::iterator it=dtf->begin(); it!=dtf->end(); ++it) { + it->Print(fout); + } + + cout << "\nContinuous place becomes empty: " << cpe->size() << endl; + for (list<Event>::iterator it=cpe->begin(); it!=cpe->end(); ++it) { + it->Print(fout); + } + + cout << "\nDiscrete transition becomes enable: " << dte->size() << endl; + for (list<Event>::iterator it=dte->begin(); it!=dte->end(); ++it) { + it->Print(fout); + } + + cout << "\nBatch becomes an output batch: " << bob->size() << endl; + for (list<Event>::iterator it=bob->begin(); it!=bob->end(); ++it) { + it->Print(fout); + } + + cout << "\nDestruction of an output batch: " << dob->size() << endl; + for (list<Event>::iterator it=dob->begin(); it!=dob->end(); ++it) { + it->Print(fout); + } + + cout << "\nBatch becomes dense: " << bbd->size() << endl; + for (list<Event>::iterator it=bbd->begin(); it!=bbd->end(); ++it) { + it->Print(fout); + } + + cout << "\nTwo batches meet: " << tbm->size() << endl; + for (list<Event>::iterator it=tbm->begin(); it!=tbm->end(); ++it) { + it->Print(fout); + } + + cout << "\nA batch meets an output batch: " << bmob->size() << endl; + for (list<Event>::iterator it=bmob->begin(); it!=bmob->end(); ++it) { + it->Print(fout); + } + + cout << "\nDecongestion of the output batch: " << obd->size() << endl; + for (list<Event>::iterator it=obd->begin(); it!=obd->end(); ++it) { + it->Print(fout); + } + + cout << "\nDecongestion of a batch in contact ahead: " << bd->size() << endl; + for (list<Event>::iterator it=bd->begin(); it!=bd->end(); ++it) { + it->Print(fout); + } + + cout << "\nFull decongestion of a batch alone: " << bbf->size() << endl; + for (list<Event>::iterator it=bbf->begin(); it!=bbf->end(); ++it) { + it->Print(fout); + } + + cout << "\nPlace reaches steady marking quantity: " << psq->size() << endl; + for (list<Event>::iterator it=psq->begin(); it!=psq->end(); ++it) { + it->Print(fout); + } + + cout << "\nRemain quantity passed by an input transition becomes free steady quantity : " << rbf->size() << endl; + for (list<Event>::iterator it=rbf->begin(); it!=rbf->end(); ++it) { + it->Print(fout); + } + +} + +//------------------------------------------------------------------------------ +// Print +//------------------------------------------------------------------------------ +void Schedule::PrintCE(ostream &fout) +{ + cout << "Transition maximum flow changes: " << tfce->size() << endl; + for (list<ControlledEvent>::iterator it=tfce->begin(); it!=tfce->end(); ++it) { + it->Print(fout); + } + cout << endl; + + cout << "Place maximum speed changes: " << psce->size() << endl; + for (list<ControlledEvent>::iterator it=psce->begin(); it!=psce->end(); ++it) { + it->Print(fout); + } +} + +//------------------------------------------------------------------------------ +// Print +//------------------------------------------------------------------------------ +void Schedule::PrintBP(ostream &fout) +{ + for (list<Breakpoint>::iterator it=breakpoint->begin(); it!=breakpoint->end(); ++it) { + it->Print(fout); + } +} + +//------------------------------------------------------------------------------ +// Print +//------------------------------------------------------------------------------ +void Schedule::Print(ostream &fout) +{ + fout << "Schedule" << endl; + fout << "========" << endl; + + fout << "Events\n" + << "------" << endl; + PrintEvents(fout); + + fout << "\nControlled events\n" + << "-----------------" << endl; + PrintCE(fout); + + fout << "\nBreakpoints\n" + << "-----------" << endl; + PrintBP(fout); +} + +//------------------------------------------------------------------------------ +// It writes the events list in the file +//------------------------------------------------------------------------------ +void Schedule::WriteEvents(ofstream &fout) +{ + if (!dtf->empty()){ + fout << "\bDiscrete transition is fired: " << dtf->size() << endl; + for (list<Event>::iterator it=dtf->begin(); it!=dtf->end(); ++it) { + fout << "Date " << it->GetDate() << "\t node " << (it->GetNode())->GetName() << endl; + } + } + + if (!cpe->empty()){ + fout << "\nContinuous place becomes empty: " << cpe->size() << endl; + for (list<Event>::iterator it=cpe->begin(); it!=cpe->end(); ++it) { + fout << "Date " << it->GetDate() << "\t node " << (it->GetNode())->GetName() << endl; + } + } + + if (!dte->empty()){ + fout << "\nDiscrete transition becomes enable: " << dte->size() << endl; + for (list<Event>::iterator it=dte->begin(); it!=dte->end(); ++it) { + fout << "Date " << it->GetDate() << "\t node " << (it->GetNode())->GetName() << endl; + } + } + + if (!bob->empty()){ + fout << "\nBatch becomes an output batch: " << bob->size() << endl; + for (list<Event>::iterator it=bob->begin(); it!=bob->end(); ++it) { + fout << "Date " << it->GetDate() << "\t node " << (it->GetNode())->GetName() << endl; + } + } + + if (!dob->empty()){ + fout << "\nDestruction of an output batch: " << dob->size() << endl; + for (list<Event>::iterator it=dob->begin(); it!=dob->end(); ++it) { + fout << "Date " << it->GetDate() << "\t node " << (it->GetNode())->GetName() << endl; + } + } + + if (!bbd->empty()){ + fout << "\nBatch becomes dense: " << bbd->size() << endl; + for (list<Event>::iterator it=bbd->begin(); it!=bbd->end(); ++it) { + fout << "Date " << it->GetDate() << "\t node " << (it->GetNode())->GetName() << endl; + } + } + + if (!tbm->empty()){ + fout << "\nTwo batches meet: " << tbm->size() << endl; + for (list<Event>::iterator it=tbm->begin(); it!=tbm->end(); ++it) { + fout << "Date " << it->GetDate() << "\t node " << (it->GetNode())->GetName() << endl; + } + } + + if (!bmob->empty()){ + fout << "\nA batch meets an output batch: " << bmob->size() << endl; + for (list<Event>::iterator it=bmob->begin(); it!=bmob->end(); ++it) { + fout << "Date " << it->GetDate() << "\t node " << (it->GetNode())->GetName() << endl; + } + } + + if (!obd->empty()){ + fout << "\nDecongestion of the output batch: " << obd->size() << endl; + for (list<Event>::iterator it=obd->begin(); it!=obd->end(); ++it) { + fout << "Date " << it->GetDate() << "\t node " << (it->GetNode())->GetName() << endl; + } + } + + if (!bd->empty()){ + fout << "\nDecongestion of a batch in contact ahead: " << bd->size() << endl; + for (list<Event>::iterator it=bd->begin(); it!=bd->end(); ++it) { + fout << "Date " << it->GetDate() << "\t node " << (it->GetNode())->GetName() << endl; + } + } + + if (!bbf->empty()){ + fout << "\nFull decongestion of a batch alone: " << bbf->size() << endl; + for (list<Event>::iterator it=bbf->begin(); it!=bbf->end(); ++it) { + fout << "Date " << it->GetDate() << "\t node " << (it->GetNode())->GetName() << endl; + } + } + + if (!psq->empty()){ + fout << "\nPlace reaches steady marking quantity: " << psq->size() << endl; + for (list<Event>::iterator it=psq->begin(); it!=psq->end(); ++it) { + fout << "Date " << it->GetDate() << "\t node " << (it->GetNode())->GetName() << endl; + // it->Print(fout); + } + } + + if (!rbf->empty()){ + fout << "\nRemain quantity passed by an input transition becomes free steady quantity: " << rbf->size() << endl; + for (list<Event>::iterator it=rbf->begin(); it!=rbf->end(); ++it) { + fout << "Date " << it->GetDate() << "\t node " << (it->GetNode())->GetName() << endl; + // it->Print(fout); + } + } + +} + +//------------------------------------------------------------------------------ +// It writes the controlled events list in the file +//------------------------------------------------------------------------------ +void Schedule::WriteCE(ofstream &fout) +{ + Clean(tfce, simulation->stime->GetCurrentDate()); + Clean(psce, simulation->stime->GetCurrentDate()); + + if (!tfce->empty() || !psce->empty()) + fout << endl << "Controlled Events" << endl; + + + if (!tfce->empty()){ + fout << "\nTransition maximum flow changes: " << tfce->size() << endl; + for (list<ControlledEvent>::iterator it=tfce->begin(); it!=tfce->end(); ++it) { + fout << "Date " << it->GetDate() << "\t node " << (it->GetNodeId()) << "\t name " << it->GetName() << endl; + } + } + + if (!psce->empty()){ + fout << "\nPlace maximum speed changes: " << psce->size() << endl; + for (list<ControlledEvent>::iterator it=psce->begin(); it!=psce->end(); ++it) { + fout << "Date " << it->GetDate() << "\t node " << (it->GetNodeId()) << "\t name " << it->GetName() << endl; + } + } + +} + +//------------------------------------------------------------------------------ +// It writes the breakpoint list in the file +//------------------------------------------------------------------------------ +void Schedule::WriteBP(ofstream &fout) +{ + if (!breakpoint->empty()){ + fout << "\nBreakpoints: " << breakpoint->size() << endl; + for (list<Breakpoint>::iterator it=breakpoint->begin(); it!=breakpoint->end(); ++it) { + fout << "Date " << it->GetDate(simulation->stime->GetCurrentDate()) << "\t node " << (it->GetNodeId()) << "\t name " << it->GetName() << endl; + } + fout << endl; + } +} + + +//------------------------------------------------------------------------------ +// It writes the events list to be proceed in the next date +//------------------------------------------------------------------------------ +void Schedule::WriteNextEvents(ofstream &fout) +{ + if (!nextevents->empty()){ + for (list<Event>::iterator it=nextevents->begin(); it!=nextevents->end(); ++it) { + fout << "Event date " << it->GetDate() << "\t in node " << (it->GetNode())->GetName() << "\t type " << it->GetDescription() << endl; + } + } + + if (!nextcontrolledevents->empty()){ + for (list<ControlledEvent>::iterator it=nextcontrolledevents->begin(); it!=nextcontrolledevents->end(); ++it) { + fout << "Event date " << it->GetDate() << "\t in node " << (it->GetNodeId()) << "\t type " << it->GetDescription() << endl; + } + } + + if (!nextbreakpoints->empty()){ + for (list<Breakpoint>::iterator it=nextbreakpoints->begin(); it!=nextbreakpoints->end(); ++it) { + fout << "Breakpoint date " << it->GetDate(simulation->stime->GetCurrentDate()) << "\t in node " << (it->GetNodeId()) << "\t type " << it->GetDescription() << endl; + } + } +} + +//------------------------------------------------------------------------------ +// Compute events +//------------------------------------------------------------------------------ +void Schedule::ComputeEvents(BPN *_bpn) +{ + _bpn->ComputeNextEventDTF(dtf); + _bpn->ComputeNextEventCPE(cpe); + _bpn->ComputeNextEventDTE(dte); + _bpn->ComputeNextEventBOB(bob); + _bpn->ComputeNextEventDOB(dob); + _bpn->ComputeNextEventBBD(bbd); + _bpn->ComputeNextEventTBM(tbm); + _bpn->ComputeNextEventBMOB(bmob); + _bpn->ComputeNextEventOBD(obd); + _bpn->ComputeNextEventBD(bd); + _bpn->ComputeNextEventBBF(bbf); + _bpn->ComputeNextEventPSQ(psq); + _bpn->ComputeNextEventRBF(rbf); +} + +//------------------------------------------------------------------------------ +// Compute next date +//------------------------------------------------------------------------------ +void Schedule::ComputeNextDate(BPN *_bpn, double duration) +{ + // clean all non-controlled events + dtf->clear(); + cpe->clear(); + dte->clear(); + bob->clear(); + dob->clear(); + bbd->clear(); + tbm->clear(); + bmob->clear(); + obd->clear(); + bd->clear(); + bbf->clear(); + psq->clear(); + rbf->clear(); + + ComputeEvents(_bpn); +} + +//------------------------------------------------------------------------------ +// Compute next event +//------------------------------------------------------------------------------ +double Schedule::ComputeNextEvent(double duration) +{ + double nextdate = duration; + + if (!dtf->empty()) + nextdate = ComputeNextEventDate(dtf, nextdate, Discr_trans_fires); + + if (!cpe->empty()) + nextdate = ComputeNextEventDate(cpe, nextdate, Cont_place_empty); + + if (!dte->empty()) + nextdate = ComputeNextEventDate(dte, nextdate, Discr_trans_enabled); + + if (!bob->empty()) + nextdate = ComputeNextEventDate(bob, nextdate, Becomes_output_batch); + + if (!dob->empty()) + nextdate = ComputeNextEventDate(dob, nextdate, Destr_output_batch); + + if (!bbd->empty()) + nextdate = ComputeNextEventDate(bbd, nextdate, Batch_becomes_dense); + + if (!tbm->empty()) + nextdate = ComputeNextEventDate(tbm, nextdate, Two_batches_meet); + + if (!bmob->empty()) + nextdate = ComputeNextEventDate(bmob, nextdate, Batch_meets_output_batch); + + if (!obd->empty()) + nextdate = ComputeNextEventDate(obd, nextdate, Output_batch_decongestion); + + if (!bd->empty()) + nextdate = ComputeNextEventDate(bd, nextdate, Batch_decongestion); + + if (!bbf->empty()) + nextdate = ComputeNextEventDate(bbf, nextdate, Batch_becomes_free); + + if (!psq->empty()) + nextdate = ComputeNextEventDate(psq, nextdate, Place_steady_quan); + + if (!rbf->empty()) + nextdate = ComputeNextEventDate(rbf, nextdate, Remaining_becomes_freesteadyquan); + + + // controlled events + if (!tfce->empty()) + nextdate = ComputeNextControlledEventDate(tfce, nextdate, Trans_flow_ce); + + if (!psce->empty()) + nextdate = ComputeNextControlledEventDate(psce, nextdate, Place_speed_ce); + + // breakpoint + if (!breakpoint->empty()) + nextdate = ComputeNextBreakpointDate(breakpoint, nextdate); + + return (nextdate); +} + +//------------------------------------------------------------------------------ +// Compute a date for an event list +//------------------------------------------------------------------------------ +double Schedule::ComputeNextEventDate(list<Event> *evl, double nextdate, ev_type type) +{ + while (!evl->empty()){ + Event *e = new Event; + *e = evl->front(); + evl->pop_front(); + double eventdate = e->GetDate(); + + if (abs(eventdate - nextdate) < PRF::prf.Min_Err()) { // both events in the same date + nextevents->push_back(*e); + } + + if (((nextdate - eventdate) > PRF::prf.Min_Err()) && (eventdate >= simulation->stime->GetCurrentDate())) { + nextdate = eventdate; + nextevents->clear(); + nextevents->push_back(*e); + } + else{ + delete e; + } + } + + for (list<Event>::iterator it=nextevents->begin(); it!=nextevents->end(); ++it) { + double eventdate = it->GetDate(); + if (nextdate < eventdate) + nextdate = eventdate; + } + return (nextdate); +} + +//------------------------------------------------------------------------------ +// Compute a date for a controlled event list +//------------------------------------------------------------------------------ +double Schedule::ComputeNextControlledEventDate(list<ControlledEvent> *cevl, double nextdate, ev_type type) +{ + int numerofcontrolledevents = cevl->size(); + + for (int i=0; i<numerofcontrolledevents; i++){ + ControlledEvent *ce = new ControlledEvent; + *ce = cevl->front(); + cevl->pop_front(); + double eventdate = ce->GetDate(); + + if (eventdate <= simulation->stime->GetCurrentDate()){ + continue; + } + else{ + cevl->push_back(*ce); + } + + if (eventdate == nextdate) { // both events in the same date + nextcontrolledevents->push_back(*ce); + } + + if (eventdate < nextdate ) { + nextdate = eventdate; + nextevents->clear(); + nextcontrolledevents->clear(); + nextcontrolledevents->push_back(*ce); + } + } + + return (nextdate); +} + +//------------------------------------------------------------------------------ +// Compute a date for the next breakpoint +//------------------------------------------------------------------------------ +double Schedule::ComputeNextBreakpointDate(list<Breakpoint> *bpl, double nextdate) +{ + int numberofbreakpoints = bpl->size(); + nextbreakpoints->clear(); + + if (nextevents->empty() && nextcontrolledevents->empty()){ + return(nextdate); + } + + for (int i=0; i<numberofbreakpoints; i++){ + Breakpoint *bp = new Breakpoint; + *bp = bpl->front(); + bpl->pop_front(); + double breakpointdate = bp->GetDate(simulation->stime->GetCurrentDate()); + + if (breakpointdate <= simulation->stime->GetCurrentDate()){ + continue; + } + else{ + bpl->push_back(*bp); + } + + if (breakpointdate == nextdate) { // both events in the same date + nextbreakpoints->push_back(*bp); + } + + if (breakpointdate < nextdate) { + nextdate = breakpointdate; + nextevents->clear(); + nextcontrolledevents->clear(); + nextbreakpoints->clear(); + nextbreakpoints->push_back(*bp); + } + } + return (nextdate); +} + +//------------------------------------------------------------------------------ +// Process events +// TODO - process controled events +//------------------------------------------------------------------------------ +void Schedule::ProcessEvents(BPN *_bpn) +{ + int type; + double speed; + + while (!nextcontrolledevents->empty()){ + ControlledEvent *ce = new ControlledEvent; + *ce = nextcontrolledevents->front(); + nextcontrolledevents->pop_front(); + + type = ce->GetType(); + + switch(type){ + case Place_speed_ce : { + TriangularBatchPlace *tbp = ce->GetNode(_bpn); + tbp->SetAndRecomputeSpeed(ce->GetValue()); + } + break; + case Trans_flow_ce : { + BatchTransition *bt = ce->GetNode(_bpn); + Flow *fl = bt->GetFlow(); + fl->SetMaximumFlow(ce->GetValue()); + bt->Print(cout); + } + break; + } + + } + + while (!nextevents->empty()){ + Event *e = new Event; + *e = nextevents->front(); + nextevents->pop_front(); + + switch(e->GetType()){ + case Discr_trans_fires : DiscreteTransition *dt = e->GetNode(); + dt->FireDiscreteTransition(); + + break; + } + } + +} + +//------------------------------------------------------------------------------ +// Process breakpoints - this function print the bpn at the breakpoint +//------------------------------------------------------------------------------ +void Schedule::ProcessBreakpoints(BPN *_bpn) +{ + while (!nextbreakpoints->empty()){ + Breakpoint *bp = new Breakpoint; + *bp = nextbreakpoints->front(); + nextbreakpoints->pop_front(); + + bp->PrintPlaceTransition(_bpn, std::cout); + } +} diff --git a/src/simul/schedule.h b/src/simul/schedule.h new file mode 100644 index 0000000000000000000000000000000000000000..aa7e7076b2c0e037576ef7be9d88570dfa5f32e1 --- /dev/null +++ b/src/simul/schedule.h @@ -0,0 +1,85 @@ +//====================================================================================// +// // +// Schedule class // +// // +//====================================================================================// +// This File: schedule.h Language: C++ (xlC and CC) // +// Software: SIMULEAU // +//====================================================================================// +// Creation: 08/may/16 by: Leonardo.Brenner@lsis.org // +// Last Change: 24/jan/20 by: Leonardo.Brenner@lsis.org // +//====================================================================================// +#ifndef SCHEDULE_H +#define SCHEDULE_H + +extern Simulate *simulation; + +class Schedule +{ + public: + Schedule(); + virtual ~Schedule(); + + void Copy(const Schedule *_schedule); + + //input functions + void AddEvent(Event& e, ev_type type); + void AddControlledEvent(ControlledEvent& ce, ev_type type); + void AddBreakpoint(Breakpoint& bp); + + //output functions + char* GetEventDescription(ev_type type); + char* GetBreakpointDescription(breakpoint_type type); + int IsEmpty(); + void Clean(list<ControlledEvent> *cevl, double _currentdate); + void CleanAll(); + + //print functions + void PrintEvents(ostream &fout); + void PrintCE(ostream &fout); + void PrintBP(ostream &fout); + void Print(ostream &fout); + void WriteEvents(ofstream & fout); + void WriteCE(ofstream & fout); + void WriteBP(ofstream & fout); + void WriteNextEvents(ofstream & fout); + + //simulation functions + void ComputeEvents(BPN *_bpn); + void ComputeNextDate(BPN *_bpn, double duration); + double ComputeNextEvent(double duration); + double ComputeNextEventDate(list<Event> *evl, double nextdate, ev_type type); + double ComputeNextControlledEventDate(list<ControlledEvent> *cevl, double nextdate, ev_type type); + double ComputeNextBreakpointDate(list<Breakpoint> *bpl, double nextdate); + void ProcessEvents(BPN *_bpn); + void ProcessBreakpoints(BPN *_bpn); + + protected: + list<Event> *dtf; // Discrete Transition is Fired + list<Event> *cpe; // Continuous Place becomes Empty + list<Event> *dte; // Discrete Transition becomes Enable + list<Event> *bob; // Batch becomes an Output Batch + list<Event> *dob; // Destruction of an Output Batch + list<Event> *bbd; // Batch Becomes Dense + list<Event> *tbm; // Two Batches Meet + list<Event> *bmob; // A batch meets an output batch + list<Event> *obd; // Decongestion of the output batch + list<Event> *bd; // Decongestion of a batch in contact head + list<Event> *bbf; // Full decongestion of an alone batch + list<Event> *psq; // Place reaches Steady marking quantity + list<Event> *rbf; // Remaining quantity passed by an input transition becomes equal to free steady quantity. + + list<ControlledEvent> *tfce; // Transition maximum Flow changes + list<ControlledEvent> *psce; // Place maximum Speed changes + + list<Breakpoint> *breakpoint; // breakpoint to print results + + list<Event> *nextevents; // list of the next events to be simulated + list<ControlledEvent> *nextcontrolledevents; // list of the next controlled events to be simulated + list<Breakpoint> *nextbreakpoints; // list of the next breakpoint to be simulated + + + private: +}; + +#endif // SCHEDULE_H diff --git a/src/simul/simtime.cpp b/src/simul/simtime.cpp new file mode 100644 index 0000000000000000000000000000000000000000..8fda6c242be65eecbc2ef4a1ac28f3ea60219764 --- /dev/null +++ b/src/simul/simtime.cpp @@ -0,0 +1,99 @@ +//====================================================================================// +// // +// Simtime class // +// // +//====================================================================================// +// This File: simtime.cpp Language: C++ (xlC and CC) // +// Software: SIMULEAU // +//====================================================================================// +// Creation: 11/may/16 by: Leonardo.Brenner@lsis.org // +// Last Change: 11/may/16 by: Leonardo.Brenner@lsis.org // +//====================================================================================// +#include "simuleau.h" + + +//------------------------------------------------------------------------------ +// Constructor +//------------------------------------------------------------------------------ +Simtime::Simtime() +{ + currentdate = 0.0; + previousdate = 0.0; + nextdate = 0.0; +} + +//------------------------------------------------------------------------------ +// Destructor +//------------------------------------------------------------------------------ +Simtime::~Simtime() +{ + //dtor +} + +//------------------------------------------------------------------------------ +// Set all dates to zero +//------------------------------------------------------------------------------ +void Simtime::Reset() +{ + previousdate = currentdate = nextdate = 0.0; +} + +//------------------------------------------------------------------------------ +// Permute dates +//------------------------------------------------------------------------------ +void Simtime::Permute() +{ + previousdate = currentdate; + currentdate = nextdate; +} + +//------------------------------------------------------------------------------ +// Compute steptime +//------------------------------------------------------------------------------ +double Simtime::StepTime() +{ + return (currentdate - previousdate); +} + +//------------------------------------------------------------------------------ +// Set the next date +//------------------------------------------------------------------------------ +void Simtime::SetNextDate(double _nd) +{ + nextdate = _nd; +} + + +//------------------------------------------------------------------------------ +// Return the previous date +//------------------------------------------------------------------------------ +double Simtime::GetPreviousDate() +{ + return previousdate; +} + +//------------------------------------------------------------------------------ +// Return the current date +//------------------------------------------------------------------------------ +double Simtime::GetCurrentDate() +{ + return currentdate; +} + +//------------------------------------------------------------------------------ +// Return the next date +//------------------------------------------------------------------------------ +double Simtime::GetNextDate() +{ + return nextdate; +} + +//------------------------------------------------------------------------------ +// Print +//------------------------------------------------------------------------------ +void Simtime::Print(ofstream &fout) +{ + cout << "Previous date = " << previousdate; + cout << "Current date = " << currentdate; + cout << "Next date = " << nextdate; +} diff --git a/src/simul/simtime.h b/src/simul/simtime.h new file mode 100644 index 0000000000000000000000000000000000000000..b5fd0724628059c2ba99655ecd9d4dbff4a35ae2 --- /dev/null +++ b/src/simul/simtime.h @@ -0,0 +1,41 @@ +//====================================================================================// +// // +// Simtime class // +// // +//====================================================================================// +// This File: simtime.h Language: C++ (xlC and CC) // +// Software: SIMULEAU // +//====================================================================================// +// Creation: 11/may/16 by: Leonardo.Brenner@lsis.org // +// Last Change: 11/may/16 by: Leonardo.Brenner@lsis.org // +//====================================================================================// +#ifndef SIMTIME_H +#define SIMTIME_H + +class Simtime +{ + public: + Simtime(); + virtual ~Simtime(); + + void Reset(); // set all dates to zero + void Permute(); // permute previousdate to currentdate and currentdate to nextdate + double StepTime(); // Compute the difference between currentdate and nextdate + + void SetNextDate(double _nd); + double GetPreviousDate(); + double GetCurrentDate(); + double GetNextDate(); + + //print + void Print(ofstream &fout); + + protected: + double currentdate; + double previousdate; + double nextdate; + + private: +}; + +#endif // SIMTIME_H diff --git a/src/simul/simulate.cpp b/src/simul/simulate.cpp new file mode 100644 index 0000000000000000000000000000000000000000..24a8a29e691ecf160464ce160170391e6e94a581 --- /dev/null +++ b/src/simul/simulate.cpp @@ -0,0 +1,352 @@ +//====================================================================================// +// // +// Simulate class // +// // +//====================================================================================// +// This File: simulate.cpp Language: C++ (xlC and CC) // +// Software: SIMULEAU // +//====================================================================================// +// Creation: 11/may/16 by: Leonardo.Brenner@lsis.org // +// Last Change: 11/may/16 by: Leonardo.Brenner@lsis.org // +//====================================================================================// +#include "simuleau.h" + +//------------------------------------------------------------------------------ +// Empty contructor +//------------------------------------------------------------------------------ +Simulate::Simulate() +{ + simulationtime = 0.0; + simulationsteps = 0; + + sbpn = NULL; + sschedule = NULL; + stime = NULL; +} + +//------------------------------------------------------------------------------ +// Its simulate the bpn model with controlled events in schedule for maxtime +//------------------------------------------------------------------------------ +Simulate::Simulate(BPN *_bpn, Schedule *_schedule) +{ + simulationtime = 0.0; + simulationsteps = 0; + + sbpn = new BPN; + sbpn->Copy(_bpn); + + sschedule = new Schedule; + sschedule->Copy(_schedule); + + stime = new Simtime; + stime->Reset(); +} + +//------------------------------------------------------------------------------ +// Destructor +//------------------------------------------------------------------------------ +Simulate::~Simulate() +{ + if (sbpn) + delete sbpn; + if (sschedule) + delete sschedule; + if (stime) + delete stime; +} + + +//------------------------------------------------------------------------------ +// It assigns a file name +//----------------------------------------------------------------------------- +void Simulate::Baptise(simuleau_name file) +{ + strcpy(filename, file); +} + + +//------------------------------------------------------------------------------ +// return the sbpn pointer +//----------------------------------------------------------------------------- +BPN * Simulate::GetBpn() +{ + return sbpn; +} + +//------------------------------------------------------------------------------ +// return the sschedule pointer +//----------------------------------------------------------------------------- +Schedule * Simulate::GetSchedule() +{ + return sschedule; +} + +//------------------------------------------------------------------------------ +// Return true if there are a bpn model in memory +//------------------------------------------------------------------------------ +int Simulate::IsEmpty() +{ + if (sbpn != NULL && sschedule != NULL) + return false; + else + return true; +} + +//------------------------------------------------------------------------------ +// Start the model simulation +//------------------------------------------------------------------------------ +int Simulate::Start(double maxtime, simuleau_options option) +{ + simuleau_name dyn_level_name; + ofstream fout; + Timer T; + + int result = 0; + int conflict = 0; + double precision = PRF::prf.Min_Err(); + double steptime = maxtime; + + strcpy(dyn_level_name, "dyn/"); strcat(dyn_level_name, filename); + Open_File(dyn_level_name, dyn_file, fout); + + //verify conflit + sbpn->ResearchStructuralConflict(); + + if (option == simulate_xct){ // no external events + sschedule->CleanAll(); + } + + // start simulation + simulationtime = maxtime; + simulationsteps = 0; + + WriteInfo(fout); + + stime->Reset(); + T.clear(); + T.start(); + + //sbpn->ComputeSteadyState(); + switch(option){ + case simulate_onoff : + case simulate_mf_onoff : sbpn->ComputeSteadyFiringQuantity(); + break; + } + + + + do{ + stime->Permute(); + WriteDate(fout); + + cout << "================================================\n" ; + cout << "Current date: " << stime->GetCurrentDate() << endl; + cout << "================================================\n" ; + + steptime = stime->StepTime(); // compute the difference betwen current and previous date + switch(option){ + case simulate_onoff : + case simulate_mf_onoff : sbpn->ComputeCurrentFiringQuantity(steptime); // compute current firing quantity from initial marking //currentFiringquantity is not in sbpn. + break; + } + + +/* fout << "================================================\n" ; + fout << "At the end of the step\n" ; + fout << "================================================\n" ; + WriteBPNMarks(fout); +*/ + sbpn->ComputeNewMarks(steptime); + + sschedule->ProcessEvents(sbpn); + + sbpn->DestructBatches(); + + sbpn->MergeBatches(); + + sbpn->DestructBatches(); + + + + fout << "================================================\n" ; + fout << "At the begin of the step\n" ; + fout << "================================================\n" ; + + + WriteBPNMarks(fout); +// sbpn->Print(ofstream &fout); + + sbpn->ComputeTransitionsStates(); + + switch(option){ + case simulate : + case simulate_xct : sbpn->ComputeIFF(); + break; + case simulate_onoff : sbpn->ComputeCFF(); // on/off control method + break; + case simulate_mf_onoff : sbpn->ComputeMCFF(); // on/off control method + break; + } + + + WriteBPNFlows(fout); + if (sbpn->IsSteadyStateReached() && (sbpn->NumberOfDiscretePlaces()==0)){ + result = 5; + cout << " Steady state reached\n" + << " stopping simulation at " << stime->GetCurrentDate() << endl; + break; + } + + sschedule->ProcessBreakpoints(sbpn); + + // Create Batches + sbpn->CreateBatches(); + + sbpn->ComputeBatchesBehaviours(); + + conflict = sbpn->VerifyConflict(); + if (conflict){ + result = conflict + 2; + cout << " conflict found\n" + << " stopping simulation at " << stime->GetCurrentDate() << endl; + break; + } + + + sbpn->ReserveMarks(); + + sschedule->ComputeNextDate(sbpn, simulationtime); + WriteEvents(fout); + + stime->SetNextDate(sschedule->ComputeNextEvent(simulationtime)); + WriteNextEvents(fout); + + simulationsteps++; + if (sschedule->IsEmpty()){ + result = 2; + } + if (stime->GetNextDate() > simulationtime){ + result = 1; + } + + + sbpn->SetBehaviourFunctions(); + cout << endl << endl; + + + } while ((result == 0) && ( conflict == 0)); + T.stop(); + + WriteEnd(fout, result); + Close_File(dyn_level_name, dyn_file, fout); + + cout << "\nFinal simulation time: " << stime->GetCurrentDate() << endl; + cout << "Number of simulation steps: " << simulationsteps; + Notify_Time_Spend(T, "simulation of a BPN model"); + +} + +//------------------------------------------------------------------------------ +// Print +//------------------------------------------------------------------------------ +void Simulate::Print(ostream &fout) +{ + if (stime != NULL){ + fout << "Simulated time: " << stime->GetCurrentDate() << endl; + fout << "Simulated step: " << simulationsteps << endl << endl; + } + + sbpn->Print(fout); + sschedule->Print(fout); +} + +//------------------------------------------------------------------------------ +// It writes model and simulation informations +//------------------------------------------------------------------------------ +void Simulate::WriteInfo(ofstream &fout) +{ + fout << "Model name: " << sbpn->GetName() << endl; + fout << "Simulation time: " << simulationtime << endl; + fout << "Precision: " << PRF::prf.Min_Err() << endl << endl; + + fout << "Number of places: " << sbpn->NumberOfPlaces() << endl; // specify discr, ..... + fout << "Number of transitions: " << sbpn->NumberOfTransitions() << endl; +} + +//------------------------------------------------------------------------------ +// It writes current date +//------------------------------------------------------------------------------ +void Simulate::WriteDate(ofstream &fout) +{ + fout << "==================================================="<< endl; + fout << "Current date : " << stime->GetCurrentDate() << endl; + fout << "==================================================="<< endl << endl; +} + +//------------------------------------------------------------------------------ +// It writes current BPN marks +//------------------------------------------------------------------------------ +void Simulate::WriteBPNMarks(ofstream &fout) +{ + sbpn->WritePlaces(fout); +} + + +//------------------------------------------------------------------------------ +// It writes continuous and batch transition flows +//------------------------------------------------------------------------------ +void Simulate::WriteBPNFlows(ofstream &fout) +{ + sbpn->WriteFlows(fout); +} + +//------------------------------------------------------------------------------ +// It writes the events list +//------------------------------------------------------------------------------ +void Simulate::WriteEvents(ofstream &fout) +{ + fout << endl << "Events" << endl; + sschedule->WriteEvents(fout); + fout << endl; + + sschedule->WriteCE(fout); + + sschedule->WriteBP(fout); + + + +} + +//------------------------------------------------------------------------------ +// It writes the next events to be proceed +//------------------------------------------------------------------------------ +void Simulate::WriteNextEvents(ofstream &fout) +{ + fout << "Next events to proceed" << endl; + + sschedule->WriteNextEvents(fout); + fout << endl; +} + +//------------------------------------------------------------------------------ +// It writes simulation steps, time, .. +//------------------------------------------------------------------------------ +void Simulate::WriteEnd(ofstream &fout, int code) +{ + fout << endl; + fout << "Final simulation time: " << stime->GetCurrentDate() << endl; + fout << "Number of simulation steps: " << simulationsteps << endl; + + switch (code){ + case 1 : fout << "Maximal simulation time reached" << endl; + break; + case 2 : fout << "No more events in the schedule" << endl; + break; + case 3 : fout << "Conflit in discrete place - Simulation was stopped" << endl; + break; + case 4 : fout << "Conflit in continuous place - Simulation was stopped" << endl; + break; + case 5 : fout << "Steady state was reached" << endl; + break; + } +} diff --git a/src/simul/simulate.h b/src/simul/simulate.h new file mode 100644 index 0000000000000000000000000000000000000000..fd6fd64e63f7d0b09caf68b257dc9c2d9bb15c18 --- /dev/null +++ b/src/simul/simulate.h @@ -0,0 +1,65 @@ +//====================================================================================// +// // +// Simulate class // +// // +//====================================================================================// +// This File: simulate.h Language: C++ (xlC and CC) // +// Software: SIMULEAU // +//====================================================================================// +// Creation: 11/may/16 by: Leonardo.Brenner@lsis.org // +// Last Change: 11/may/16 by: Leonardo.Brenner@lsis.org // +//====================================================================================// +#ifndef SIMULATE_H +#define SIMULATE_H +#include "interf.h" + +class Simulate +{ + public: + Simulate(); + Simulate(BPN *_bpn, Schedule *_schedule); + virtual ~Simulate(); + + void Baptise(simuleau_name file); + + BPN * GetBpn(); + Schedule * GetSchedule(); + + int IsEmpty(); + + int Start(double maxtime, simuleau_options option); + + void Print(ostream &fout); + void PrintBPN(); + void PrintSchecule(); + + + //friend class Schedule; + //friend class BPN; + //friend class ::Node; + +// friend double Schedule::ComputeNextEventDate(list<Event> *evl, double nextdate, ev_type type); + + BPN *sbpn; + Schedule *sschedule; + Simtime *stime; + + protected: + double simulationtime; + int simulationsteps; + + simuleau_name filename; //output file name + + void WriteInfo(ofstream &fout); // write model and simulation informations + void WriteDate(ofstream &fout); // write current date + void WriteBPNMarks(ofstream &fout); // write current BPN marks + void WriteBPNFlows(ofstream &fout); // write continuous and batch transition flows + void WriteEvents(ofstream &fout); // write the events list + void WriteNextEvents(ofstream &fout); // write the next events to be proceed + void WriteEnd(ofstream &fout, int code); // write simulation step, time, ... + + + private: +}; + +#endif // SIMULATE_H diff --git a/src/simuleau.cpp b/src/simuleau.cpp new file mode 100644 index 0000000000000000000000000000000000000000..f587bc3dbfdbb325c42de2403e67124d443fb1b8 --- /dev/null +++ b/src/simuleau.cpp @@ -0,0 +1,180 @@ +//====================================================================================// +// // +// SIMULEAU Main // +// // +//====================================================================================// +// This File: simuleau.cpp Language: C++ (xlC and CC) // +// Software: SIMULEAU // +//====================================================================================// +// Creation: 12/apr/16 by: Leonardo.Brenner@lsis.org // +// Last Change: 12/apr/16 by: Leonardo.Brenner@lsis.org // +//====================================================================================// +#include "simuleau.h" + + +//====================================================================================// +// Global Variables // +//====================================================================================// + BPN *bpn = NULL; + Schedule *schedule = NULL; + Simulate *simulation = NULL; + PRF prf; + + + +//====================================================================================// +// BPN compilation function prototype - glc.y // +//====================================================================================// +void Compile_Network(const simuleau_name simuleau_level_name, const simuleau_name str_level_name); + +//====================================================================================// +void Compile_BPN() // Main compile peration // +//====================================================================================// +{ // BPN model name in all directories handled by SIMULEAU + simuleau_name model_name; // current directory (just the name, no paths, no extensions) + simuleau_name bpn_level_name; // directory where the textual network is (./*.bpn) + simuleau_name str_level_name; // directory to store the internal structure(./str/*.str) + + Timer T; // timer to inform total time spent + + cout << "\nCompilation of a BPN model"; + T.clear(); + Ask_an_Existing_File_Name(bpn_level_name, bpn_file); + Get_Only_the_File_Name(bpn_level_name, model_name); + strcpy(str_level_name, "str/"); strcat(str_level_name, model_name); + if (Permission_to_Proceed(str_level_name, str_file)) { // .bpn compilation + T.start(); + cout << "Compile_Network\n"; + Compile_Network(bpn_level_name, str_level_name); +// simulation = new Simulate(bpn, schedule); // prepare to simulation + T.stop(); + Notify_Time_Spend(T, "compilation of a BPN model"); + } +} + +//====================================================================================// +bool Start_Up_BPN() // Main simulation operation // +//====================================================================================// +{ + bool answer = false; + simuleau_name name; + simuleau_name bpn_level_name; // directory where the textual network is (./*.bpn) + simuleau_name dyn_level_name; // directory to store the simulation results(./dyn/*.dyn) + + if (bpn == NULL){ + cout << "There is no Batch Petri Net model (bpn) in memory.\n"; + cout << "You must compile a bpn using the option 1 in main menu.\n"; + return(false); + } + + simulation = new Simulate(bpn, schedule); // prepare to simulation + cout << "\nSimulation of the model '" << bpn->GetName() << "' (" + << bpn->NumberOfPlaces() << " places - " << bpn->NumberOfTransitions() << " transitions)\n"; + Ask_a_File_Name(bpn_level_name, dyn_file); + Get_Only_the_File_Name(bpn_level_name, name); + strcpy(dyn_level_name, "dyn/"); strcat(dyn_level_name, name); + + if (Permission_to_Proceed(dyn_level_name, dyn_file)) { + simulation->Baptise(name); + PRF::prf.Max_Time(Ask_a_Simulation_Time()); + answer = true; + } + + return(answer); +} + +//====================================================================================// +bool Start_Up_BPN_SteadyState() // Compute Steady state operation // +//====================================================================================// +{ + bool answer = false; + simuleau_name name; + simuleau_name bpn_level_name; // directory where the textual network is (./*.bpn) + simuleau_name dyn_level_name; // directory to store the simulation results(./dyn/*.dyn) + + if (bpn == NULL){ + cout << "There is no Batch Petri Net model (bpn) in memory.\n"; + cout << "You must compile a bpn using the option 1 in main menu.\n"; + return(false); + } + + cout << "\nComputation of the steady state for the model '" << bpn->GetName() << "' (" + << bpn->NumberOfPlaces() << " places - " << bpn->NumberOfTransitions() << " transitions)\n"; + + if (Ask_an_Answer("This procedure will modify the steady state. Procede anyway (y/n)?")) { + answer = true; + } + + return(answer); +} + +//====================================================================================// +// SIMULEAU Main // +//====================================================================================// +int main() +{ + bool cont = true; + simuleau_name name; + + //cout.setf(ios::fixed); + //cout.precision(16); + //set_new_handler(Communicate_Out_of_Memory); + Create_Temporary_Directories(); + do { + switch (Welcome_Get_Simuleau_Option()) { +//====================================================================================// +// Compiling Operations // +//====================================================================================// + case compile : Compile_BPN(); break; +//====================================================================================// +// Simulation Operations // +//====================================================================================// + case simulate_xct : if(Start_Up_BPN()){ + simulation->Start(PRF::prf.Max_Time(), simulate_xct); + } + break; + case simulate : if(Start_Up_BPN()){ + simulation->Start(PRF::prf.Max_Time(), simulate); + } + break; + case simulate_onoff : if(Start_Up_BPN()){ + simulation->Start(PRF::prf.Max_Time(), simulate_onoff); + } + break; + case compute_steadystate : if(Start_Up_BPN_SteadyState()){ + bpn->ComputeSteadyState(); + } + + break; + case compute_periodicsteadystate : if(Start_Up_BPN_SteadyState()){ + bpn->ComputePeriodicSteadyState(); + } + + break; + case simulate_mf_onoff : if(Start_Up_BPN()){ + simulation->Start(PRF::prf.Max_Time(), simulate_mf_onoff); + } + break; + +//====================================================================================// +// Inspect Operations // +//====================================================================================// + case see_bpn : See_BPN(); break; + case see_place : See_place(); break; + case see_trans : See_trans(); break; + case see_events : See_events(); break; + + + +//====================================================================================// +// Other Operations // +//====================================================================================// + case credits : Show_Credits(); break; + case goodbye : cont = false; break; + default : Programming_Error("invalid SIMULEAU option", 0000) + } + } while (cont); + Say_Goodbye(); + return(EXIT_SUCCESS); +} + diff --git a/src/simuleau.h b/src/simuleau.h new file mode 100644 index 0000000000000000000000000000000000000000..193630b87fa7e1c7e2165786c04d1292b31a5cc4 --- /dev/null +++ b/src/simuleau.h @@ -0,0 +1,259 @@ +//====================================================================================// +// // +// SIMULEAU Global Declarations // +// // +//====================================================================================// +// This File: simuleau.h Language: C++ (xlC and CC) // +// Software: SIMULEAU // +//====================================================================================// +// Creation: 12/apr/16 by: Leonardo.Brenner@lsis.org // +// Last Change: 28/apr/16 by: Leonardo.Brenner@lsis.org // +//====================================================================================// +#ifndef SIMULEAU_H +#define SIMULEAU_H + +#include <fstream> // file streams (i/o) +#include <iostream> // std i/o with streams (cin, cout, cerr) +#include <iomanip> // i/o manipulators (setiosflags-scientific) +#include <string.h> // string manipulation (strcpy, strcat) +#include <math.h> // absolute values (abs), square roots (sqrt) +#include <cmath> // std::abs +#include <limits.h> // maximum and minimum values to int, float, etc +#include <new> // handler for new commands (test for allocation) +#include <stdio.h> // i/o standard of C language (used for the parser) +#include <stdlib.h> // standard library of C language +#include <unistd.h> // +#include <sys/stat.h> // system file manipulation functions +#include <sys/types.h> // +#include <list> // list manipulation +#include <stack> // stack manipulation +#include <glpk.h> // linear program solver + + + +using namespace std; + +//====================================================================================// +// Release Date ******************** CHANGE THIS DATE FOR NEW RELEASES OF SIMULEAU // +//====================================================================================// + +#define __RELEASE_DATE__ "Apr 30 2016" + + +//====================================================================================// +// BPN classes // +//====================================================================================// +class BPN; // Main BPN class (main structure) 1100 +class Node; // Node class (node main structure) 1200 +class Place; // Place class (place main structure) 1300 +class DiscretePlace; // DiscretePlace class (discrete place structure) 1300 +class ContinuousPlace; // ContinuousPlace class (continuous place structure)1300 +class BatchPlace; // BatchPlace class (batch place structure) 1300 +class TriangularBatchPlace; // TriangularBatchPlace class + // (traingular batch place structure) 1300 + +class Transition; // Transition class (transition main structure) 1400 +class DiscreteTransition; // DiscreteTransition class + // (discrete transition structure) 1400 +class ContinuousTransition; // ContinuousTransition class + // (continuous transition structure) 1400 +class BatchTransition; // BatchTransition clas (batch transition structure) 1400 +class Arc; // Arc class (arc main structure) 1500 +class Batch; // Batch class (batch main structure) 1600 +class ControllableBatch; // ControllableBatch class + // (controllable batch structure) 1600 +class Flow; // Flow class (flow main structure) 1700 + +class Event; // Event class (event main structure) 1800 +class ControlledEvent; // ControlledEvent class(Controlled event structure) 1800 +class Breakpoint; // Breakpoint class (Breakpoint structure) 1850 +class Schedule; // Schedule class (Schedule main structure) 1900 +class Simtime; // Simtime class (simtime structure) 2000 +class Simulate; // Simulate class (simulate structure) 2100 + + + +//====================================================================================// +// User Interface // +//====================================================================================// +class PRF; // User Preferences (main structure) 6100 + +//====================================================================================// +// Miscelaneous // +//====================================================================================// +class Timer; // general chronometers from pac++ + +//====================================================================================// +// Types of Files Handled by Simuleau // +//====================================================================================// + +enum file_types // all files handled by Simuleau + { bpn_file , // textual description of BPN + str_file , // internal representation of BPN STRucture + xct_file , // textual description of eXTernal Controlled events + dyn_file , // messages of DYNamics of BPN + tim_file , // messages of TIMes spend in Simuleau software + dbg_file , // textual output (Readable) with DeBuGging information + prf_file , // user PReFerences for parameters (numerical precision, etc) + dot_file , // names without extension + err_file }; // unrecognized extension + +//====================================================================================// +// Basic Definitions // +//====================================================================================// +const int no = 0; // used in formalisation variable +const int yes = 1; // used in formalisation variable +const double zero = 0.0; // double sized constants to avoid +const double one = 1.0; // problems passing parameters +const double two = 2.0; +const double epsilon = 1e-5; // a small double valeu +const double close_to_zero = 1e-16; // a very small double valeu +const double round_zero = 1e-12; // a rather small double valeu +const double visual_zero = 1e-5; // smallest value displayed as decimal +const int simuleau_precision = 10; // precision to handle (i/o) double values +const int max_integer = INT_MAX; // maximum integer (signed) +const int min_integer = INT_MIN; // minimum integer (signed) +const double max_float = 1e+50; // max. float (actually just a huge one) +const double min_float = -1e+50; // min. float (actually just a tiny one) +#ifdef _CC_COMPILER_ + typedef int bool; // boolean variables + const bool true = 1; // gcc and other non-standart c++ + const bool false = 0; // compilers have built-in bool types +#endif +const int mem_unit = 1024; // unit of memory space (Kbytes) + +//====================================================================================// +// Simuleau Name Definitions // +//====================================================================================// + +const int max_simuleau_name = 128; // Maximum size (actually the last 4 are ".ext") + +typedef char simuleau_name[max_simuleau_name]; + // User Definided Names for any Simuleau Entity + +//====================================================================================// +// Identifiers Definitions // +//====================================================================================// +typedef int any_id; // for identifiers of any kind +const any_id no_id = -1; + +typedef int node_id; // for node (anykind) +const node_id no_node = -1; +const node_id fst_node = 0; + +typedef int place_id; // for place (anykind) +const place_id no_place = -1; +const place_id fst_place = 0; + +typedef int trans_id; // for transtion (anykind) +const trans_id no_trans = -1; +const trans_id fst_trans = 0; + +typedef int batch_id; // for batch in a place +const batch_id no_batch = -1; +const batch_id fst_batch = 0; + +typedef int ev_id; // for events +const ev_id no_ev = -1; +const ev_id fst_ev = 0; + +typedef int m_coord; // for pre/post matrices coordinates +const m_coord no_coord = -1; +const m_coord fst_m_coord = 0; // the first coordinate (in matrices) + +typedef double pl_cont_fed; +const pl_cont_fed Not_fed = 0.0; +const pl_cont_fed Fed = 0.5; // The place has an input flow + + +//====================================================================================// +// Pre-defined Enumerations // +//====================================================================================// +enum node_type { Place_nd , Transition_nd }; // Place or Transition node +enum place_type { Discrete_pl , Continuous_pl , Batch_pl, Triangular_pl }; + // Discrete, Continuous, Batch and Triangular Batch places +enum trans_type { Discrete_tr , Continuous_tr , Batch_tr }; + // Discrete, Continuous and Batch transitions +enum batch_type { Batch_bt , Controllable_bt }; // Batches types +enum node_state { No_state }; // No state, ... +enum Batch_place_behaviour { Accumulating_behaviour=2 }; // No behaviour, ... +enum ctrl_batch_state{ No_st , Free_st , Congested_st }; + // States of a Controllable batch +enum ctrl_batch_behaviour { No_behaviour , + Free_behaviour , + Congesting_behaviour , + Uncongesting_behaviour }; + // Behaviours of a controllable batch + +enum ev_class { Internal_ev, External_ev, Controlled_ev }; + // Internal, External and Controlled event classification +enum ev_type { No_event, // No event + Discr_trans_fires, // Discrete transition is fired + Cont_place_empty, // Continuous place becomes empty + Discr_trans_enabled, // Discrete transition becomes enable + Becomes_output_batch,// A batch becomes an output batch + Destr_output_batch, // Destruction of an output batch + Batch_becomes_dense, // Full accumulation/congestion of a batch + Two_batches_meet, // Two batches meet + Batch_meets_output_batch, // A batch meet an output batch + Output_batch_decongestion, // Decongestion of the output batch + Batch_decongestion, // Decongestion of a batch in contact head + Batch_becomes_free, // Full decongestion of an alone batch + Place_steady_quan, // Place reaches Steady marking Quantity + Remaining_becomes_freesteadyquan, //Remaining quantity becomes free steady quantity + + + Trans_flow_ce, // A controled event changes the maximum + // flow of a transition + Place_speed_ce // A controlled event changes the maximum + // speed of a batch place + }; +enum ce_type { Flow_ce, Speed_ce }; // Flow and Speed controlled events + +enum breakpoint_type { at_bp, every_bp }; // Flow and Speed controlled events + + +//====================================================================================// +// User Preferences Defaults // +//====================================================================================// + +const int def_verbose = 1; // Verbose mode +const double def_time = 1.0 ; // Maximum simulation time +const double def_err = 1e-5; // Minimum error +const double def_thresh = close_to_zero; // Threshold +const simuleau_name def_length_unity = "km"; // Length unity +const simuleau_name def_time_unity = "h"; // Time unity + +//====================================================================================// +// Includes Simuleau Classes Error Codes // +//====================================================================================// +#include "bpn/bpn.h" // main BPN class (class BPN ) 1100 +#include "bpn/node.h" // node class (class Node ) 1200 +#include "bpn/place.h" // place classes (class Place, DiscretePlace, + // ContinuousPlace, BatchPlace, + // TriangularBatchPlace ) 1300 +#include "bpn/transition.h" // transition classes (class Transition, + // DiscreteTransition, + // ContinuousTransition, + // BatchTransition ) 1400 +#include "bpn/arc.h" // arc class (class Arc ) 1500 +#include "bpn/batch.h" // batch classes (class Batch, TriangularBatch) 1600 +#include "bpn/flow.h" // flow class (class Flow ) 1700 +#include "bpn/firingquantity.h" // firingquantity class + +#include "simul/event.h" // event classes (class Event, ExternalEvent ) 1800 +#include "simul/breakpoint.h" // event classes (class Event, ExternalEvent ) 1850 +#include "simul/schedule.h" // schedule class (class Schedule ) 1900 +#include "simul/simtime.h" // simtime class (class Simtime ) 2000 +#include "simul/simulate.h" // simulate class (class Simulate ) 2100 + + +//====================================================================================// +// Includes Simuleau Packages Error Codes // +//====================================================================================// +#include "interf/interf.h" // user interface package for UNIX version 6200 +#include "interf/prf.h" // user preferences (class PRF) 6100 +#include "interf/timer.h" // timer definitions package (timer.C from pac++) + + +#endif // SIMULEAU_H