I'm using the clips framework to build an expert system. However I'm having trouble with memory usage atm, which would make it unsuitable for my task. So here is the problem:
It generates 144 of the SpinWave facts as its supposed to, with a total of around 150 facts. Each fact should not hold more than a bunch of integers (roughly 15). CLIPS consumes 1GB of memory with roughly 6mio memory requests made. I'm kind of baffled why it allocates that much memory... Can someone point me into the right direction or give an explanation. The code I'm using is below. Thanks in advance!
Steve
; define helicity wave final or initial state template
(deftemplate SpinWaveMultiplet
(slot unique_id (type INTEGER))
(slot charge (type INTEGER))
(slot isospin_num (type INTEGER))
(slot isospin_denom (type INTEGER))
(slot isospin_z_num (type INTEGER))
(slot spin_num (type INTEGER))
(slot spin_denom (type INTEGER))
; we have multislot of spin z to allow for specific components
; in the initial or final state
(multislot spin_z_num)
(slot parity (type INTEGER))
(slot cparity (type INTEGER))
)
; define spin wave
(deftemplate SpinWave
(slot unique_id (type INTEGER))
(slot charge (type INTEGER))
(slot isospin_num (type INTEGER))
(slot isospin_denom (type INTEGER))
(slot isospin_z_num (type INTEGER))
(slot spin_num (type INTEGER))
(slot spin_denom (type INTEGER))
(slot spin_z_num (type INTEGER))
(slot parity (type INTEGER))
(slot cparity (type INTEGER))
)
; allowed intermediate state spins
(deffacts user-conditions
(AllowedQN
(spin_nums 0 1 2) (spin_denom 1 ) (isospin_nums 0 1) (isospin_denom 1)
(charge 0) (parity -1 1) (cparity -1 1)
)
)
(deffacts initial-state
(SpinWaveMultiplet (unique_id 0) (spin_num 1) (spin_denom 1) (spin_z_num -1 1)
(isospin_num 0) (isospin_denom 1) (isospin_z_num 0)
)
)
(deffacts final-state-list
(SpinWaveMultiplet (unique_id 1) (spin_num 1) (spin_denom 1) (spin_z_num -1 1)
(isospin_num 0) (isospin_denom 1) (isospin_z_num 0)
)
(SpinWaveMultiplet (unique_id 2) (spin_num 0) (spin_denom 1) (spin_z_num 0)
(isospin_num 1) (isospin_denom 1) (isospin_z_num 0)
)
(SpinWaveMultiplet (unique_id 3) (spin_num 0) (spin_denom 1) (spin_z_num 0)
(isospin_num 1) (isospin_denom 1) (isospin_z_num 0)
)
)
; create all spin waves
(defrule create-initial-spin-waves
(AllowedQN
(spin_nums $?spin_nums) (spin_denom ?spin_denom)
(isospin_nums $?isospin_nums) (isospin_denom ?isospin_denom)
(charge $?charges)
(parity $?parities)
(cparity $?cparities)
)
=>
(foreach ?charge ?charges
(foreach ?parity ?parities
(foreach ?cparity ?cparities
(foreach ?isospin_num ?isospin_nums
(bind ?isospin_z_num (* -1 ?isospin_num))
(while (<= ?isospin_z_num ?isospin_num)
(foreach ?spin_num ?spin_nums
(bind ?spin_z_num (* -1 ?spin_num))
(while (<= ?spin_z_num ?spin_num)
(assert
(SpinWave (unique_id ?*total_unique_id_counter*)
(spin_num ?spin_num) (spin_denom ?spin_denom) (spin_z_num ?spin_z_num)
(isospin_num ?isospin_num) (isospin_denom ?isospin_denom) (isospin_z_num ?isospin_z_num)
(charge ?charge) (parity ?parity) (cparity ?cparity)
)
)
(bind ?*total_unique_id_counter* (+ ?*total_unique_id_counter* 1))
(bind ?spin_z_num (+ ?spin_z_num ?spin_denom))
)
)
(bind ?isospin_z_num (+ ?isospin_z_num ?isospin_denom))
)
)
)
)
)
)