Soar Kernel  9.3.2 08-06-12
 All Data Structures Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros
Typedefs | Functions
reorder.h File Reference

Go to the source code of this file.

Typedefs

typedef struct action_struct action
typedef struct agent_struct agent
typedef char Bool
typedef struct condition_struct condition
typedef struct cons_struct cons
typedef cons list
typedef uint64_t tc_number

Functions

listcollect_root_variables (agent *thisAgent, condition *, tc_number, Bool)
void init_reorderer (agent *thisAgent)
Bool reorder_action_list (agent *thisAgent, action **action_list, tc_number lhs_tc)
Bool reorder_lhs (agent *thisAgent, condition **lhs_top, condition **lhs_bottom, Bool reorder_nccs)

Typedef Documentation

typedef struct action_struct action

Definition at line 23 of file reorder.h.

typedef struct agent_struct agent

Definition at line 22 of file reorder.h.

typedef char Bool

Definition at line 19 of file reorder.h.

typedef struct condition_struct condition

Definition at line 24 of file reorder.h.

typedef struct cons_struct cons

Definition at line 21 of file reorder.h.

typedef cons list

Definition at line 25 of file reorder.h.

typedef uint64_t tc_number

Definition at line 20 of file reorder.h.

Function Documentation

list* collect_root_variables ( agent thisAgent,
condition ,
tc_number  ,
Bool   
)

Definition at line 590 of file reorder.cpp.

References add_bound_variables_in_test(), add_to_growable_string(), condition_struct::data, FALSE, cons_struct::first, free_growable_string(), three_field_tests_struct::id_test, make_blank_growable_string(), agent_struct::name_of_production_being_reordered, condition_struct::next, NIL, POSITIVE_CONDITION, print(), PRINT_WARNINGS_SYSPARAM, print_with_symbols(), cons_struct::rest, symbol_to_string(), agent_struct::sysparams, test_includes_equality_test_for_symbol(), test_includes_goal_or_impasse_id_test(), condition_struct::condition_main_data_union::tests, text_of_growable_string(), TRUE, condition_struct::type, unmark_variables_and_free_list(), three_field_tests_struct::value_test, and xml_generate_warning().

Referenced by find_compile_time_match_goal(), reorder_lhs(), and reorder_simplified_conditions().

{
list *new_vars_from_value_slot;
list *new_vars_from_id_slot;
cons *c;
condition *cond;
Bool found_goal_impasse_test;
/* --- find everthing that's in the value slot of some condition --- */
new_vars_from_value_slot = NIL;
for (cond=cond_list; cond!=NIL; cond=cond->next)
&new_vars_from_value_slot);
/* --- now see what else we can add by throwing in the id slot --- */
new_vars_from_id_slot = NIL;
for (cond=cond_list; cond!=NIL; cond=cond->next)
&new_vars_from_id_slot);
/* --- unmark everything we just marked --- */
unmark_variables_and_free_list (thisAgent, new_vars_from_value_slot);
for (c=new_vars_from_id_slot; c!=NIL; c=c->rest)
static_cast<Symbol *>(c->first)->var.tc_num = 0;
/* --- make sure each root var has some condition with goal/impasse --- */
if (allow_printing_warnings && thisAgent->sysparams[PRINT_WARNINGS_SYSPARAM]) {
for (c=new_vars_from_id_slot; c!=NIL; c=c->rest) {
found_goal_impasse_test = FALSE;
for (cond=cond_list; cond!=NIL; cond=cond->next) {
if (cond->type!=POSITIVE_CONDITION) continue;
static_cast<symbol_union *>(c->first)))
TRUE, TRUE)) {
found_goal_impasse_test = TRUE;
break;
}
}
if (! found_goal_impasse_test) {
print (thisAgent, "\nWarning: On the LHS of production %s, identifier ",
print_with_symbols (thisAgent, "%y is not connected to any goal or impasse.\n",
static_cast<Symbol *>(c->first));
// XML geneneration
add_to_growable_string(thisAgent, &gs, "Warning: On the LHS of production ");
add_to_growable_string(thisAgent, &gs, ", identifier ");
add_to_growable_string(thisAgent, &gs, symbol_to_string (thisAgent, static_cast<Symbol *>(c->first), true, 0, 0));
add_to_growable_string(thisAgent, &gs, " is not connected to any goal or impasse.");
free_growable_string(thisAgent, gs);
}
}
}
return new_vars_from_id_slot;
}
void init_reorderer ( agent thisAgent)

Definition at line 1218 of file reorder.cpp.

References init_memory_pool(), and agent_struct::saved_test_pool.

Referenced by init_production_utilities().

{ /* called from init_production_utilities() */
init_memory_pool (thisAgent, &thisAgent->saved_test_pool, sizeof(saved_test), "saved test");
}
Bool reorder_action_list ( agent thisAgent,
action **  action_list,
tc_number  lhs_tc 
)

Definition at line 85 of file reorder.cpp.

References add_all_variables_in_action(), FALSE, legal_to_execute_action(), agent_struct::name_of_production_being_reordered, action_struct::next, NIL, print(), TRUE, and unmark_variables_and_free_list().

Referenced by make_production().

{
list *new_bound_vars;
action *remaining_actions;
action *first_action, *last_action;
action *a, *prev_a;
Bool result_flag;
new_bound_vars = NIL;
remaining_actions = *action_list;
first_action = NIL;
last_action = NIL;
while (remaining_actions) {
/* --- scan through remaining_actions, look for one that's legal --- */
prev_a = NIL;
a = remaining_actions;
while (TRUE) {
if (!a) break; /* looked at all candidates, but none were legal */
if (legal_to_execute_action (a, lhs_tc)) break;
prev_a = a;
a = a->next;
}
if (!a) break;
/* --- move action a from remaining_actions to reordered list --- */
if (prev_a) prev_a->next = a->next; else remaining_actions = a->next;
a->next = NIL;
if (last_action) last_action->next = a; else first_action = a;
last_action = a;
/* --- add new variables from a to new_bound_vars --- */
add_all_variables_in_action (thisAgent, a, lhs_tc, &new_bound_vars);
}
if (remaining_actions) {
/* --- there are remaining_actions but none can be legally added --- */
print (thisAgent, "Error: production %s has a bad RHS--\n",
print (thisAgent, " Either it creates structure not connected to anything\n");
print (thisAgent, " else in WM, or it tries to pass an unbound variable as\n");
print (thisAgent, " an argument to a function.\n");
/* --- reconstruct list of all actions --- */
if (last_action)
last_action->next = remaining_actions;
else
first_action = remaining_actions;
result_flag = FALSE;
} else {
result_flag = TRUE;
}
/* --- unmark variables that we just marked --- */
unmark_variables_and_free_list (thisAgent, new_bound_vars);
/* --- return final result --- */
*action_list = first_action;
return result_flag;
}
Bool reorder_lhs ( agent thisAgent,
condition **  lhs_top,
condition **  lhs_bottom,
Bool  reorder_nccs 
)

Definition at line 1175 of file reorder.cpp.

References add_bound_variables_in_test(), check_negative_relational_test_bindings(), collect_root_variables(), condition_struct::data, FALSE, fill_in_vars_requiring_bindings(), free_list(), get_new_tc_number(), three_field_tests_struct::id_test, agent_struct::name_of_production_being_reordered, condition_struct::next, NIL, POSITIVE_CONDITION, print(), remove_isa_state_tests_for_non_roots(), remove_vars_requiring_bindings(), reorder_condition_list(), test_includes_goal_or_impasse_id_test(), condition_struct::condition_main_data_union::tests, TRUE, and condition_struct::type.

Referenced by make_production().

{
list *roots;
tc = get_new_tc_number (thisAgent);
/* don't mark any variables, since nothing is bound outside the LHS */
roots = collect_root_variables (thisAgent, *lhs_top, tc, TRUE);
/* SBH/MVP 6-24-94 Fix to include only root "STATE" test in the LHS of a chunk.*/
if (roots) remove_isa_state_tests_for_non_roots(thisAgent, lhs_top,lhs_bottom,roots);
/* MVP 6-8-94 - fix provided by Bob */
if (!roots) {
condition *cond;
for (cond = *lhs_top; cond!=NIL; cond=cond->next) {
if ((cond->type == POSITIVE_CONDITION) &&
TRUE, FALSE))) {
add_bound_variables_in_test (thisAgent, cond->data.tests.id_test, tc, &roots);
if (roots) break;
}
}
}
if (!roots) {
print (thisAgent, "Error: in production %s,\n", thisAgent->name_of_production_being_reordered);
print (thisAgent, " The LHS has no roots.\n");
/* hmmm... most people aren't going to understand this error message */
return FALSE;
}
fill_in_vars_requiring_bindings (thisAgent, *lhs_top, tc);
reorder_condition_list (thisAgent, lhs_top, lhs_bottom, roots, tc, reorder_nccs);
remove_vars_requiring_bindings (thisAgent, *lhs_top);
free_list (thisAgent, roots);
return check_negative_relational_test_bindings (thisAgent, *lhs_top, get_new_tc_number (thisAgent));
}