/* @author: MB @version: OCT 2026 Programm illustrates situated information flow: extracting information by using constraints and information present in a situation */ #include #include // Simplified infon, represented by a sentence struct Infon{ char content[40]; int truthValue; // 1 for true, 0 for false }; // Situation Type with a single conditioning infon struct SituationType{ struct Infon condition; }; // Constraint with antecedent and consequent situation types, given a condition struct Constraint{ struct SituationType antecedent; struct SituationType consequent; char condition[40]; }; // Situation with given information and operative constraints struct Situation{ struct Infon givenInformation[10]; struct Constraint operativeConstraints[10]; }; int main(void){ // Initializing a situation s1 struct Infon i1 = {"smoky", 1}; struct Infon i2 = {"fire", 1}; struct Infon i3 = {"alarm", 1}; struct Infon i4 = {"bell rings", 1}; struct Infon i5 = {"person at the door", 1}; struct Infon i6 = {"person is a firefighter", 1}; struct Infon i7 = {"person is a burglar", 0}; struct Infon i8 = {"person at the door", 0}; struct Infon i9 = {"alarm and bell rings", 1}; struct SituationType ST1 = {i1}; struct SituationType ST2 = {i2}; struct SituationType ST3 = {i3}; struct SituationType ST4 = {i4}; struct SituationType ST5 = {i5}; struct SituationType ST6 = {i6}; struct SituationType ST7 = {i7}; struct SituationType ST8 = {i8}; struct SituationType ST9 = {i9}; struct Constraint c1 = {ST1, ST2, "s2 < s1"}; // smoke means fire struct Constraint c2 = {ST1, ST3, "s1 = s1"}; // smoke triggers alarm struct Constraint c3 = {ST4, ST5, "s5 < s1"}; // bell rings, so person at the door before struct Constraint c4 = {ST9, ST6, "s1 = s1"}; // bell rings & alarm, so person is a firefighter struct Constraint c6 = {ST6, ST7, "s1 = s1"}; // a firefighter is not a burglar struct Situation s1 = {.givenInformation = {i4, i1, i9}, .operativeConstraints = {c1, c2, c3, c4, c6}}; printf("Given information in the situation s1: \n"); int amountOfInformation = sizeof(s1.givenInformation) / sizeof(s1.givenInformation[0]); int infons = 0; int amountOfConstraints = sizeof(s1.operativeConstraints) / sizeof(s1.operativeConstraints[0]); int constraints = 0; for (int i = 0; i < amountOfInformation; i++){ struct Infon currentInfon = s1.givenInformation[i]; if (strcmp(currentInfon.content,"") == 0) continue; char content[] = ""; if (currentInfon.truthValue) { strcat(strcat(content, currentInfon.content), " is true"); } else { strcat(strcat(content, currentInfon.content), " is false"); } printf("Infon %d: %s \n", infons, content); infons++; } printf("Information of s1 consists in %d infons \n \n", infons); printf("Operative constraints in the situation s1: \n"); for (int i = 0; i < amountOfConstraints; i++){ if (strcmp(s1.operativeConstraints[i].antecedent.condition.content, "") == 0) continue; struct Constraint currentConstraint = s1.operativeConstraints[i]; printf("Contraint %d: If %s %s, then %s %s under the condition %s \n", constraints, currentConstraint.antecedent.condition.content, ((currentConstraint.antecedent.condition.truthValue)? " is true" : " is false "), currentConstraint.consequent.condition.content, ((currentConstraint.consequent.condition.truthValue)? " is true" : " is false "), currentConstraint.condition); constraints++; } printf("In s1 %d constraints are operative \n \n", constraints); // Extracting information from the situation s1 struct Constraint currentConstraint = s1.operativeConstraints[0]; struct Infon antecedentInfon = currentConstraint.antecedent.condition; struct Infon givenInfon = {"being in s1", 1}; printf("Extracting information from the situation s1: \n"); for (int i = 0; i < constraints; i++){ currentConstraint = s1.operativeConstraints[i]; printf("Working with constraint %d \n", i); // Check if the antecedent is satisfied by the given information int antecedentSatisfied = 0; antecedentInfon = currentConstraint.antecedent.condition; printf("Looking for the information: %s \n", antecedentInfon.content); for (int k = 0; k < infons; k++){ givenInfon = s1.givenInformation[k]; printf("Found in the situation: %s \n", givenInfon.content); if ((strcmp(antecedentInfon.content, givenInfon.content) == 0) && (antecedentInfon.truthValue == givenInfon.truthValue)){ antecedentSatisfied = 1; printf("Satisfied antecedent: %s \n", givenInfon.content); break; } } // If the antecedent is satisfied, infer to the consequent, and maybe another situation // Infer another situation related to given situation according to condition of the constraint struct Infon consequentInfon = currentConstraint.consequent.condition; if (antecedentSatisfied && (strcmp(currentConstraint.condition, "s1 = s1") != 0)){ printf("Inferring to new situation: %s %s \n", consequentInfon.content, ((consequentInfon.truthValue)? " is true" : " is false ")); printf("%s \n", currentConstraint.condition); struct Situation newSituation = {.givenInformation = {consequentInfon} }; } // Add extracted information to the given situation if no further situation required else if (antecedentSatisfied && (strcmp(currentConstraint.condition, "s1 = s1") == 0)){ printf("Inferring to a information. \n"); printf("In that situation: %s %s \n", consequentInfon.content, ((consequentInfon.truthValue)? " is true" : " is false ")); for (int k = 0; k < infons; k++){ givenInfon = s1.givenInformation[k]; if (strcmp(consequentInfon.content, givenInfon.content) == 0 && consequentInfon.truthValue == givenInfon.truthValue){ break; } else { s1.givenInformation[infons++] = consequentInfon; } } } } return 0; } /* OUTPUT Given information in the situation s1: Infon 0: bell rings is true Infon 1: smoky is true Infon 2: alarm and bell rings is true Information of s1 consists in 3 infons Operative constraints in the situation s1: Contraint 0: If smoky is true, then fire is true under the condition s2 < s1 Contraint 1: If smoky is true, then alarm is true under the condition s1 = s1 Contraint 2: If bell rings is true, then person at the door is true under the condition s5 < s1 Contraint 3: If alarm and bell rings is true, then person is a firefighter is true under the condition s1 = s1 Contraint 4: If person is a firefighter is true, then person is a burglar is false under the condition s1 = s1 In s1 5 constraints are operative Extracting information from the situation s1: Working with constraint 0 Looking for the information: smoky Found in the situation: bell rings Found in the situation: smoky Satisfied antecedent: smoky Inferring to new situation: fire is true s2 < s1 Working with constraint 1 Looking for the information: smoky Found in the situation: bell rings Found in the situation: smoky Satisfied antecedent: smoky Inferring to a information. In that situation: alarm is true Working with constraint 2 Looking for the information: bell rings Found in the situation: bell rings Satisfied antecedent: bell rings Inferring to new situation: person at the door is true s5 < s1 Working with constraint 3 Looking for the information: alarm and bell rings Found in the situation: bell rings Found in the situation: smoky Found in the situation: alarm and bell rings Satisfied antecedent: alarm and bell rings Inferring to a information. In that situation: person is a firefighter is true Working with constraint 4 Looking for the information: person is a firefighter Found in the situation: bell rings Found in the situation: smoky Found in the situation: alarm and bell rings Found in the situation: alarm Found in the situation: person is a firefighter Satisfied antecedent: person is a firefighter Inferring to a information. In that situation: person is a burglar is false */