0
votes

I'm getting a strange problem with CLIPS that is kind of difficult to debug. I have the following fact list:

f-0     (initial-fact)
f-1     (SpinWave (quantum_number_names "charge" "isospin" "spin" "parity" "cparity") (quantum_number_values 0 1 2 -1 -1))
f-2     (SpinWave (quantum_number_names "charge" "isospin" "spin" "parity" "cparity") (quantum_number_values 0 1 3 -1 -1))
f-3     (SpinWave (quantum_number_names "charge" "isospin" "spin" "parity" "cparity") (quantum_number_values 0 1 4 -1 -1))
f-4     (SpinWave (quantum_number_names "charge" "isospin" "spin" "parity" "cparity") (quantum_number_values 0 3 1 -1 1))
f-5     (ViolatingRulesForDecay (list_of_violated_rules))
f-6     (SpinQuantumNumber (unique_id 1) (numerator 0) (denominator 1) (z_component_numerator 0))
f-7     (SpinQuantumNumber (unique_id 2) (numerator 1) (denominator 1) (z_component_numerator -1))
f-8     (SpinQuantumNumber (unique_id 3) (numerator 1) (denominator 1) (z_component_numerator 0))
f-9     (SpinQuantumNumber (unique_id 4) (numerator 1) (denominator 1) (z_component_numerator 1))
f-10    (SpinQuantumNumber (unique_id 5) (numerator 2) (denominator 1) (z_component_numerator -2))
f-11    (SpinQuantumNumber (unique_id 6) (numerator 2) (denominator 1) (z_component_numerator -1))
f-12    (SpinQuantumNumber (unique_id 7) (numerator 2) (denominator 1) (z_component_numerator 0))
f-13    (SpinQuantumNumber (unique_id 8) (numerator 2) (denominator 1) (z_component_numerator 1))
f-14    (SpinQuantumNumber (unique_id 9) (numerator 2) (denominator 1) (z_component_numerator 2))
f-15    (AllowedQuantumNumbers (name "spin") (values 1 2 3 4 5 6 7 8 9))
f-16    (AllowedQuantumNumbers (name "isospin") (values 1 2 3 4))
f-17    (AllowedQuantumNumbers (name "charge") (values -1 0 1))
f-18    (AllowedQuantumNumbers (name "parity") (values -1 1))
f-19    (AllowedQuantumNumbers (name "cparity") (values -1 1))
For a total of 20 facts.

Im trying to search for one of the facts within c++ and I do it in the following way:

DATA_OBJECT found_spin_quantum_number_facts;
std::stringstream clips_query;
clips_query << "(find-fact ((?f SpinQuantumNumber)) 
(and (= ?f:numerator " << spin_state.J_numerator_ << ") (and (= 
?f:denominator " << spin_state.J_denominator_ << ") (= 
?f:z_component_numerator " << spin_state.J_z_numerator_ << "))))";

std::cout << clips_query.str() << std::endl;
EnvEval(clips_environment_, clips_query.str().c_str(),
  &found_spin_quantum_number_facts);

which works several times until it breaks with the following clips expression (which seems legit to me and works several times until it fails):

(find-fact ((?f SpinQuantumNumber)) (and (= ?f:numerator 0) (and (= ?f:denominator 1) (= ?f:z_component_numerator 0))))

The find-fact function actually finishes executing, however in a function FlushMultifields() clips gets stuck... What am I missing? Thanks in advance!

Steve

1
Ok i turned on debug flags for clips, and it gets stuck in that FlushMultiflields function because a busyCount flag is set to 1, whatever that means. Here is the code segment... while (theSegment != NULL) { nextPtr = theSegment->next; if (theSegment->busyCount == 0) {steve
There's not enough information in your question to diagnose the problem. Your code fragment involves a simple call to EnvEval, there's nothing obviously wrong with it, and it works the first few times you call it. The most likely cause of the problem is outside of the scope of code you've posted (e.g. the problem may be in the code that comes after EnvEval).Gary Riley

1 Answers

0
votes

so I kept debugging it, and as Gary mentioned the problem was somewhere completely else. I was asserting a fact with an address that was already pointing to an existing fact (on the fact stack so to say). Don't know what I was thinking there...

void* ifs_template = EnvFindDeftemplate(clips_environment_,
  "InitialAndFinalState");
void* ifs_fact = EnvCreateFact(clips_environment_, ifs_template);
if (ifs_fact != NULL) {
  DATA_OBJECT field;
  field.type = FACT_ADDRESS;

  OLD-CODE: field.value = EnvAssert(clips_environment_,
    addSpinWaveToClipsEnvironment(initial_state));
  NEW-CODE: field.value = 
    addSpinWaveToClipsEnvironment(initial_state);
  EnvPutFactSlot(clips_environment_, ifs_fact, "initial_state", &field);

The addSpinWaveToClipsEnvironment() function creates a new SpinWave fact, if not existent, and returns the fact address to this fact.