Main Page | Alphabetical List | Data Structures | File List | Data Fields | Globals

scheduler.c

Go to the documentation of this file.
00001 /*
00002  * =======================================================================
00003  *  File:  soarScheduler.c
00004  *
00005  * Uses a round-robin to run all soar agents.
00006  *
00007  * =======================================================================
00008  *
00009  *
00010  * Copyright 1995-2003 Carnegie Mellon University,
00011  *                                                                               University of Michigan,
00012  *                                                                               University of Southern California/Information
00013  *                                                                               Sciences Institute. All rights reserved.
00014  *                                                                              
00015  * Redistribution and use in source and binary forms, with or without
00016  * modification, are permitted provided that the following conditions are met:
00017  *
00018  * 1.   Redistributions of source code must retain the above copyright notice,
00019  *              this list of conditions and the following disclaimer. 
00020  * 2.   Redistributions in binary form must reproduce the above copyright notice,
00021  *              this list of conditions and the following disclaimer in the documentation
00022  *              and/or other materials provided with the distribution. 
00023  *
00024  * THIS SOFTWARE IS PROVIDED BY THE SOAR CONSORTIUM ``AS IS'' AND ANY EXPRESS OR
00025  * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
00026  * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO
00027  * EVENT SHALL THE SOAR CONSORTIUM  OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT,
00028  * INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
00029  * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
00030  * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
00031  * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
00032  * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
00033  * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
00034  * The views and conclusions contained in the software and documentation are
00035  * those of the authors and should not be interpreted as representing official
00036  * policies, either expressed or implied, of Carnegie Mellon University, the
00037  * University of Michigan, the University of Southern California/Information
00038  * Sciences Institute, or the Soar consortium.
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                  *  I have put a callback in to do just this.  But I haven't
00089                  *  really figured out what functionality it provides....
00090                  *  This statement was only defined with the USE_TCL flag
00091                  *  082099 SW
00092                  */
00093                 /*
00094                    Soar_SelectGlobalInterpByInterp(soar_agent->interpreter);
00095                  */
00096 
00097                 if (!current_agent(stop_soar)) {
00098 
00099                     run_current_agent(1, go_type, go_slot_attr, go_slot_level);
00100 
00101                 }               /* if */
00102             }                   /* for */
00103 
00104         }                       /* while */
00105 
00106         soar_agent = prev_agent;
00107 
00108         /* 
00109          *  There is no analog for this, however, I don't really see
00110          *  what this does either... (possible bug)
00111          *  This block was only defined in with USE_TCL flag
00112          *  082099 SW
00113          *  SWBUG possible bug for when using Tcl
00114          */
00115         /*  Soar_SelectGlobalInterpByInterp(soar_agent->interpreter); */
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 }

Generated on Thu Dec 11 13:00:20 2003 for Soar Kernel by doxygen 1.3.5