/[ascend]/trunk/tcltk98/generic/interface/MtxProc.c
ViewVC logotype

Diff of /trunk/tcltk98/generic/interface/MtxProc.c

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

revision 230 by johnpye, Mon Dec 19 06:12:40 2005 UTC revision 231 by johnpye, Sun Jan 29 14:15:44 2006 UTC
# Line 1  Line 1 
1  /*  /*
2   *  MtxProc.c   *  Incidence matrix routines
3   *  by Kirk Abbott and Ben Allan   *  by Kirk Abbott and Ben Allan
4   *  Created: 1/94   *  Created: 1/94
  *  Version: $Revision: 1.29 $  
  *  Version control file: $RCSfile: MtxProc.c,v $  
  *  Date last modified: $Date: 2003/08/23 18:43:07 $  
  *  Last modified by: $Author: ballan $  
5   *   *
6   *  This file is part of the ASCEND Tcl/Tk interface   *  This file is part of the ASCEND Tcl/Tk interface
7   *   *
# Line 46  Line 42 
42  #include "compiler/instance_enum.h"  #include "compiler/instance_enum.h"
43  #include "compiler/symtab.h"  #include "compiler/symtab.h"
44  #include "compiler/instance_name.h"  #include "compiler/instance_name.h"
45  #include "solver/slv_types.h"  
46  #include "solver/calc.h"  #include "solver/incidence.h"
47  #include "solver/mtx.h"  
 #include "solver/var.h"  
 #include "solver/rel.h"  
 #include "solver/discrete.h"  
 #include "solver/conditional.h"  
 #include "solver/logrel.h"  
 #include "solver/bnd.h"  
 #include "solver/relman.h"  
 #include "solver/slv_common.h"  
 #include "solver/linsol.h"  
 #include "solver/linsolqr.h"  
 #include "solver/slv_client.h"  
 #include "solver/slv_interface.h"  
 #include "solver/system.h"  
48  #include "compiler/types.h"  #include "compiler/types.h"
49  #include "compiler/functype.h"  #include "compiler/functype.h"
50  #include "compiler/func.h"  #include "compiler/func.h"
51  #include "compiler/extfunc.h"  #include "compiler/extfunc.h"
52  #include "compiler/extcall.h"  #include "compiler/extcall.h"
53  #include "compiler/relation_type.h"  #include "compiler/relation_type.h"
54    
55  #include "interface/old_utils.h"  #include "interface/old_utils.h"
56  #include "interface/HelpProc.h"  #include "interface/HelpProc.h"
57  #include "interface/Qlfdid.h"  #include "interface/Qlfdid.h"
# Line 76  Line 60 
60  #include "interface/HelpProc.h"  #include "interface/HelpProc.h"
61  #include "interface/SolverGlobals.h"  #include "interface/SolverGlobals.h"
62    
63    
64  #ifndef lint  #ifndef lint
65  static CONST char MtxProcID[] = "$Id: MtxProc.c,v 1.29 2003/08/23 18:43:07 ballan Exp $";  static CONST char MtxProcID[] = "$Id: MtxProc.c,v 1.29 2003/08/23 18:43:07 ballan Exp $";
66  #endif  #endif
# Line 88  static CONST char MtxProcID[] = "$Id: Mt Line 73  static CONST char MtxProcID[] = "$Id: Mt
73  #define QLFDID_LENGTH 1023  #define QLFDID_LENGTH 1023
74  #define MP_DEBUG TRUE  #define MP_DEBUG TRUE
75    
76    /* Some code moved to solver/incidence.h -- JP, 30 Jan 06 */
77    
78  static int GPI_Error(ClientData cdata, Tcl_Interp *interp,  static int GPI_Error(ClientData cdata, Tcl_Interp *interp,
79                       int argc, CONST84 char *argv[])                       int argc, CONST84 char *argv[])
80  {  {
81    (void)cdata;    /* stop gcc whine about unused parameter */    /* stop gcc whine about unused parameters */
82    (void)argc;     /* stop gcc whine about unused parameter */    (void)cdata;
83    (void)argv;     /* stop gcc whine about unused parameter */    (void)argc;
84      (void)argv;
85    
86    Tcl_ResetResult(interp);    Tcl_ResetResult(interp);
87    Tcl_SetResult(interp, "Error in args to mtx_gui_plot_incidence", TCL_STATIC);    Tcl_SetResult(interp, "Error in args to mtx_gui_plot_incidence", TCL_STATIC);
# Line 110  static int GPI_Error(ClientData cdata, T Line 98  static int GPI_Error(ClientData cdata, T
98    return TCL_ERROR;    return TCL_ERROR;
99  }  }
100    
 struct mem_mine {  
   unsigned int pr2e :1; /* the next 5 will be set 1 if we */  
   unsigned int e2pr :1; /* should deallocate, and 0 if not */  
   unsigned int pc2v :1;  
   unsigned int v2pc :1;  
   unsigned int vfixed :1;  
 };  
 struct mplotvars {  
   int nprow; /* number of plotted rows  (== neqn always for now) */  
   int neqn; /* number of relations. orgrows 0-neqns are relations */  
   int npcol; /* number of plotted columns (== nfakevar) */  
   int nvar; /* number of variables. orgcols 0-nvars-1 are variables */  
   int nfakevar; /* nvar -nnincident + nslack (currently always == npcol) */  
   struct mem_mine own;  
   int *pr2e; /* len nprow */ /* plot row to eqn id */  
   int *e2pr; /* len neqn */ /* eqn id to plot row */  
   int *pc2v; /* len npcol */ /* plot column to var org col */  
   int *v2pc; /* len nvar */ /* var org col to plot col */  
   char *vfixed; /* len nvar */ /* fixed flags by var org col */  
   struct var_variable **vlist;  
   struct rel_relation **rlist;  
 };  
   
 /* fill in an mplotvars struct */  
 /* return is 0 if ok, 1 otherwise */  
 /* this function is in charge of setting the layout that will appear  
    in the canvas (row and column ordering). right now it is doing  
    its own arrangement based on the mtx structure associated with  
    the solver. Eventually it would be much better if the solvers  
    provided the display orderings themselves.  
    Also this does a 1time query of all the var fixed flags.  
   
   6/96 baa. THIS FUNCTION NEEDS TO BE REWRITTEN OR DONE AWAY WITH  
   IN FAVOR OF JUST USING THE SOLVERS VAR/REL LIST ORDERINGS SINCE  
   THE SOLVERS CAN NOW REORDER THESE LISTS WE DON'T NEED TO MESS  
   WITH LOOKING AT THEIR MATRICES DIRECTLY. go go gadget abstraction  
   boundary.  
   
   10/96. Done the note of 6/96.  
   Where previously we looked up a permutation on the mtx,  
   we now assume that the solver_*_list from sys is in the  
   desired order.  
   Probably that means some or all of the machinery here is  
   irrelevant.  
   
   1/97 vrr. Modified to plot only active variables and  
   relations.  
   
 */  
 static int Fill_GPI_Plot_Data(struct mplotvars *pd, slv_system_t sys)  
 {  
   int32 mord=-1, row,col,var,rel,plrow,plcol,uninclow;  
   var_filter_t vincident;  
   rel_filter_t ractive;  
   
   vincident.matchbits = (VAR_INCIDENT | VAR_SVAR | VAR_ACTIVE);  
   vincident.matchvalue = (VAR_INCIDENT | VAR_SVAR | VAR_ACTIVE );  
   
   ractive.matchbits = (REL_ACTIVE);  
   ractive.matchvalue = (REL_ACTIVE );  
   
   if (ISNULL(sys) || ISNULL(pd)) {  
     FPRINTF(stderr,"Fill_GPI_Plot_Data called with NULL!\n");  
     return 1;  
   }  
   
   pd->vlist = slv_get_solvers_var_list(sys);  
   pd->rlist = slv_get_solvers_rel_list(sys);  
   if (pd->vlist==NULL || pd->rlist==NULL) {  
     FPRINTF(stderr,"Mtx: (Fill_GPI_Plot_Data) Nothing to plot!\n");  
     return 1;  
   }  
   pd->neqn = slv_count_solvers_rels(sys,&ractive);  
   pd->nprow = pd->neqn;  
   pd->nvar = slv_get_num_solvers_vars(sys);  
   pd->npcol = slv_count_solvers_vars(sys,&vincident);  
   pd->nfakevar = pd->npcol; /* this could change with autoslack solvers */  
   pd->pr2e = (int *)ascmalloc(sizeof(int)*(pd->nprow +1));  
   pd->e2pr = (int *)ascmalloc(sizeof(int)*(pd->neqn +1));  
   pd->pc2v = (int *)ascmalloc(sizeof(int)*(pd->npcol +1));  
   pd->v2pc = (int *)ascmalloc(sizeof(int)*(pd->nvar +1));  
   pd->vfixed = (char *)asccalloc((pd->nvar +1),sizeof(char));  
   pd->own.pr2e = 1;  
   pd->own.e2pr = 1;  
   pd->own.pc2v = 1;  
   pd->own.v2pc = 1;  
   pd->own.vfixed = 1;  
   if ( ISNULL(pd->pr2e) || ISNULL(pd->e2pr) ||  
        ISNULL(pd->pc2v) || ISNULL(pd->v2pc) ||  
        ISNULL(pd->vfixed) ) {  
     FPRINTF(stderr,"Mtx: (Fill_GPI_Plot_Data) Insufficient memory.\n");  
     return 1;  
   }  
   mord =  MAX(pd->neqn,pd->nvar);  
   /* fix up row permutations */  
   plrow=plcol=-1;  
   uninclow=pd->neqn; /* set lowwater mark for unincluded eqns */  
   for (row=0;row<mord;row++) {  
     rel = row;  
     if (rel < pd->neqn) {  
       if (rel_included(pd->rlist[rel]) && rel_active(pd->rlist[rel])) {  
         plrow++;  
         pd->pr2e[plrow] = rel;  
         pd->e2pr[rel] = plrow;  
       } else {  
         uninclow--;  
         pd->pr2e[uninclow] = rel;  
         pd->e2pr[rel] = uninclow;  
       }  
     } /* else skip this row: it is nothing */  
   }  
   for (col = 0; col < mord; col++) {  
     var = col;  
     if (var < pd->nvar) {  
       /* set fixed flag vector whether incident or not */  
       if (var_fixed(pd->vlist[var])) {  
         pd->vfixed[var]=1;  
       }  
       if (var_incident(pd->vlist[var]) && var_active(pd->vlist[var])) {  
         plcol++;  
         pd->pc2v[plcol] = var;  
         pd->v2pc[var] = plcol;  
       } else {  
         /* nonincident vars dont get plot cols */  
         pd->v2pc[var] = -1;  /* be safe if someone asks */  
       }  
     } /* else skip this col: it is nothing */  
   }  
   return 0;  
 }  
   
 /* free memory in an mplotvars struct, if it is our memory */  
 static void Empty_GPI_Plot_Data(struct mplotvars *pd) {  
   if (NOTNULL(pd)) {  
     if (pd->own.pr2e)   {ascfree(pd->pr2e); pd->pr2e=NULL;}  
     if (pd->own.e2pr)   {ascfree(pd->e2pr); pd->e2pr=NULL;}  
     if (pd->own.pc2v)   {ascfree(pd->pc2v); pd->pc2v=NULL;}  
     if (pd->own.v2pc)   {ascfree(pd->v2pc); pd->v2pc=NULL;}  
     if (pd->own.vfixed) {ascfree(pd->vfixed); pd->vfixed=NULL;}  
   }  
 }  
 int Asc_MtxGUIPlotIncidence(ClientData cdata, Tcl_Interp *interp,  
                            int argc, CONST84 char *argv[])  
 {  
101  /*  /*
102  TCL: mtx_gui_plot_incidence <sf xoff yoff cname bmfg bmbg ra ca va ea>\n");  TCL: mtx_gui_plot_incidence <sf xoff yoff cname bmfg bmbg ra ca va ea>\n");
103  WARNING: If you mess with this arg list, update the SET_PLOT_STRING macro  WARNING: If you mess with this arg list, update the SET_PLOT_STRING macro
104           below.           below.rel_incidence_list
105  */  */
106    int Asc_MtxGUIPlotIncidence(ClientData cdata, Tcl_Interp *interp,
107                               int argc, CONST84 char *argv[])
108    {
109    
110    int sf,xoff,yoff,status,i,j,x,y,vndx;    int sf,xoff,yoff,status,i,j,x,y,vndx;
111    Tk_Window tkcanwin, tkwin;    Tk_Window tkcanwin, tkwin;
112    slv_system_t sys;    slv_system_t sys;
113    struct mplotvars pd;    incidence_vars_t pd;
114    struct rel_relation *rel;    struct rel_relation *rel;
115    const struct var_variable **vp;    const struct var_variable **vp;
116    char numstring[80],*plotstring;    char numstring[80],*plotstring;
# Line 321  WARNING: If you mess with this arg list, Line 169  WARNING: If you mess with this arg list,
169      return TCL_ERROR;      return TCL_ERROR;
170    }    }
171  */  */
172    if (Fill_GPI_Plot_Data(&pd,sys)) {    if (build_incidence_data(sys,&pd)) {
173      FPRINTF(stderr,"mtx_gui_plot_incidence: error calculating grid\n");      FPRINTF(stderr,"mtx_gui_plot_incidence: error calculating grid\n");
174      Tcl_SetResult(interp, "mtx_gui_plot_incidence: C plot calculation error",      Tcl_SetResult(interp, "mtx_gui_plot_incidence: C plot calculation error",
175                    TCL_STATIC);                    TCL_STATIC);
176      Empty_GPI_Plot_Data(&pd);      free_incidence_data(&pd);
177      return TCL_ERROR;      return TCL_ERROR;
178    }    }
179  #define MAX_BM_NAME_LEN 60  #define MAX_BM_NAME_LEN 60
# Line 364  sprintf(plotstring, \ Line 212  sprintf(plotstring, \
212            }            }
213            if (status==TCL_ERROR) {            if (status==TCL_ERROR) {
214            FPRINTF(stderr,"Error plotting x%d y%d with:\n%s\n",x,y,plotstring);            FPRINTF(stderr,"Error plotting x%d y%d with:\n%s\n",x,y,plotstring);
215              Empty_GPI_Plot_Data(&pd);              free_incidence_data(&pd);
216              return status;              return status;
217            }            }
218          }          }
# Line 386  sprintf(plotstring, \ Line 234  sprintf(plotstring, \
234                if (status==TCL_ERROR) {                if (status==TCL_ERROR) {
235                  FPRINTF(stderr,"Error plotting x%d y%d with:\n%s\n",                  FPRINTF(stderr,"Error plotting x%d y%d with:\n%s\n",
236                    x,y,plotstring);                    x,y,plotstring);
237                  Empty_GPI_Plot_Data(&pd);                  free_incidence_data(&pd);
238                  return status;                  return status;
239                }                }
240              }              }
# Line 450  sprintf(plotstring, \ Line 298  sprintf(plotstring, \
298      Tcl_SetVar2(interp,argv[10],plotstring,numstring, TCL_GLOBAL_ONLY);      Tcl_SetVar2(interp,argv[10],plotstring,numstring, TCL_GLOBAL_ONLY);
299    }    }
300    
301    Empty_GPI_Plot_Data(&pd);    free_incidence_data(&pd);
302    Tcl_ResetResult(interp);    Tcl_ResetResult(interp);
303    ascfree(plotstring);    ascfree(plotstring);
304    return TCL_OK;    return TCL_OK;

Legend:
Removed from v.230  
changed lines
  Added in v.231

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