idp_engine.Problem

Class to represent a collection of theory and structure blocks.

class idp_engine.Problem.Problem(*blocks)[source]

A collection of theory and structure blocks.

declarations

the list of type and symbol declarations

Type

dict[str, Type]

constraints

a set of assertions.

Type

OrderedSet

assignments

the set of assignments. The assignments are updated by the different steps of the problem resolution.

Type

Assignment

clark

A mapping of defined symbol to the rule that defines it.

Type

dict[(SymbolDeclaration, Definition), Rule]

def_constraints

A mapping of defined symbol to the whole-domain constraint equivalent to its definition.

Type

dict[SymbolDeclaration], Expression

interpretations

A mapping of enumerated symbols to their interpretation.

Type

dict[string, SymbolInterpretation]

goals

A set of goal symbols

Type

dict[string, SymbolDeclaration]

_formula

the logic formula that represents the problem.

Type

Expression, optional

questions

the set of questions in the problem. Questions include predicates and functions applied to arguments, comparisons, and variable-free quantified expressions.

Type

OrderedSet

co_constraints

the set of co_constraints in the problem.

Type

OrderedSet

classmethod make(theories, structures)[source]

polymorphic creation

assert_(code: str, value: Any, status: idp_engine.Assignments.Status = <Status.GIVEN: 2>)[source]

asserts that an expression has a value

Parameters
  • code (str) – the code of the expression, e.g., “p()”

  • value (Any) – a Python value, e.g., “True”

  • status (Status, Optional) – how the value was obtained. Default: Status.GIVEN

formula()[source]

the formula encoding the knowledge base

expand(max=10, complete=False, extended=False)[source]

output: a list of Assignments, ending with a string

symbolic_propagate(tag=<Status.UNIVERSAL: 4>)[source]

determine the immediate consequences of the constraints

propagate(tag=<Status.CONSEQUENCE: 6>, extended=False)[source]

determine all the consequences of the constraints

explain(consequence)[source]

returns the facts and laws that justify ‘consequence in the ‘self Problem

Parameters
  • self (Problem) – the problem state

  • consequence (string) – the code of the sentence to be explained. Must be a key in self.assignments

Returns

list of facts and laws that explain the consequence

Return type

(facts, laws) (List[Assignment], List[Expression])]

simplify()[source]

simplify constraints using known assignments

decision_table(goal_string='', timeout=20, max_rows=50, first_hit=True, verify=False)[source]

returns a decision table for goal_string, given self.

Parameters
  • goal_string (str, optional) – the last column of the table.

  • timeout (int, optional) – maximum duration in seconds. Defaults to 20.

  • max_rows (int, optional) – maximum number of rows. Defaults to 50.

  • first_hit (bool, optional) – requested hit-policy. Defaults to True.

  • verify (bool, optional) – request verification of table completeness. Defaults to False

Returns

the non-empty cells of the decision table

Return type

list(list(Assignment))