~jdpipe/ascend/trunk-old

« back to all changes in this revision

Viewing changes to base/generic/solver/slv8.c

  • Committer: johnpye
  • Date: 2006-10-26 10:18:53 UTC
  • Revision ID: svn-v4:f15cd148-d149-4907-926e-73cf92b3ee03:trunk:908
first attempt at merging with Ben's changes on the trunk

Show diffs side-by-side

added added

removed removed

Lines of Context:
29
29
#include <utilities/ascMalloc.h>
30
30
#include <utilities/set.h>
31
31
#include <general/tm_time.h>
 
32
#include <general/mathmacros.h>
32
33
#include <utilities/mem.h>
33
34
#include <general/list.h>
34
35
#include <compiler/fractions.h>
367
368
 
368
369
        destroy_array(p)
369
370
        create_array(len,type)
370
 
        
 
371
 
371
372
        zero_vector(vec)
372
373
        copy_vector(vec1,vec2)
373
374
        prod = inner_product(vec1,vec2)
498
499
 
499
500
/**
500
501
        Calculate all of the residuals in the current block and compute
501
 
        the residual norm for block status.  
 
502
        the residual norm for block status.
502
503
 
503
504
        @return true iff calculations preceded without error.
504
505
*/
601
602
        } else {
602
603
          n =  -n;
603
604
 
604
 
          ERROR_REPORTER_START_HERE(ASC_USER_ERROR);    
 
605
          ERROR_REPORTER_START_HERE(ASC_USER_ERROR);
605
606
          FPRINTF(fp,"Variable ");
606
607
          print_var_name(fp,sys,var);
607
608
          FPRINTF(fp," has negative nominal value.\n");
1040
1041
        Reset all flags to setup a new solve.
1041
1042
        Should set sys->s.block.current_block = -1
1042
1043
        before calling.
1043
 
        
 
1044
 
1044
1045
        @TODO This is currently a HACK! Not sure if should call when done.
1045
1046
*/
1046
1047
static void conopt_initialize( slv8_system_t sys){
1523
1524
 
1524
1525
/**
1525
1526
        Perform structural analysis on the system, setting the flags in
1526
 
        status.  
 
1527
        status.
1527
1528
 
1528
1529
        The problem must be set up, the relation/variable list
1529
 
        must be non-NULL. The jacobian (linear) system must be created 
 
1530
        must be non-NULL. The jacobian (linear) system must be created
1530
1531
        and have the correct order (stored in sys->cap).  Everything else
1531
1532
        will be determined here.
1532
1533
 
1709
1710
          - Fix interface so that solvers define status messages. We
1710
1711
            should not be stuck with one standard set that all solvers
1711
1712
            must deal with.
1712
 
        
 
1713
 
1713
1714
          - Reimplement old code to detect linear coefficients and use
1714
1715
            in conopt hookup.
1715
1716
 
1816
1817
  /*
1817
1818
  for (offset = row = sys->J.reg.row.low;
1818
1819
       row <= sys->J.reg.row.high; row++) {
1819
 
        
 
1820
 
1820
1821
    rel = sys->rlist[mtx_row_to_org(sys->J.mtx,row)];
1821
1822
    nominal = sys->weights.vec[row];
1822
1823
    * fv[row-offset] = sys->residuals.vec[row];* * already scaled *
2087
2088
      var_set_value(var, value);
2088
2089
    }
2089
2090
  }
2090
 
  /** 
 
2091
  /**
2091
2092
        @TODO could be more efficient when mode = 3
2092
2093
        (with future versions of CONOPT)
2093
2094
  */
2169
2170
/**
2170
2171
        COISTA Pass the solution from CONOPT to the modeler. It returns
2171
2172
        completion status
2172
 
        
 
2173
 
2173
2174
        @param modsta model status
2174
2175
        @param solsta solver status
2175
2176
        @param iter   number of iterations
2352
2353
    if (strlen(sys->p.parms[sys->con.opt_count].interface_label) == 6){
2353
2354
      if (strncmp(sys->p.parms[sys->con.opt_count].interface_label,
2354
2355
                  "R",1) == 0) {
2355
 
                name = 
 
2356
                name =
2356
2357
          strncpy(name, sys->p.parms[sys->con.opt_count].interface_label,6);
2357
2358
                *rval = sys->p.parms[sys->con.opt_count].info.r.value;
2358
2359
                sys->con.opt_count++;
2359
2360
                return 0;
2360
2361
      } else if (strncmp(sys->p.parms[sys->con.opt_count].interface_label,
2361
2362
                         "L",1) == 0) {
2362
 
                name = 
 
2363
                name =
2363
2364
                  strncpy(name,sys->p.parms[sys->con.opt_count].interface_label,6);
2364
2365
                *ival = sys->p.parms[sys->con.opt_count].info.i.value;
2365
2366
                sys->con.opt_count++;
2467
2468
            FPRINTF(ASCERR,"Variable '%s' : ",varname);
2468
2469
                ASC_FREE(varname);
2469
2470
        }else if(*COLNO == -1 ){
2470
 
            FPRINTF(ASCERR,"Relation '%s' : ",relname); 
 
2471
            FPRINTF(ASCERR,"Relation '%s' : ",relname);
2471
2472
                ASC_FREE(relname);
2472
2473
        }else{
2473
2474
            FPRINTF(ASCERR,"Variable '%s' appearing in relation '%s' : ",varname,relname);
2515
2516
  char *varname=NULL;
2516
2517
  struct rel_relation **rp;
2517
2518
  struct var_variable **vp;
2518
 
  
 
2519
 
2519
2520
  slv8_system_t sys;
2520
2521
  sys = (slv8_system_t)usrmem;
2521
 
  
 
2522
 
2522
2523
  rp=slv_get_solvers_rel_list(SERVER);
2523
2524
  vp=slv_get_solvers_var_list(SERVER);
2524
2525
  /* assumes cur = org */
2546
2547
){
2547
2548
  int32 stop, i, len;
2548
2549
  char *line[15];
2549
 
  /* should put option to make stop = *smsg or *nmsg 
 
2550
  /* should put option to make stop = *smsg or *nmsg
2550
2551
   * and option to route output
2551
2552
   */
2552
2553
  stop = *nmsg;
2599
2600
 
2600
2601
    slv8_system_t sys;
2601
2602
    sys = (slv8_system_t)usrmem;
2602
 
  
 
2603
 
2603
2604
    rp=slv_get_solvers_rel_list(SERVER);
2604
2605
    vp=slv_get_solvers_var_list(SERVER);
2605
2606
    /* assumes cur = org */
2609
2610
    vp = vp + col;
2610
2611
    relname= rel_make_name(SERVER,*rp);
2611
2612
    varname= var_make_name(SERVER,*vp);
2612
 
  
 
2613
 
2613
2614
    FPRINTF(stderr,"ERROR: Infeasible specification discovered at:\n");
2614
2615
    FPRINTF(stderr,"     relation: %s\n          residual: %g\n",
2615
2616
      relname, (*resid)/sys->weights.vec[row]);
2616
2617
    FPRINTF(stderr,"     variable: %s\n          value: %g\n",
2617
2618
      varname, (*value)*sys->nominals.vec[col]);
2618
 
    
 
2619
 
2619
2620
    if (relname) {
2620
2621
      ascfree(relname);
2621
2622
    }
2769
2770
        sys->con.nz = num_jacobian_nonzeros(sys, &(sys->con.maxrow));
2770
2771
        COIDEF_NumNZ(cntvect, &(sys->con.nz));
2771
2772
        COIDEF_NumNlNz(cntvect, &(sys->con.nz));
2772
 
        
 
2773
 
2773
2774
        sys->con.base = 0;
2774
2775
        COIDEF_Base(cntvect,&(sys->con.base));
2775
2776
    COIDEF_ErrLim(cntvect, &(DOMLIM));
2788
2789
 
2789
2790
        temp = 0;
2790
2791
        COIDEF_StdOut(cntvect, &temp);
2791
 
        
 
2792
 
2792
2793
        COIDEF_ReadMatrix(cntvect, &slv8_conopt_readmatrix);
2793
2794
        COIDEF_FDEval(cntvect, &slv8_conopt_fdeval);
2794
2795
        COIDEF_Option(cntvect, &slv8_conopt_option);
2924
2925
    ERROR_REPORTER_HERE(ASC_PROG_ERR,"Not ready to solve.");
2925
2926
    return;
2926
2927
  }
2927
 
  
 
2928
 
2928
2929
  if (sys->s.block.current_block==-1) {
2929
2930
    conopt_initialize(sys);
2930
2931
    sys->s.converged = sys->con.optimized;