00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
00028
00029
00030
00031
00032
00033
00034
00035
00036
00037
00038
00039
00040
00041
00042 #include "soarkernel.h"
00043 #include "scheduler.h"
00044
00045 void run_all_agents(long go_number, enum go_type_enum go_type, Symbol * go_slot_attr, goal_stack_level go_slot_level)
00046 {
00047 bool agent_to_run = TRUE;
00048 cons *c;
00049 agent *the_agent;
00050 agent *prev_agent;
00051 long cycle_count = 0;
00052
00053 prev_agent = soar_agent;
00054 c = all_soar_agents;
00055 if (!c->rest) {
00056
00057 run_current_agent(go_number, go_type, go_slot_attr, go_slot_level);
00058 }
00059
00060 else {
00061
00062 for (c = all_soar_agents; c != NIL; c = c->rest) {
00063 the_agent = (agent *) c->first;
00064 the_agent->stop_soar = FALSE;
00065 }
00066
00067 for (;;) {
00068
00069 if (cycle_count == go_number)
00070 break;
00071 cycle_count++;
00072
00073 agent_to_run = FALSE;
00074 for (c = all_soar_agents; c != NIL; c = c->rest) {
00075 soar_agent = (agent *) c->first;
00076 if (!(soar_agent->stop_soar)) {
00077 agent_to_run = TRUE;
00078 }
00079 }
00080
00081 if (!agent_to_run)
00082 break;
00083
00084 for (c = all_soar_agents; c != NIL; c = c->rest) {
00085 soar_agent = (agent *) c->first;
00086
00087
00088
00089
00090
00091
00092
00093
00094
00095
00096
00097 if (!current_agent(stop_soar)) {
00098
00099 run_current_agent(1, go_type, go_slot_attr, go_slot_level);
00100
00101 }
00102 }
00103
00104 }
00105
00106 soar_agent = prev_agent;
00107
00108
00109
00110
00111
00112
00113
00114
00115
00116 }
00117
00118 }
00119
00120 void run_current_agent(long go_number, enum go_type_enum go_type, Symbol * go_slot_attr, goal_stack_level go_slot_level)
00121 {
00122
00123 soar_invoke_callbacks(soar_agent, BEFORE_SCHEDULE_CYCLE_CALLBACK, (soar_call_data) TRUE);
00124
00125 switch (go_type) {
00126 case GO_PHASE:
00127 run_for_n_phases(go_number);
00128 break;
00129 case GO_ELABORATION:
00130 run_for_n_elaboration_cycles(go_number);
00131 break;
00132 case GO_DECISION:
00133 run_for_n_decision_cycles(go_number);
00134 break;
00135 case GO_STATE:
00136 run_for_n_selections_of_slot(go_number, soar_agent->state_symbol);
00137 break;
00138 case GO_OPERATOR:
00139 run_for_n_selections_of_slot(go_number, soar_agent->operator_symbol);
00140 break;
00141 case GO_SLOT:
00142 run_for_n_selections_of_slot_at_level(go_number, go_slot_attr, go_slot_level);
00143 break;
00144 case GO_OUTPUT:
00145 run_for_n_modifications_of_output(go_number);
00146 break;
00147 }
00148
00149 soar_invoke_callbacks(soar_agent, AFTER_SCHEDULE_CYCLE_CALLBACK, (soar_call_data) TRUE);
00150
00151 }