ñòð. 112 |

TMax ï¬‚t : max time allowed for continued run

dT ï¬‚t :delta time

dPdT ï¬‚t :growth rate of population

terminate ï¬‚t; : minimum population growth rate to

continue run

:rule r0

rule (goal Calculate population growth rate dPdT at

time T)

IF (in Population size = <size> AND K = <K> AND r = <r>

AND T = <T> AND dT = <dT> AND dPdT.cf = 0)

THEN

write "Time <T> population <size>\n",

in 1 dPdT = (<r> * <size> * <dT> * (1 - <size> / <K>)),

in 1 T = (<T> + <dT>);

:rule r1

TEAM LinG - Live, Informative, Non-cost and Genuine !

326 APPENDIX

rule (goal Calculate population size at T+dT from size

at T recursively)

IF (in Population size = <size> AND K = <K> AND r = <r>

AND T = <T> AND dT = <dT> AND dPdT = <dPdT>

AND terminate < <dPdT> AND TMax > <T>)

THEN

in 1 size = (<size> + <dPdT> * <dT>),

in 1 dPdT.cf = 0;

:rule r2

rule (goal Terminate run)

IF (in Population (T = <T> AND TMax < <T>) OR (dPdT =

<dPdT> AND terminate > <dPdT>))

THEN

write "Termination criterion met - ending run\n",

exit;

make Population size = 1000 K = 10000 r = 1 T = 0 TMax =

10 dT = 1 terminate = 0.01;

: ******************************************************

:* MC.FPS - missionaries and cannibals

: ******************************************************

: RULES OF GAME:

: -- can never be more cannibals than missionaries in the

boat or on either shore, except

: - - all cannibals and no missionaries is OK.

: i.e. miss >= cannibals, OR

: miss = 0.

: - - must be at least two in boat if L to R, or one if

R to L.

: ------------------------------------------------------

: ALGORITHM - basically a simulation.

:

: DATA ELEMENTS: "boat" holds missionaries, cannibals, total,

: boat state: "L" when docked at left bank, "R" when docked

: at right bank, "LR" when going from left to right, and

: "RL when going from right to left.

:

: "left" holds missionaries, cannibals, total on left bank;

: "right" holds missionaries, cannibals, total on right bank.

:

: "temp" is temporary storage for finding out what bank

totals

: will be after the boat is unloaded, so we can check whether a

TEAM LinG - Live, Informative, Non-cost and Genuine !

327

APPENDIX

: missionary will get eaten if we unload.

:

: "max" holds input data: total number of missionaries and

: cannibals, and max number allowed in the boat.

:

: PROCEDURE: first input data (rule r0), then put all the

: missionaries and cannibals on the left bank, nobody in

: boat, nobody on right bank (rule r1).

:

: Now load as many as possible up to the boat limit on

: the left bank (rules r2, r3, r4). Check to make sure

: that nobody will get eaten on the left bank or in the

: boat (rules r5,r6). If this test is passed, sail from

: left to right; if not, forget it and backtrack (rules

: r7, r8).

:

: After we have sailed from the left bank, see what the

: right bank totals will be if we unload (rule r19). If

: nobody will get eaten, unload (rule r20); if somebody

: will get eaten, forget it and backtrack (rule r21).

: Check if we have solved the problem (rule r22). If not:

:

: Now load as few as possible up to the boat limit on the

: right bank (rules r9, r10, r11). Check to make sure

: that nobody will get eaten on the right bank or in the

: boat (rules r12, r13). If this test is passed, sail

: from right to left; if not, forget it and backtrack

: (rules r14, r15).

:

: After we have sailed from the right bank, see what the

: left bank totals will be if we unload (rule r16). If

: nobody will get eaten, unload (rule r17); if somebody

: will get eaten, forget it and backtrack (rule r18).

: Continue until problem is solved.

: ******************************************************

message â€™loading program MC.FPS...\nâ€™ ;

declare Boat

miss int

cann int

total int

state str;

declare Left

TEAM LinG - Live, Informative, Non-cost and Genuine !

328 APPENDIX

miss int

cann int

total int ;

declare Right

miss int

cann int

total int ;

declare Temp

miss int

cann int

total int ;

declare Max

miss int

cann int

boat int

total int ;

: ++++++++++++++++++++++++++++++++++++++++++++++++++++++

ñòð. 112 |