/[ascend]/trunk/base/generic/solver/slv.c
ViewVC logotype

Diff of /trunk/base/generic/solver/slv.c

Parent Directory Parent Directory | Revision Log Revision Log | View Patch Patch

revision 198 by johnpye, Thu Jan 19 08:14:26 2006 UTC revision 199 by johnpye, Sat Jan 21 02:23:55 2006 UTC
# Line 4  Line 4 
4      Copyright (C) 1993 Joseph Zaher      Copyright (C) 1993 Joseph Zaher
5      Copyright (C) 1994 Joseph Zaher, Benjamin Andrew Allan      Copyright (C) 1994 Joseph Zaher, Benjamin Andrew Allan
6      Copyright (C) 1996 Benjamin Andrew Allan      Copyright (C) 1996 Benjamin Andrew Allan
7      Copyright (C) 2005 Carnegie-Mellon University      Copyright (C) 2005-2006 Carnegie-Mellon University
8    
9      This program is free software; you can redistribute it and/or modify      This program is free software; you can redistribute it and/or modify
10      it under the terms of the GNU General Public License as published by      it under the terms of the GNU General Public License as published by
# Line 197  struct slv_system_structure { Line 197  struct slv_system_structure {
197    struct gl_list_t *symbollist; /* list of symbol values struct used to */    struct gl_list_t *symbollist; /* list of symbol values struct used to */
198                                  /* assign an integer value to a symbol value */                                  /* assign an integer value to a symbol value */
199    struct {    struct {
200        /** @TODO move the 'bufs' into the above structs (disunatt, etc) */
201      struct var_variable *ubuf; /* data space for unclassified real ATOMs */      struct var_variable *ubuf; /* data space for unclassified real ATOMs */
202      struct dis_discrete *udbuf; /* data space for unclassified discrete ATOM */      struct dis_discrete *udbuf; /* data space for unclassified discrete ATOM */
203      struct var_variable *pbuf; /* data space for real ATOMs that are pars */      struct var_variable *pbuf; /* data space for real ATOMs that are pars */
# Line 222  struct slv_system_structure { Line 223  struct slv_system_structure {
223    } data;    } data;
224    
225    int32 nmodels;    int32 nmodels;
226    int32 need_consistency; /*    int32 need_consistency; /* consistency analysis required for conditional model ? */
                * consistency analysis required for conditional  
                * model ?  
                */  
227    real64 objvargrad; /* maximize -1 minimize 1 noobjvar 0 */    real64 objvargrad; /* maximize -1 minimize 1 noobjvar 0 */
228  };  };
   
229    
230  /**  /**
231   global variable used to communicate information between solvers and   global variable used to communicate information between solvers and
# Line 268  static int g_number_of_bnds; Line 265  static int g_number_of_bnds;
265  /** Return the solver index for a given slv_system_t */  /** Return the solver index for a given slv_system_t */
266  #define SNUM(sys) ((sys)->solver)  #define SNUM(sys) ((sys)->solver)
267    
268  /** leave it in here John. Unilateral 'housecleaning' of this sort is not appreciated. */  /** Number of registered clients */
269  #define NORC g_SlvNumberOfRegisteredClients  #define NORC g_SlvNumberOfRegisteredClients
270    
271  /** leave it in here John. Unilateral 'housecleaning' of this sort is not appreciated. */  /** Return the pointer to a registered SLV client's data space. @see SF, related.
272        @param i registered solver ID
273    */
274  #define SCD(i) SlvClientsData[(i)]  #define SCD(i) SlvClientsData[(i)]
275    
276  /** Get the solver index for a system and return TRUE if the solver  /** Get the solver index for a system and return TRUE if the solver
# Line 352  unsigned slv_serial_id(slv_system_t sys) Line 351  unsigned slv_serial_id(slv_system_t sys)
351    return sys->serial_id;    return sys->serial_id;
352  }  }
353    
354    /*----------------------------------------------------
355        destructors
356    */
357  static  static
358  void slv_destroy_dvar_buffer(struct dis_discrete *dbuf)  void slv_destroy_dvar_buffer(struct dis_discrete *dbuf)
359  {  {
# Line 462  void slv_destroy_client(slv_system_t sys Line 464  void slv_destroy_client(slv_system_t sys
464    }    }
465  }  }
466    
467    /*---------------------------------------------------------
468        get/set instance
469    */
470    
471  SlvBackendToken slv_instance(slv_system_t sys)  SlvBackendToken slv_instance(slv_system_t sys)
472  {  {
# Line 511  void slv_set_num_models(slv_system_t sys Line 516  void slv_set_num_models(slv_system_t sys
516    }    }
517  }  }
518    
 void slv_set_master_var_list(slv_system_t sys,  
                              struct var_variable **vlist, int size)  
 {  
   SFUN(sys->vars.master);  
   sys->vars.mnum = size;  
   sys->vars.master = vlist;  
 }  
   
 void slv_set_master_par_list(slv_system_t sys,  
                              struct var_variable **vlist, int size)  
 {  
   SFUN(sys->pars.master);  
   sys->pars.mnum = size;  
   sys->pars.master = vlist;  
 }  
   
 void slv_set_master_unattached_list(slv_system_t sys,  
                              struct var_variable **vlist, int size)  
 {  
   SFUN(sys->unattached.master);  
   sys->unattached.mnum = size;  
   sys->unattached.master = vlist;  
 }  
   
 void slv_set_master_dvar_list(slv_system_t sys,  
                               struct dis_discrete **dlist, int size)  
 {  
   SFUN(sys->dvars.master);  
   sys->dvars.mnum = size;  
   sys->dvars.master = dlist;  
 }  
   
 void slv_set_master_disunatt_list(slv_system_t sys,  
                                   struct dis_discrete **dlist, int size)  
 {  
   SFUN(sys->disunatt.master);  
   sys->disunatt.mnum = size;  
   sys->disunatt.master = dlist;  
 }  
   
 void slv_set_master_rel_list(slv_system_t sys,struct rel_relation **rlist,  
               int size)  
 {  
   SFUN(sys->rels.master);  
   sys->rels.mnum = size;  
   sys->rels.master = rlist;  
 }  
   
   
 void slv_set_master_condrel_list(slv_system_t sys,struct rel_relation **rlist,  
                          int size)  
 {  
   SFUN(sys->condrels.master);  
   sys->condrels.mnum = size;  
   sys->condrels.master = rlist;  
 }  
   
 void slv_set_master_obj_list(slv_system_t sys,struct rel_relation **rlist,  
                      int size)  
 {  
   SFUN(sys->objs.master);  
   sys->objs.mnum = size;  
   sys->objs.master = rlist;  
 }  
   
 void slv_set_master_logrel_list(slv_system_t sys,  
                 struct logrel_relation **lrlist,  
                         int size)  
 {  
   SFUN(sys->logrels.master);  
   sys->logrels.mnum = size;  
   sys->logrels.master = lrlist;  
 }  
   
 void slv_set_master_condlogrel_list(slv_system_t sys,  
                 struct logrel_relation **lrlist,  
                         int size)  
 {  
   SFUN(sys->condlogrels.master);  
   sys->condlogrels.mnum = size;  
   sys->condlogrels.master = lrlist;  
 }  
   
 void slv_set_master_when_list(slv_system_t sys,  
                   struct w_when **wlist,  
                       int size)  
 {  
   SFUN(sys->whens.master);  
   sys->whens.mnum = size;  
   sys->whens.master = wlist;  
 }  
   
 void slv_set_master_bnd_list(slv_system_t sys,  
                  struct bnd_boundary **blist,  
                      int size)  
 {  
   SFUN(sys->bnds.master);  
   sys->bnds.mnum = size;  
   sys->bnds.master = blist;  
 }  
519    
520  void slv_set_symbol_list(slv_system_t sys,  void slv_set_symbol_list(slv_system_t sys,
521               struct gl_list_t *sv)               struct gl_list_t *sv)
# Line 621  void slv_set_symbol_list(slv_system_t sy Line 526  void slv_set_symbol_list(slv_system_t sy
526    sys->symbollist = sv;    sys->symbollist = sv;
527  }  }
528    
529  void slv_set_var_buf(slv_system_t sys, struct var_variable *vbuf)  /*--------------------------------------------------------]
530  {      Macros to declare
   if (sys->data.vbuf !=NULL ) {  
     Asc_Panic(2,"slv_set_var_buf",  
               "bad call.");  
   } else {  
     sys->data.vbuf = vbuf;  
   }  
 }  
531    
532        slv_set_master_*_list(slv_system_t sys, string var_variable **list, int size)
533        slv_set_*_buf(slv_system_t sys, string var_variable **list, int size)
534    */
535    
536  void slv_set_par_buf(slv_system_t sys, struct var_variable *pbuf)  #define DEFINE_SET_MASTER_LIST_METHOD(NAME,PROP,TYPE) \
537  {      void slv_set_master_##NAME##_list(slv_system_t sys, struct TYPE **vlist, int size){ \
538    if (sys->data.pbuf !=NULL ) {          SFUN(sys->PROP.master); \
539      Asc_Panic(2,"slv_set_par_buf",          sys->PROP.mnum = size; \
540                "bad call.");          sys->PROP.master = vlist; \
541    } else {      }
     sys->data.pbuf = pbuf;  
   }  
 }  
542    
 void slv_set_unattached_buf(slv_system_t sys, struct var_variable *ubuf)  
 {  
   if (sys->data.ubuf !=NULL ) {  
     Asc_Panic(2,"slv_set_unattached_buf",  
               "bad call.");  
   } else {  
     sys->data.ubuf = ubuf;  
   }  
 }  
543    
 void slv_set_dvar_buf(slv_system_t sys, struct dis_discrete *dbuf, int len)  
 {  
   if (sys->data.dbuf !=NULL ) {  
     Asc_Panic(2,"slv_set_dvar_buf",  
               "bad call.");  
   } else {  
     sys->data.dbuf = dbuf;  
     g_number_of_dvars = len;  
   }  
 }  
544    
545    #define DEFINE_SET_MASTER_LIST_METHODS(D) \
546        D(var,vars,var_variable) \
547        D(par,pars,var_variable) \
548        D(unattached,unattached,var_variable); \
549        D(dvar,dvars,dis_discrete) \
550        D(disunatt,disunatt,dis_discrete) \
551        D(rel,rels,rel_relation) \
552        D(condrel,condrels,rel_relation) \
553        D(obj,objs,rel_relation) \
554        D(logrel,logrels,logrel_relation) \
555        D(condlogrel,condlogrels,logrel_relation) \
556        D(when,whens,w_when) \
557        D(bnd,bnds,bnd_boundary)
558    
559  void slv_set_disunatt_buf(slv_system_t sys, struct dis_discrete *udbuf)  DEFINE_SET_MASTER_LIST_METHODS(DEFINE_SET_MASTER_LIST_METHOD)
 {  
   if (sys->data.udbuf !=NULL ) {  
     Asc_Panic(2,"slv_set_disunatt_buf",  
               "bad call.");  
   } else {  
     sys->data.udbuf = udbuf;  
   }  
 }  
560    
561  void slv_set_rel_buf(slv_system_t sys, struct rel_relation *rbuf)  /*------------------------------------------------------------
562  {      Macros to declare
   if (sys->data.rbuf !=NULL ) {  
     Asc_Panic(2,"slv_set_rel_buf",  
               "bad call.");  
   } else {  
     sys->data.rbuf = rbuf;  
   }  
 }  
563    
564        slv_set_NAME_buf(slv_system_t sts, struct TYPE *PROP)
565    */
566    
567  void slv_set_condrel_buf(slv_system_t sys, struct rel_relation *cbuf)  #define DEFINE_SET_BUF_METHOD(NAME,PROP,TYPE) \
568  {      void slv_set_##NAME##_buf(slv_system_t sys, struct TYPE *PROP){ \
569    if (sys->data.cbuf !=NULL ) {          if(sys->data.PROP !=NULL ){ \
570      Asc_Panic(2,"slv_set_condrel_buf",              Asc_Panic(2,"slv_set_" #NAME "_buf","bad call."); \
571                "bad call.");          }else{ \
572    } else {              sys->data.PROP = PROP; \
573      sys->data.cbuf = cbuf;          } \
574    }      }
 }  
   
 void slv_set_obj_buf(slv_system_t sys, struct rel_relation *obuf)  
 {  
   if (sys->data.obuf !=NULL ) {  
     Asc_Panic(2,"slv_set_obj_buf",  
               "bad call.");  
   } else {  
     sys->data.obuf = obuf;  
   }  
 }  
   
 void slv_set_logrel_buf(slv_system_t sys, struct logrel_relation *lbuf)  
 {  
   if (sys->data.lbuf !=NULL ) {  
     Asc_Panic(2,"slv_set_logrel_buf",  
               "bad call.");  
   } else {  
     sys->data.lbuf = lbuf;  
   }  
 }  
575    
576    #define DEFINE_SET_BUF_METHODS(D) \
577        D(var,vbuf,var_variable) \
578        D(par,pbuf,var_variable) \
579        D(unattached,ubuf,var_variable) \
580        D(disunatt,udbuf,dis_discrete) \
581        D(rel,rbuf,rel_relation) \
582        D(condrel,cbuf,rel_relation) \
583        D(obj,obuf,rel_relation) \
584        D(logrel,lbuf,logrel_relation) \
585        D(condlogrel,clbuf,logrel_relation)
586    
587    DEFINE_SET_BUF_METHODS(DEFINE_SET_BUF_METHOD)
588    
589    /*
590        Before the following can be placed into the above macro, the globals
591            g_number_of_dvars
592            g_number_of_whens
593            g_number_of_bnds
594        need to be eliminated. They should be entered as properties of the 'sys', presumably?
595    */
596    
597  void slv_set_condlogrel_buf(slv_system_t sys, struct logrel_relation *clbuf)  void slv_set_dvar_buf(slv_system_t sys, struct dis_discrete *dbuf, int len)
598  {  {
599    if (sys->data.clbuf !=NULL ) {    if (sys->data.dbuf !=NULL ) {
600      Asc_Panic(2,"slv_set_condlogrel_buf",      Asc_Panic(2,"slv_set_dvar_buf",
601                "bad call.");                "bad call.");
602    } else {    } else {
603      sys->data.clbuf = clbuf;      sys->data.dbuf = dbuf;
604        g_number_of_dvars = len;
605    }    }
606  }  }
607    
# Line 747  void slv_set_bnd_buf(slv_system_t sys, s Line 626  void slv_set_bnd_buf(slv_system_t sys, s
626    }    }
627  }  }
628    
629    /*---------------------------------------------------------------*/
630    
631  void slv_set_incidence(slv_system_t sys, struct var_variable **incidence,long s)  void slv_set_incidence(slv_system_t sys, struct var_variable **incidence,long s)
632  {  {
633    if (sys->data.incidence !=NULL || incidence == NULL) {    if (sys->data.incidence !=NULL || incidence == NULL) {
# Line 769  void slv_set_var_incidence(slv_system_t Line 650  void slv_set_var_incidence(slv_system_t
650    }    }
651  }  }
652    
653  void slv_set_logincidence(slv_system_t sys, struct dis_discrete **logincidence,  void slv_set_logincidence(slv_system_t sys, struct dis_discrete **logincidence,long s)
               long s)  
654  {  {
655    if (sys->data.logincidence !=NULL) {    if (sys->data.logincidence !=NULL) {
656      Asc_Panic(2,"slv_set_logincidence","bad call.");      Asc_Panic(2,"slv_set_logincidence","bad call.");
# Line 923  void slv_bnd_initialization(slv_system_t Line 803  void slv_bnd_initialization(slv_system_t
803    }    }
804  }  }
805    
806    struct gl_list_t *slv_get_symbol_list(slv_system_t sys)
 void slv_set_solvers_var_list(slv_system_t sys,  
                               struct var_variable **vlist, int size)  
 {  
   if (sys->vars.master == NULL) {  
     ERROR_REPORTER_NOLINE(ASC_PROG_ERR,"slv_set_solvers_var_list: called before slv_set_master_var_list.");  
     return; /* must be error */  
   }  
   sys->vars.snum = size;  
   sys->vars.solver = vlist;  
 }  
   
   
 void slv_set_solvers_par_list(slv_system_t sys,  
                               struct var_variable **vlist, int size)  
 {  
   if (sys->pars.master == NULL ) {  
     ERROR_REPORTER_NOLINE(ASC_PROG_WARNING,"slv_set_solvers_par_list: called before slv_set_master_par_list.");  
   } /* might be ok */  
   sys->pars.snum = size;  
   sys->pars.solver = vlist;  
 }  
   
 void slv_set_solvers_unattached_list(slv_system_t sys,  
                                      struct var_variable **vlist, int size)  
 {  
   if (sys->unattached.master == NULL) {  
     ERROR_REPORTER_NOLINE(ASC_PROG_WARNING,"slv_set_solvers_unattached_list: called before slv_set_master_unattached_list.");  
   } /* might be ok */  
   sys->unattached.snum = size;  
   sys->unattached.solver = vlist;  
 }  
   
 void slv_set_solvers_dvar_list(slv_system_t sys,  
                               struct dis_discrete **dlist, int size)  
 {  
   if (sys->dvars.master == NULL) {  
     ERROR_REPORTER_NOLINE(ASC_PROG_ERROR,"slv_set_solvers_dvar_list: called before slv_set_master_dvar_list.");  
     return; /* must be error */  
   }  
   sys->dvars.snum = size;  
   sys->dvars.solver = dlist;  
 }  
   
 void slv_set_solvers_disunatt_list(slv_system_t sys,  
                                    struct dis_discrete **dlist, int size)  
 {  
   if (sys->disunatt.master == NULL) {  
     ERROR_REPORTER_NOLINE(ASC_PROG_WARNING,"slv_set_solvers_disunatt_list: called before slv_set_master_disunatt_list.");  
   } /* might be ok */  
   sys->disunatt.snum = size;  
   sys->disunatt.solver = dlist;  
 }  
   
 void slv_set_solvers_rel_list(slv_system_t sys,  
                               struct rel_relation **rlist, int size)  
 {  
   /* Give relation list to the system itself. */  
   if (sys->rels.master == NULL) {  
     ERROR_REPORTER_NOLINE(ASC_PROG_ERROR,"slv_set_solvers_rel_list: called before slv_set_master_rel_list.");  
     return; /* can't be right */  
   }  
   sys->rels.snum = size;  
   sys->rels.solver = rlist;  
 }  
   
   
 void slv_set_solvers_obj_list(slv_system_t sys,  
                               struct rel_relation **rlist, int size)  
 {  
   /* Give relation list to the system itself. */  
   if (sys->objs.master == NULL) {  
     ERROR_REPORTER_NOLINE(ASC_PROG_ERROR,"slv_set_solvers_obj_list: called before slv_set_master_rel_list.");  
     return;  
   }  
   sys->objs.snum = size;  
   sys->objs.solver = rlist;  
 }  
   
 void slv_set_solvers_condrel_list(slv_system_t sys,  
                               struct rel_relation **rlist, int size)  
 {  
   /* Give relation list to the system itself. */  
   if (sys->condrels.master == NULL) {  
     ERROR_REPORTER_NOLINE(ASC_PROG_ERROR,"slv_set_solvers_condrel_list: called before slv_set_master_condrel_list");  
     return;  
   }  
   sys->condrels.snum = size;  
   sys->condrels.solver = rlist;  
 }  
   
   
 void slv_set_solvers_logrel_list(slv_system_t sys,  
                                  struct logrel_relation **lrlist, int size)  
 {  
   /* Give logrelation list to the system itself. */  
   if (sys->logrels.master == NULL) {  
     ERROR_REPORTER_NOLINE(ASC_PROG_ERROR,"slv_set_solvers_logrel_list: called before slv_set_master_logrel_list.");  
     return; /* can't be right */  
   }  
   sys->logrels.snum = size;  
   sys->logrels.solver = lrlist;  
 }  
   
 void slv_set_solvers_condlogrel_list(slv_system_t sys,  
                                      struct logrel_relation **lrlist, int size)  
 {  
   /* Give logrelation list to the system itself. */  
   if (sys->condlogrels.master == NULL) {  
     ERROR_REPORTER_NOLINE(ASC_PROG_ERROR,  
         "slv_set_solvers_condlogrel_list: called before slv_set_master_logrel_list.");  
     return; /* can't be right */  
   }  
   sys->condlogrels.snum = size;  
   sys->condlogrels.solver = lrlist;  
 }  
   
 void slv_set_solvers_when_list(slv_system_t sys,  
                                struct w_when **wlist, int size)  
 {  
   if (sys->whens.master == NULL) {  
     ERROR_REPORTER_NOLINE(ASC_PROG_ERROR,"slv_set_solvers_when_list: called before slv_set_master_when_list.");  
     return;  
   }  
   sys->whens.snum = size;  
   sys->whens.solver = wlist;  
 }  
   
 void slv_set_solvers_bnd_list(slv_system_t sys,  
                               struct bnd_boundary **blist, int size)  
 {  
   if (sys->bnds.master == NULL) {  
     ERROR_REPORTER_NOLINE(ASC_PROG_ERROR,"slv_set_solvers_bnd_list: called before slv_set_master_bnd_list.");  
     return;  
   }  
   sys->bnds.snum = size;  
   sys->bnds.solver = blist;  
 }  
   
 struct var_variable **slv_get_solvers_var_list(slv_system_t sys)  
 {  
   if (sys->vars.solver == NULL) {  
     ERROR_REPORTER_NOLINE(ASC_PROG_ERROR,"slv_get_solvers_var_list: returning NULL (?).");  
   }  
   return sys->vars.solver;  
 }  
   
 struct var_variable **slv_get_solvers_par_list(slv_system_t sys)  
 {  
   if (sys->pars.solver == NULL) {  
     ERROR_REPORTER_NOLINE(ASC_PROG_ERROR,"slv_get_solvers_par_list: returning NULL (?).");  
   }  
   return sys->pars.solver;  
 }  
   
 struct var_variable **slv_get_solvers_unattached_list(slv_system_t sys)  
 {  
   if (sys->unattached.solver == NULL) {  
     ERROR_REPORTER_NOLINE(ASC_PROG_ERROR,"slv_get_solvers_unattached_list: returning NULL?\n");  
   }  
   return sys->unattached.solver;  
 }  
   
 struct dis_discrete **slv_get_solvers_dvar_list(slv_system_t sys)  
 {  
   if (sys->dvars.solver == NULL) {  
     ERROR_REPORTER_NOLINE(ASC_PROG_ERROR,"dvar_list is NULL\n");  
   }  
   return sys->dvars.solver;  
 }  
   
 struct dis_discrete **slv_get_solvers_disunatt_list(slv_system_t sys)  
 {  
   if (sys->disunatt.solver == NULL) {  
     ERROR_REPORTER_NOLINE(ASC_PROG_ERROR,"slv_get_solvers_disunatt_list returning NULL?\n");  
   }  
   return sys->disunatt.solver;  
 }  
   
 struct var_variable **slv_get_master_var_list(slv_system_t sys)  
 {  
   if (sys->vars.master == NULL) {  
     ERROR_REPORTER_NOLINE(ASC_PROG_ERROR,"slv_get_master_var_list returning NULL?\n");  
   }  
   return sys->vars.master;  
 }  
   
   
 struct var_variable **slv_get_master_par_list(slv_system_t sys)  
 {  
   if (sys->pars.master == NULL) {  
     ERROR_REPORTER_NOLINE(ASC_PROG_ERROR,"slv_get_master_par_list returning NULL?\n");  
   }  
   return sys->pars.master;  
 }  
   
 struct var_variable **slv_get_master_unattached_list(slv_system_t sys)  
 {  
   if (sys->unattached.master == NULL) {  
     ERROR_REPORTER_NOLINE(ASC_PROG_ERROR,"slv_get_solvers_unattached_list returning NULL?\n");  
   }  
   return sys->unattached.master;  
 }  
   
 struct dis_discrete **slv_get_master_dvar_list(slv_system_t sys)  
 {  
   if (sys->dvars.master == NULL) {  
     ERROR_REPORTER_NOLINE(ASC_PROG_ERROR,"dvar_list is NULL\n");  
   }  
   return sys->dvars.master;  
 }  
   
 struct dis_discrete **slv_get_master_disunatt_list(slv_system_t sys)  
 {  
   if (sys->disunatt.master == NULL) {  
     ERROR_REPORTER_NOLINE(ASC_PROG_ERROR,"slv_get_solvers_disunatt_list returning NULL?\n");  
   }  
   return sys->disunatt.master;  
 }  
   
 struct rel_relation **slv_get_solvers_rel_list(slv_system_t sys)  
 {  
   if (sys->rels.solver == NULL) {  
     ERROR_REPORTER_NOLINE(ASC_PROG_ERROR,"slv_get_solvers_rel_list returning NULL?\n");  
   }  
   return sys->rels.solver;  
 }  
   
 struct rel_relation **slv_get_solvers_condrel_list(slv_system_t sys)  
 {  
   if (sys->condrels.solver == NULL) {  
     ERROR_REPORTER_NOLINE(ASC_PROG_ERROR,"condrel_list is NULL?\n");  
   }  
   return sys->condrels.solver;  
 }  
   
 struct rel_relation **slv_get_solvers_obj_list(slv_system_t sys)  
 {  
   if (sys->objs.solver == NULL) {  
     ERROR_REPORTER_NOLINE(ASC_PROG_ERROR,"slv_get_solvers_obj_list returning NULL?\n");  
   }  
   return sys->objs.solver;  
 }  
   
 struct logrel_relation **slv_get_solvers_logrel_list(slv_system_t sys)  
 {  
   if (sys->logrels.solver == NULL) {  
     ERROR_REPORTER_NOLINE(ASC_PROG_ERROR,"logrel_list is NULL\n");  
   }  
   return sys->logrels.solver;  
 }  
   
 struct logrel_relation **slv_get_solvers_condlogrel_list(slv_system_t sys)  
 {  
   if (sys->condlogrels.solver == NULL) {  
     ERROR_REPORTER_NOLINE(ASC_PROG_ERROR,"logrel_list is NULL\n");  
   }  
   return sys->condlogrels.solver;  
 }  
   
 struct w_when **slv_get_solvers_when_list(slv_system_t sys)  
 {  
   if (sys->whens.solver == NULL) {  
     ERROR_REPORTER_NOLINE(ASC_PROG_ERROR,"when_list is NULL\n");  
   }  
   return sys->whens.solver;  
 }  
   
 struct bnd_boundary **slv_get_solvers_bnd_list(slv_system_t sys)  
 {  
   if (sys->bnds.solver == NULL) {  
     ERROR_REPORTER_NOLINE(ASC_PROG_ERROR,"bnd_list is NULL\n");  
   }  
   return sys->bnds.solver;  
 }  
   
 struct rel_relation **slv_get_master_rel_list(slv_system_t sys)  
 {  
   if (sys->rels.master == NULL) {  
     ERROR_REPORTER_NOLINE(ASC_PROG_ERROR,"slv_get_master_rel_list returning NULL?\n");  
   }  
   return sys->rels.master;  
 }  
   
   
 struct rel_relation **slv_get_master_condrel_list(slv_system_t sys)  
807  {  {
808    if (sys->condrels.master == NULL) {    if (sys==NULL) {
809      ERROR_REPORTER_NOLINE(ASC_PROG_ERROR,"condrel_list is NULL\n");      ERROR_REPORTER_NOLINE(ASC_PROG_ERROR,"slv_get_symbol_list called with NULL system.\n");
810        return NULL;
811    }    }
812    return sys->condrels.master;    return sys->symbollist;
813  }  }
814    
815  struct rel_relation **slv_get_master_obj_list(slv_system_t sys)  /*---------------------------------------------------------
816  {      Macros to define
   if (sys->objs.master == NULL) {  
     ERROR_REPORTER_NOLINE(ASC_PROG_ERROR,"slv_get_master_obj_list returning NULL?\n");  
   }  
   return sys->objs.master;  
 }  
817    
818            slv_set_solvers_*_list
819            slv_get_solvers_*_list
820            slv_get_master_*_list
821    */
822    #define DEFINE_SET_SOLVERS_LIST_METHOD(NAME,PROP,TYPE) \
823        void slv_set_solvers_##NAME##_list(slv_system_t sys, struct TYPE **vlist, int size){ \
824            if(sys->PROP.master==NULL){ \
825                ERROR_REPORTER_NOLINE(ASC_PROG_ERR,"slv_set_solvers_" #NAME "_list: called before slv_set_master_" #NAME "_list."); \
826                /* might be ok, no return */ \
827            } \
828            sys->PROP.snum = size; \
829            sys->PROP.solver = vlist; \
830        }
831    
832  struct logrel_relation **slv_get_master_logrel_list(slv_system_t sys)  #define DEFINE_SET_SOLVERS_LIST_METHOD_RETURN(NAME,PROP,TYPE) \
833  {      void slv_set_solvers_##NAME##_list(slv_system_t sys, struct TYPE **vlist, int size){ \
834    if (sys->logrels.master == NULL) {          if(sys->PROP.master==NULL){ \
835      ERROR_REPORTER_NOLINE(ASC_PROG_ERROR,"logrel_list is NULL\n");              ERROR_REPORTER_NOLINE(ASC_PROG_ERR,"slv_set_solvers_" #NAME "_list: called before slv_set_master_" #NAME "_list."); \
836    }              return; /* can't be OK, so return now */ \
837    return sys->logrels.master;          } \
838  }          sys->PROP.snum = size; \
839            sys->PROP.solver = vlist; \
840        }
841    
842  struct logrel_relation **slv_get_master_condlogrel_list(slv_system_t sys)  #define DEFINE_GET_SOLVERS_LIST_METHOD(NAME,PROP,TYPE) \
843  {      struct TYPE **slv_get_solvers_##NAME##_list(slv_system_t sys){ \
844    if (sys->condlogrels.master == NULL) {          if (sys->PROP.solver == NULL) { \
845      ERROR_REPORTER_NOLINE(ASC_PROG_ERROR,"logrel_list is NULL\n");              ERROR_REPORTER_NOLINE(ASC_PROG_ERROR,"slv_get_solvers_" #NAME "_list: returning NULL (?)."); \
846    }          } \
847    return sys->condlogrels.master;          return sys->PROP.solver; \
848  }      }
849    
850    #define DEFINE_GETSET_LIST_METHODS(D,D_RETURN) \
851        D_RETURN(var,vars,var_variable) \
852        D(par,pars,var_variable) \
853        D(unattached,unattached,var_variable) \
854        D_RETURN(dvar,dvars,dis_discrete) \
855        D(disunatt,disunatt,dis_discrete) \
856        D_RETURN(rel,rels,rel_relation) \
857        D_RETURN(obj,objs,rel_relation) \
858        D_RETURN(condrel,condrels,rel_relation) \
859        D_RETURN(logrel,logrels,logrel_relation) \
860        D_RETURN(condlogrel,condlogrels,logrel_relation) \
861        D_RETURN(when,whens,w_when) \
862        D_RETURN(bnd,bnds,bnd_boundary)
863    
864    /* the slv_set_solvers_*_list methods: some have a 'return' when sys->PROP.master==NULL; others do not: */
865    DEFINE_GETSET_LIST_METHODS(DEFINE_SET_SOLVERS_LIST_METHOD, DEFINE_SET_SOLVERS_LIST_METHOD_RETURN)
866    
867    /* the slv_get_solvers_*_list methods: all have the same form so it's DEFINE...(D,D) in this case: */
868    DEFINE_GETSET_LIST_METHODS(DEFINE_GET_SOLVERS_LIST_METHOD, DEFINE_GET_SOLVERS_LIST_METHOD)
869    
870    #define DEFINE_GET_MASTER_LIST_METHOD(NAME,PROP,TYPE) \
871        struct TYPE **slv_get_master_##NAME##_list(slv_system_t sys){ \
872            if (sys->PROP.master == NULL) { \
873                ERROR_REPORTER_NOLINE(ASC_PROG_ERROR,"slv_get_master_" #NAME "_list returning NULL?\n"); \
874            } \
875            return sys->PROP.master; \
876        }
877    
878  struct w_when **slv_get_master_when_list(slv_system_t sys)  /* the slv_get_master_*_list are also all of the same form, so DEFINE...(D,D) */
879  {  DEFINE_GETSET_LIST_METHODS(DEFINE_GET_MASTER_LIST_METHOD,DEFINE_GET_MASTER_LIST_METHOD)
   if (sys->whens.master == NULL) {  
     ERROR_REPORTER_NOLINE(ASC_PROG_ERROR,"when_list is NULL\n");  
   }  
   return sys->whens.master;  
 }  
880    
881  struct bnd_boundary **slv_get_master_bnd_list(slv_system_t sys)  /*----------------------------------------------------------------------
882  {      Macros to define:
   if (sys->bnds.master == NULL) {  
     ERROR_REPORTER_NOLINE(ASC_PROG_ERROR,"bnd_list is NULL\n");  
   }  
   return sys->bnds.master;  
 }  
883    
884  struct gl_list_t *slv_get_symbol_list(slv_system_t sys)          slv_get_num_solvers_TYPE
885  {          slv_get_num_master_TYPE
886    if (sys==NULL) {  */
     ERROR_REPORTER_NOLINE(ASC_PROG_ERROR,"slv_get_symbol_list called with NULL system.\n");  
     return NULL;  
   }  
   return sys->symbollist;  
 }  
887    
888  #define DEFINE_SOLVERS_GET_NUM_METHOD(TYPE) \  #define DEFINE_SOLVERS_GET_NUM_METHOD(TYPE) \
889      int slv_get_num_solvers_##TYPE(slv_system_t sys){ \      int slv_get_num_solvers_##TYPE(slv_system_t sys){ \
# Line 1378  int32 slv_need_consistency(slv_system_t Line 996  int32 slv_need_consistency(slv_system_t
996    return sys->need_consistency;    return sys->need_consistency;
997  }  }
998    
999  /* dont call this with null! */  /*----------------------------------------------------------------
1000  static int slv_count_vars(var_filter_t *vfilter, struct var_variable **vlist)      Macros to define
 {  
   int ret = 0;  
   assert(vlist!=NULL);  
   while(*vlist!=NULL) {  
     ret += var_apply_filter(*vlist,vfilter);  
     vlist++;  
   }  
   return ret;  
 }  
1001    
1002  /* dont call this with null! */          slv_count_vars
1003  static int slv_count_rels(rel_filter_t *rfilter, struct rel_relation **rlist)                    rels
1004  {                    dvars
1005    int ret = 0;                    logrels
1006    assert(rlist!=NULL);                    whens
1007    while(*rlist!=NULL) {                    bnds
1008      ret += rel_apply_filter(*rlist,rfilter);  */
     rlist++;  
   }  
   return ret;  
 }  
   
 /* dont call this with null! */  
 static int slv_count_dvars(dis_filter_t *disfilter,  
                struct dis_discrete **dlist)  
 {  
   int ret = 0;  
   assert(dlist!=NULL);  
   while(*dlist!=NULL) {  
     ret += dis_apply_filter(*dlist,disfilter);  
     dlist++;  
   }  
   return ret;  
 }  
1009    
1010  /* dont call this with null! */  #define DEFINE_SLV_COUNT_METHOD(NAME,FILTER,TYPE) \
1011  static int slv_count_logrels(logrel_filter_t *lrfilter,      static int slv_count_##NAME(FILTER##_filter_t *filter, struct TYPE **list){ \
1012                   struct logrel_relation **lrlist)          int ret=0; \
1013  {          assert(list!=NULL); \
1014    int ret = 0;          while(*list!=NULL){ \
1015    assert(lrlist!=NULL);              ret += FILTER##_apply_filter(*list,filter); \
1016    while(*lrlist!=NULL) {              list++; \
1017      ret += logrel_apply_filter(*lrlist,lrfilter);          } \
1018      lrlist++;          return ret; \
1019    }      }
   return ret;  
 }  
1020    
1021  /* dont call this with null! */  #define DEFINE_SLV_COUNT_METHODS(D) \
1022  static int slv_count_whens(when_filter_t *wfilter,struct w_when **wlist)      D(vars,var,var_variable) \
1023  {      D(rels,rel,rel_relation) \
1024    int ret = 0;      D(dvars,dis,dis_discrete) \
1025    assert(wlist!=NULL);      D(logrels,logrel,logrel_relation) \
1026    while(*wlist!=NULL) {      D(whens,when,w_when) \
1027      ret += when_apply_filter(*wlist,wfilter);      D(bnds,bnd,bnd_boundary)
     wlist++;  
   }  
   return ret;  
 }  
1028    
1029  /* dont call this with null! */  DEFINE_SLV_COUNT_METHODS(DEFINE_SLV_COUNT_METHOD)
 static int slv_count_bnds(bnd_filter_t *bfilter,struct bnd_boundary **blist)  
 {  
   int ret = 0;  
   assert(blist!=NULL);  
   while(*blist!=NULL) {  
     ret += bnd_apply_filter(*blist,bfilter);  
     blist++;  
   }  
   return ret;  
 }  
1030    
1031  /*--------------------------------------------------------------  /*--------------------------------------------------------------
1032      The following is some pretty aggressive simplication of the      Methods to define
1033      previously very repetitive 'method' declarations for          slv_count_solvers_*
1034      returning the numbers of various types of things in the          slv_count_master_*
     slv_system_t.  
1035  */  */
1036    
1037  /** This macro automates the declaration of the slv_count_solvers_* methods */  /** This macro automates the declaration of the slv_count_solvers_* methods */

Legend:
Removed from v.198  
changed lines
  Added in v.199

john.pye@anu.edu.au
ViewVC Help
Powered by ViewVC 1.1.22