/[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 199 by johnpye, Sat Jan 21 02:23:55 2006 UTC revision 200 by johnpye, Sat Jan 21 03:45:15 2006 UTC
# Line 103  struct slv_system_structure { Line 103  struct slv_system_structure {
103     * (e_maximize,e_minimize). this list will include the first included obj.     * (e_maximize,e_minimize). this list will include the first included obj.
104     */     */
105    struct {    struct {
106      int snum;           /* length of the solver list */      int snum;           /* length of the solver list */
107      int mnum;           /* length of the master list */      int mnum;           /* length of the master list */
108      struct var_variable **solver;      struct var_variable **solver;
109      struct var_variable **master;      struct var_variable **master;
110        struct var_variable *buf;
111    } vars;    } vars;
112    
113    struct {    struct {
# Line 114  struct slv_system_structure { Line 115  struct slv_system_structure {
115      int mnum;                  /* length of the master list */      int mnum;                  /* length of the master list */
116      struct dis_discrete **solver;      struct dis_discrete **solver;
117      struct dis_discrete **master;      struct dis_discrete **master;
118        struct dis_discrete *buf;
119    } dvars;    } dvars;
120    
121    struct {    struct {
# Line 121  struct slv_system_structure { Line 123  struct slv_system_structure {
123      int mnum;           /* length of the master list */      int mnum;           /* length of the master list */
124      struct rel_relation **solver;      struct rel_relation **solver;
125      struct rel_relation **master;      struct rel_relation **master;
126        struct rel_relation *buf;
127    } rels;    } rels;
128    
129    struct {    struct {
# Line 128  struct slv_system_structure { Line 131  struct slv_system_structure {
131      int mnum;      int mnum;
132      struct rel_relation **solver;      struct rel_relation **solver;
133      struct rel_relation **master;      struct rel_relation **master;
134        struct rel_relation *buf;
135    } objs;    } objs;
136    
137    struct {    struct {
# Line 135  struct slv_system_structure { Line 139  struct slv_system_structure {
139      int mnum;           /* length of the master list */      int mnum;           /* length of the master list */
140      struct rel_relation **solver;      struct rel_relation **solver;
141      struct rel_relation **master;      struct rel_relation **master;
142        struct rel_relation *buf;
143    } condrels;    } condrels;
144    
145    struct {    struct {
# Line 142  struct slv_system_structure { Line 147  struct slv_system_structure {
147      int mnum;           /* length of the master list */      int mnum;           /* length of the master list */
148      struct logrel_relation **solver;      struct logrel_relation **solver;
149      struct logrel_relation **master;      struct logrel_relation **master;
150        struct logrel_relation *buf;
151    } logrels;    } logrels;
152    
153    struct {    struct {
# Line 149  struct slv_system_structure { Line 155  struct slv_system_structure {
155      int mnum;           /* length of the master list */      int mnum;           /* length of the master list */
156      struct logrel_relation **solver;      struct logrel_relation **solver;
157      struct logrel_relation **master;      struct logrel_relation **master;
158        struct logrel_relation *buf;
159    } condlogrels;    } condlogrels;
160    
161    struct {    struct {
# Line 156  struct slv_system_structure { Line 163  struct slv_system_structure {
163      int mnum;           /* length of the master list */      int mnum;           /* length of the master list */
164      struct w_when **solver;      struct w_when **solver;
165      struct w_when **master;      struct w_when **master;
166        struct w_when *buf;
167    } whens;    } whens;
168    
169    struct {    struct {
# Line 163  struct slv_system_structure { Line 171  struct slv_system_structure {
171      int mnum;           /* length of the master list */      int mnum;           /* length of the master list */
172      struct bnd_boundary **solver;      struct bnd_boundary **solver;
173      struct bnd_boundary **master;      struct bnd_boundary **master;
174        struct bnd_boundary *buf;
175    } bnds;    } bnds;
176    
177    struct {    struct {
# Line 170  struct slv_system_structure { Line 179  struct slv_system_structure {
179      int mnum;      int mnum;
180      struct var_variable **solver;      struct var_variable **solver;
181      struct var_variable **master;      struct var_variable **master;
182        struct var_variable *buf;
183    } pars;    } pars;
184    
185    struct {    struct {
# Line 177  struct slv_system_structure { Line 187  struct slv_system_structure {
187      int mnum;      int mnum;
188      struct var_variable **solver;      struct var_variable **solver;
189      struct var_variable **master;      struct var_variable **master;
190        struct var_variable *buf;
191    } unattached;    } unattached;
192    
193    struct {    struct {
# Line 184  struct slv_system_structure { Line 195  struct slv_system_structure {
195      int mnum;      int mnum;
196      struct dis_discrete **solver;      struct dis_discrete **solver;
197      struct dis_discrete **master;      struct dis_discrete **master;
198        struct dis_discrete *buf;
199    } disunatt;    } disunatt;
200    
201    /* the data that follows is for internal consumption only. */    /* the data that follows is for internal consumption only. */
# Line 197  struct slv_system_structure { Line 209  struct slv_system_structure {
209    struct gl_list_t *symbollist; /* list of symbol values struct used to */    struct gl_list_t *symbollist; /* list of symbol values struct used to */
210                                  /* assign an integer value to a symbol value */                                  /* assign an integer value to a symbol value */
211    struct {    struct {
     /** @TODO move the 'bufs' into the above structs (disunatt, etc) */  
     struct var_variable *ubuf; /* data space for unclassified real ATOMs */  
     struct dis_discrete *udbuf; /* data space for unclassified discrete ATOM */  
     struct var_variable *pbuf; /* data space for real ATOMs that are pars */  
     struct var_variable *vbuf; /* data space for real ATOMs that are vars */  
     struct dis_discrete *dbuf; /* data space for discrete ATOMs that are vars*/  
     struct rel_relation *rbuf; /* data space for real rel constraints */  
     struct rel_relation *cbuf; /* data space for conditional rel */  
     struct rel_relation *obuf; /* data space for real relation objectives */  
     struct logrel_relation *lbuf; /* data space for logical rel  */  
     struct logrel_relation *clbuf; /* data space for conditional logical rel*/  
     struct w_when *wbuf;          /* data space for whens */  
     struct bnd_boundary *bbuf;    /* data space for boundaries */  
212      struct var_variable **incidence; /* all relation incidence list memory */      struct var_variable **incidence; /* all relation incidence list memory */
213      struct rel_relation **varincidence; /* all variable incidence list memory */      struct rel_relation **varincidence; /* all variable incidence list memory */
214      struct dis_discrete **logincidence; /* all logrel incidence list memory */      struct dis_discrete **logincidence; /* all logrel incidence list memory */
# Line 354  unsigned slv_serial_id(slv_system_t sys) Line 353  unsigned slv_serial_id(slv_system_t sys)
353  /*----------------------------------------------------  /*----------------------------------------------------
354      destructors      destructors
355  */  */
 static  
 void slv_destroy_dvar_buffer(struct dis_discrete *dbuf)  
 {  
   int c;  
   struct dis_discrete *cur_dis;  
   for (c=0;c<g_number_of_dvars;c++){  
     cur_dis = &(dbuf[c]);  
     dis_destroy(cur_dis);  
   }  
   ascfree(dbuf);  
 }  
356    
357  static  #define DEFINE_DESTROY_BUFFER(NAME,PROP,TYPE,DESTROY) \
358  void slv_destroy_when_buffer(struct w_when *wbuf)      static void slv_destroy_##NAME##_buffer(struct TYPE *buf){ \
359  {          int c; struct TYPE *cur; \
360    int c;          for(c=0;c<g_number_of_##PROP;c++){ \
361    struct w_when *cur_when;              cur = &(buf[c]); \
362    for (c=0;c<g_number_of_whens;c++){              DESTROY(cur); \
363      cur_when = &(wbuf[c]);          } \
364      when_destroy(cur_when);          ascfree(buf); \
365    }      }
   ascfree(wbuf);  
 }  
366    
367  static  #define DEFINE_DESTROY_BUFFERS(D) \
368  void slv_destroy_bnd_buffer(struct bnd_boundary *bbuf)      D(dvar, dvars, dis_discrete, dis_destroy) \
369  {      D(when, whens, w_when, when_destroy) \
370    int c;      D(bnd, bnds, bnd_boundary, bnd_destroy)
371    struct bnd_boundary *cur_bnd;  
372    for (c=0;c<g_number_of_bnds;c++){  DEFINE_DESTROY_BUFFERS(DEFINE_DESTROY_BUFFER)
373      cur_bnd = &(bbuf[c]);  
374      bnd_destroy(cur_bnd);  #define SLV_FREE_BUF(PROP) \
375    }      if(sys->PROP.buf !=NULL) ascfree(sys->PROP.buf); \
376    ascfree(bbuf);      sys->PROP.buf = NULL;
377  }  
378    #define SLV_FREE_BUF_GLOBAL(NAME, PROP) \
379        if (sys->PROP.buf != NULL) { \
380            slv_destroy_##NAME##_buffer(sys->PROP.buf); \
381            sys->PROP.buf = NULL; \
382        }
383    
384    #define SLV_FREE_BUFS(D,D_GLOBAL) \
385        D(vars) \
386        D(rels) \
387        D(objs) \
388        D(condrels) \
389        D(logrels) \
390        D(condlogrels) \
391        D(pars) \
392        D(unattached) \
393        D(disunatt) \
394        D_GLOBAL(dvar, dvars) \
395        D_GLOBAL(when, whens) \
396        D_GLOBAL(bnd, bnds)
397    
398    #if 0
399        /** @TODO move the 'bufs' into the above structs (disunatt, etc) */
400        struct var_variable *ubuf; /* data space for unclassified real ATOMs */
401        struct dis_discrete *udbuf; /* data space for unclassified discrete ATOM */
402        struct var_variable *pbuf; /* data space for real ATOMs that are pars */
403        struct var_variable *vbuf; /* data space for real ATOMs that are vars */
404        struct dis_discrete *dbuf; /* data space for discrete ATOMs that are vars*/
405        struct rel_relation *rbuf; /* data space for real rel constraints */
406        struct rel_relation *cbuf; /* data space for conditional rel */
407        struct rel_relation *obuf; /* data space for real relation objectives */
408        struct logrel_relation *lbuf; /* data space for logical rel  */
409        struct logrel_relation *clbuf; /* data space for conditional logical rel*/
410        struct w_when *wbuf;          /* data space for whens */
411        struct bnd_boundary *bbuf;    /* data space for boundaries */
412    #endif
413    
414    /* vars dvars rels objs condrels logrels condlogrels whens bnds pars unattached disunatt */
415    
416  int slv_destroy(slv_system_t sys)  int slv_destroy(slv_system_t sys)
417  {  {
# Line 406  int slv_destroy(slv_system_t sys) Line 429  int slv_destroy(slv_system_t sys)
429    if (ret) {    if (ret) {
430      ERROR_REPORTER_HERE(ASC_PROG_FATAL,"slv_destroy: slv_system_t 0x%p not freed.",sys);      ERROR_REPORTER_HERE(ASC_PROG_FATAL,"slv_destroy: slv_system_t 0x%p not freed.",sys);
431    } else {    } else {
432      if (sys->data.ubuf != NULL) ascfree(sys->data.ubuf);  
433      sys->data.ubuf = NULL;      SLV_FREE_BUFS(SLV_FREE_BUF, SLV_FREE_BUF_GLOBAL)
434      if (sys->data.udbuf != NULL) ascfree(sys->data.udbuf);  
     sys->data.udbuf = NULL;  
     if (sys->data.pbuf != NULL) ascfree(sys->data.pbuf);  
     sys->data.pbuf = NULL;  
     if (sys->data.vbuf != NULL) ascfree(sys->data.vbuf);  
     sys->data.vbuf = NULL;  
     if (sys->data.dbuf != NULL) {  
       slv_destroy_dvar_buffer(sys->data.dbuf);  
       sys->data.dbuf = NULL;  
     }  
     if (sys->data.rbuf != NULL) ascfree(sys->data.rbuf);  
     sys->data.rbuf = NULL;  
     if (sys->data.cbuf != NULL) ascfree(sys->data.cbuf);  
     sys->data.cbuf = NULL;  
     if (sys->data.obuf != NULL) ascfree(sys->data.obuf);  
     sys->data.obuf = NULL;  
     if (sys->data.lbuf != NULL) ascfree(sys->data.lbuf);  
     sys->data.lbuf = NULL;  
     if (sys->data.clbuf != NULL) ascfree(sys->data.clbuf);  
     sys->data.clbuf = NULL;  
     if (sys->data.wbuf != NULL) {  
       slv_destroy_when_buffer(sys->data.wbuf);  
       sys->data.wbuf = NULL;  
     }  
     if (sys->data.bbuf != NULL) {  
       slv_destroy_bnd_buffer(sys->data.bbuf);  
       sys->data.bbuf = NULL;  
     }  
435      if (sys->data.incidence != NULL) ascfree(sys->data.incidence);      if (sys->data.incidence != NULL) ascfree(sys->data.incidence);
436      sys->data.incidence = NULL;      sys->data.incidence = NULL;
437      if (sys->data.varincidence != NULL) ascfree(sys->data.varincidence);      if (sys->data.varincidence != NULL) ascfree(sys->data.varincidence);
# Line 566  DEFINE_SET_MASTER_LIST_METHODS(DEFINE_SE Line 562  DEFINE_SET_MASTER_LIST_METHODS(DEFINE_SE
562    
563  #define DEFINE_SET_BUF_METHOD(NAME,PROP,TYPE) \  #define DEFINE_SET_BUF_METHOD(NAME,PROP,TYPE) \
564      void slv_set_##NAME##_buf(slv_system_t sys, struct TYPE *PROP){ \      void slv_set_##NAME##_buf(slv_system_t sys, struct TYPE *PROP){ \
565          if(sys->data.PROP !=NULL ){ \          if(sys->PROP.buf !=NULL ){ \
566              Asc_Panic(2,"slv_set_" #NAME "_buf","bad call."); \              Asc_Panic(2,"slv_set_" #NAME "_buf","bad call."); \
567          }else{ \          }else{ \
568              sys->data.PROP = PROP; \              sys->PROP.buf = PROP; \
569          } \          } \
570      }      }
571    
572  #define DEFINE_SET_BUF_METHODS(D) \  #define DEFINE_SET_BUF_METHOD_GLOBAL(NAME,PROP,TYPE) \
573      D(var,vbuf,var_variable) \      void slv_set_##NAME##_buf(slv_system_t sys, struct TYPE *buf, int len){ \
574      D(par,pbuf,var_variable) \          if(sys->PROP.buf != NULL){ \
575      D(unattached,ubuf,var_variable) \              Asc_Panic(2,"slv_set_" #NAME "_buf","bad call."); \
576      D(disunatt,udbuf,dis_discrete) \          }else{ \
577      D(rel,rbuf,rel_relation) \              sys->PROP.buf = buf; \
578      D(condrel,cbuf,rel_relation) \              g_number_of_##PROP = len; \
579      D(obj,obuf,rel_relation) \          } \
580      D(logrel,lbuf,logrel_relation) \      }
     D(condlogrel,clbuf,logrel_relation)  
   
 DEFINE_SET_BUF_METHODS(DEFINE_SET_BUF_METHOD)  
   
 /*  
     Before the following can be placed into the above macro, the globals  
         g_number_of_dvars  
         g_number_of_whens  
         g_number_of_bnds  
     need to be eliminated. They should be entered as properties of the 'sys', presumably?  
 */  
   
 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;  
   }  
 }  
   
 void slv_set_when_buf(slv_system_t sys, struct w_when *wbuf, int len)  
 {  
   if (sys->data.wbuf !=NULL ) {  
     Asc_Panic(2,"slv_set_when_buf","bad call.");  
   } else {  
     sys->data.wbuf = wbuf;  
     g_number_of_whens = len;  
   }  
 }  
   
 void slv_set_bnd_buf(slv_system_t sys, struct bnd_boundary *bbuf, int len)  
 {  
   if (sys->data.bbuf !=NULL ) {  
     Asc_Panic(2,"slv_set_bnd_buf",  
               "bad call.");  
   } else {  
     sys->data.bbuf = bbuf;  
     g_number_of_bnds = len;  
   }  
 }  
581    
582  /*---------------------------------------------------------------*/  #define DEFINE_SET_BUF_METHODS(D, D_GLOBAL) \
583        D(var,vars,var_variable) \
584        D(par,pars,var_variable) \
585        D(unattached,unattached,var_variable) \
586        D(disunatt,disunatt,dis_discrete) \
587        D(rel,rels,rel_relation) \
588        D(condrel,condrels,rel_relation) \
589        D(obj,objs,rel_relation) \
590        D(logrel,logrels,logrel_relation) \
591        D(condlogrel,condlogrels,logrel_relation) \
592        D_GLOBAL(dvar, dvars, dis_discrete) \
593        D_GLOBAL(when, whens, w_when) \
594        D_GLOBAL(bnd,bnds,bnd_boundary)
595        
596    
597    DEFINE_SET_BUF_METHODS(DEFINE_SET_BUF_METHOD, DEFINE_SET_BUF_METHOD_GLOBAL)
598    
599    /*---------------------------------------------------------------
600        Macros to define
601            slv_set_incidence
602            slv_set_var_incidence
603            slv_set_logincidence
604    */
605    
606    #define DEFINE_SET_INCIDENCE(NAME,PROP,TYPE,SIZE) \
607        void slv_set_##NAME(slv_system_t sys, struct TYPE **inc, long s){ \
608            if(sys->data.PROP != NULL || inc == NULL){ \
609                Asc_Panic(2,"slv_set_" #NAME,"bad call"); \
610            }else{ \
611                sys->data.PROP = inc; \
612                sys->data.SIZE = s; \
613            } \
614        }
615    
616  void slv_set_incidence(slv_system_t sys, struct var_variable **incidence,long s)  #define DEFINE_SET_INCIDENCES(D) \
617  {      D(incidence, incidence, var_variable, incsize) \
618    if (sys->data.incidence !=NULL || incidence == NULL) {      D(var_incidence, varincidence, rel_relation, varincsize) \
619      Asc_Panic(2,"slv_set_incidence",      D(logincidence, logincidence, dis_discrete, incsize)
               "bad call.");  
   } else {  
     sys->data.incidence = incidence;  
     sys->data.incsize = s;  
   }  
 }  
620    
621  void slv_set_var_incidence(slv_system_t sys, struct rel_relation **varincidence,long s)  DEFINE_SET_INCIDENCES(DEFINE_SET_INCIDENCE)
 {  
   if (sys->data.varincidence !=NULL || varincidence == NULL) {  
     Asc_Panic(2,"slv_set_varincidence",  
               "bad call.");  
   } else {  
     sys->data.varincidence = varincidence;  
     sys->data.varincsize = s;  
   }  
 }  
622    
623  void slv_set_logincidence(slv_system_t sys, struct dis_discrete **logincidence,long s)  /*-------------------------------------------------------------*/
 {  
   if (sys->data.logincidence !=NULL) {  
     Asc_Panic(2,"slv_set_logincidence","bad call.");  
   } else {  
     sys->data.logincidence = logincidence;  
     sys->data.incsize = s;  
   }  
 }  
624    
625  void slv_set_extrel_list(slv_system_t sys,struct ExtRelCache **erlist,  void slv_set_extrel_list(slv_system_t sys,struct ExtRelCache **erlist,
626                           int size)                           int size)

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

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