topics:  main-page   everything   99things   things-to-do   software   space   future   exercise & health   faith  
  thought   web   movies+TV   music   mymusic   food   curiosity   tidbits   I remember   wishlist   misc   links


This section lists all blog posts, regardless of topic.

Exercise 16: Implement SolveCondition
September 12, 2008

Summary

Inputs:

A rule condition with 1 or more variable tokens.
A hash which defines the values of zero or more variables.
The current token position.

Outputs:

A list of hashes. Each hash represents a set of variable values that satisfies the condition.

Algorithm:

Tokens are processed from left to right.
Non-variable tokens are skipped over.
Each variable which is found to exist in the variable hash should have its value substituted.
Each unknown variable token needs to be solved. This list of possible entities is used to permute the variable hash into N new hashes. For each hash, the function recurses.
This subroutine should not be called for relationships with two variables.
The output of a recurse is a list of hashes. Each of these hashes represents part of the final output of the function.



Exercise 15: Implement SolveAssignmentVariable and SolveRelationshipVariable
September 12, 2008

SolveAssignmentVariable Summary

If the variable is within the path, use SolvePathVariable. Once solved, if the path is free of variables and the value is known, ensure the value matches.

If the variable is the value of the assignment, then simply look it up.

SolveRelationshipVariable Summary

If there is only one variable, then use the appropriate entity's relation index to return all possibilities.

If there are two variables, then this subroutine should not have been called.

Input:

An assignment and a position within that assignment.

Output:

A list of entities.


Exercise 14: Implement SolvePathVariable
September 11, 2008

Summary

Inputs:

A parent entity, which might be null.
A parent relation type which describes the mandatory relationship between the parent entity and the variable entity that is being solved for.
A child entity, which might be null.
A child relation type which describes the mandatory relationship between the the variable entity that is being solved for and the child entity.

Outputs:

All entities that satisfy the conditions.

To accomplish this, new indices and their respective look up functions will need to be added to the Entity and Brain classes:

New index:

Given an entity Y and relation type R, what entities X satisfy the relationship X R Y?

New lookup functions:

1.GetInverseHasList: Given an entity X, which entities have a has_a relationship with X?

2.GetInverseIsAList: Given an entity X, which entities have a is_a relationship with X? (Actually, it appears that this one might not be needed)

older >>