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

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

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

revision 1067 by johnpye, Thu Oct 26 10:18:53 2006 UTC revision 1068 by johnpye, Mon Jan 8 04:45:47 2007 UTC
# Line 799  static int32 slv9a_dof_changed(slv9a_sys Line 799  static int32 slv9a_dof_changed(slv9a_sys
799  }  }
800    
801    
802  static void reset_cost(struct slv_block_cost *cost,int32 costsize)  static void reset_cost(struct slv_block_cost *cost,int32 costsize){
 {  
803    int32 ind;    int32 ind;
804    for( ind = 0; ind < costsize; ++ind ) {    for( ind = 0; ind < costsize; ++ind ) {
805      cost[ind].size = 0;      cost[ind].size = 0;
# Line 815  static void reset_cost(struct slv_block_ Line 814  static void reset_cost(struct slv_block_
814  }  }
815    
816    
817  static void slv9a_presolve(slv_system_t server, SlvClientToken asys)  static int slv9a_presolve(slv_system_t server, SlvClientToken asys){
 {  
818    struct dis_discrete **dvp;    struct dis_discrete **dvp;
819    struct logrel_relation **lrp;    struct logrel_relation **lrp;
820    int32 cap, ind;    int32 cap, ind;
# Line 827  static void slv9a_presolve(slv_system_t Line 825  static void slv9a_presolve(slv_system_t
825    iteration_begins(sys);    iteration_begins(sys);
826    check_system(sys);    check_system(sys);
827    if( sys->vlist == NULL ) {    if( sys->vlist == NULL ) {
828      FPRINTF(ASCERR,"ERROR:  (slv9a) slv9a_presolve\n");      ERROR_REPORTER_HERE(ASC_PROG_ERR,"Discrete Variable list was never set.");
829      FPRINTF(ASCERR,"        Discrete Variable list was never set.\n");      return 1;
     return;  
830    }    }
831    if( sys->rlist == NULL ) {    if( sys->rlist == NULL ) {
832      FPRINTF(ASCERR,"ERROR:  (slv9a) slv9a_presolve\n");      ERROR_REPORTER_HERE(ASC_PROG_ERR,"Logical Relation list was never set.");
833      FPRINTF(ASCERR,"        Logical Relation list was never set.\n");      return 2;
     return;  
834    }    }
835    
836    if(sys->presolved > 0) { /* system has been presolved before */    if(sys->presolved > 0) { /* system has been presolved before */
# Line 895  static void slv9a_presolve(slv_system_t Line 891  static void slv9a_presolve(slv_system_t
891    update_status(sys);    update_status(sys);
892    iteration_ends(sys);    iteration_ends(sys);
893    sys->s.cost[sys->s.block.number_of].time=sys->s.cpu_elapsed;    sys->s.cost[sys->s.block.number_of].time=sys->s.cpu_elapsed;
894      return 0;
895  }  }
896    
897    static int slv9a_resolve(slv_system_t server, SlvClientToken asys){
 static void slv9a_resolve(slv_system_t server, SlvClientToken asys)  
 {  
898    struct dis_discrete **dvp;    struct dis_discrete **dvp;
899    struct logrel_relation **lrp;    struct logrel_relation **lrp;
900    slv9a_system_t sys;    slv9a_system_t sys;
# Line 929  static void slv9a_resolve(slv_system_t s Line 924  static void slv9a_resolve(slv_system_t s
924    sys->s.block.iteration = 0;    sys->s.block.iteration = 0;
925    
926    update_status(sys);    update_status(sys);
927      return 0;
928  }  }
929    
930    
# Line 939  static void slv9a_resolve(slv_system_t s Line 935  static void slv9a_resolve(slv_system_t s
935   * required for conditional analysis. The use of the structure instance   * required for conditional analysis. The use of the structure instance
936   * in this function is an insanity, but we stick with it by now.   * in this function is an insanity, but we stick with it by now.
937   */   */
938  static void slv9a_iterate(slv_system_t server, SlvClientToken asys)  static int slv9a_iterate(slv_system_t server, SlvClientToken asys){
 {  
939    slv9a_system_t sys;    slv9a_system_t sys;
940    struct bnd_boundary **blist;    struct bnd_boundary **blist;
941    struct bnd_boundary *cur_bnd;    struct bnd_boundary *cur_bnd;
# Line 959  static void slv9a_iterate(slv_system_t s Line 954  static void slv9a_iterate(slv_system_t s
954    sys = SLV9A(asys);    sys = SLV9A(asys);
955    mif = MIF(sys);    mif = MIF(sys);
956    lif = LIF(sys);    lif = LIF(sys);
957    if (server == NULL || sys==NULL) return;    if(server == NULL || sys==NULL)return 1;
958    if (check_system(SLV9A(sys))) return;    if(check_system(SLV9A(sys)))return 2;
959    if( !sys->s.ready_to_solve ) {    if(!sys->s.ready_to_solve){
960      FPRINTF(ASCERR,"ERROR:  (slv9a) slv9a_iterate\n");      ERROR_REPORTER_HERE(ASC_PROG_ERR,"Not ready to solve.");
961      FPRINTF(ASCERR,"        Not ready to solve.\n");      return 3;
     return;  
962    }    }
963    
964    /*    /*
965     * To change truth values of some boundaries      To change truth values of some boundaries
966     */    */
967    blist = sys->blist;    blist = sys->blist;
968    if (blist == NULL && PERTURB_BOUNDARY) {    if (blist == NULL && PERTURB_BOUNDARY) {
969      FPRINTF(lif,"No boundaries in the problem. The solver cannot\n");      ERROR_REPORTER_HERE(ASC_USER_ERROR,"No boundaries in the problem."
970      FPRINTF(lif,"work in perturbation mode \n");          " The solver cannot work in perturbation mode."
971        );
972      sys->s.ready_to_solve = FALSE;      sys->s.ready_to_solve = FALSE;
973      iteration_ends(sys);      iteration_ends(sys);
974      return;      return 4;
975    }    }
976    
977    /*    /*
978     * Solution process begins      Solution process begins
979     */    */
980    if (sys->s.block.current_block==-1) {    if(sys->s.block.current_block==-1) {
981      find_next_unconverged_block(sys);      find_next_unconverged_block(sys);
982      update_status(sys);      update_status(sys);
983      return;      return 0; /* is that right? */
984    }    }
985    
986    /*    /*
987     * finding the list of boundaries to be perturbed      finding the list of boundaries to be perturbed
988     */    */
989    per_insts = NULL;    per_insts = NULL;
990    if (PERTURB_BOUNDARY) {    if(PERTURB_BOUNDARY) {
991      numbnds = slv_get_num_solvers_bnds(server);      numbnds = slv_get_num_solvers_bnds(server);
992      bfilter.matchbits = (BND_PERTURB);      bfilter.matchbits = (BND_PERTURB);
993      bfilter.matchvalue = (BND_PERTURB);      bfilter.matchvalue = (BND_PERTURB);
994      numper = slv_count_solvers_bnds(server,&bfilter);      numper = slv_count_solvers_bnds(server,&bfilter);
995      if (numper != 0) {      if(numper != 0) {
996        per_insts = gl_create(numper);        per_insts = gl_create(numper);
997        for (nb=0; nb <numbnds; nb++){        for (nb=0; nb <numbnds; nb++){
998      cur_bnd = blist[nb];          cur_bnd = blist[nb];
999          if(bnd_perturb(cur_bnd)) {          if(bnd_perturb(cur_bnd)) {
1000        if(bnd_kind(cur_bnd) == e_bnd_rel) {        if(bnd_kind(cur_bnd) == e_bnd_rel) {
1001              rel = bnd_rel(bnd_real_cond(cur_bnd));              rel = bnd_rel(bnd_real_cond(cur_bnd));
1002              i = (struct Instance *)rel_instance(rel);              i = (struct Instance *)rel_instance(rel);
1003          gl_append_ptr(per_insts,i);          gl_append_ptr(per_insts,i);
1004        } else {        }else{
1005          if (bnd_kind(cur_bnd) == e_bnd_logrel) {          if (bnd_kind(cur_bnd) == e_bnd_logrel) {
1006                logrel = bnd_logrel(bnd_log_cond(cur_bnd));                logrel = bnd_logrel(bnd_log_cond(cur_bnd));
1007                i = (struct Instance *)logrel_instance(logrel);                i = (struct Instance *)logrel_instance(logrel);
# Line 1018  static void slv9a_iterate(slv_system_t s Line 1013  static void slv9a_iterate(slv_system_t s
1013      }      }
1014    }    }
1015    
   
1016    iteration_begins(sys);    iteration_begins(sys);
1017    
1018    /*    /*
1019     *  Attempt direct solve if appropriate      Attempt direct solve if appropriate
1020     */    */
1021    if( sys->s.block.current_size == 1 ) {    if( sys->s.block.current_size == 1 ) {
1022      struct dis_discrete *dvar;      struct dis_discrete *dvar;
1023      struct logrel_relation *lrel;      struct logrel_relation *lrel;
# Line 1055  static void slv9a_iterate(slv_system_t s Line 1049  static void slv9a_iterate(slv_system_t s
1049          FPRINTF(lif,"Unable to directly solve a logical relation.\n");          FPRINTF(lif,"Unable to directly solve a logical relation.\n");
1050        }        }
1051        FPRINTF(lif,"Bad discrete variable or logrel\n");        FPRINTF(lif,"Bad discrete variable or logrel\n");
1052        return;        return 5;
1053      case 1:      case 1:
1054        if (SHOW_LESS_IMPT) {        if (SHOW_LESS_IMPT) {
1055          FPRINTF(lif,"Directly solved.\n");          FPRINTF(lif,"Directly solved.\n");
# Line 1063  static void slv9a_iterate(slv_system_t s Line 1057  static void slv9a_iterate(slv_system_t s
1057        iteration_ends(sys);        iteration_ends(sys);
1058        find_next_unconverged_block(sys);        find_next_unconverged_block(sys);
1059        update_status(sys);        update_status(sys);
1060        return;        return 0;
1061      case 2:      case 2:
1062        if (SHOW_LESS_IMPT) {        if (SHOW_LESS_IMPT) {
1063          FPRINTF(lif,"Directly solved.\n");          FPRINTF(lif,"Directly solved.\n");
1064        }        }
1065        sys->s.inconsistent = TRUE;        sys->s.inconsistent = TRUE;
1066        FPRINTF(mif,"Multiple solution exists for the discrete variable:\n");        ERROR_REPORTER_START_HERE(ASC_USER_ERROR);
1067        print_dis_name(mif,sys,dvar); PUTC('\n',mif);        FPRINTF(ASCERR,"Multiple solution exists for the discrete variable '");
1068        FPRINTF(mif,"when solving the logical relation:\n");        print_dis_name(ASCERR,sys,dvar);
1069        print_logrel_name(mif,sys,lrel); PUTC('\n',mif);        FPRINTF(ASCERR,"' when solving the logical relation '");
1070          print_logrel_name(ASCERR,sys,lrel);
1071          FPRINTF(ASCERR,"'.");
1072          error_reporter_end_flush();
1073        iteration_ends(sys);        iteration_ends(sys);
1074        update_status(sys);        update_status(sys);
1075        return;        return 6;
1076      case -1:      case -1:
1077        sys->s.inconsistent = TRUE;        sys->s.inconsistent = TRUE;
1078        FPRINTF(mif,"No solution exists for the discrete variable:\n");        ERROR_REPORTER_START_HERE(ASC_USER_ERROR);
1079        print_dis_name(mif,sys,dvar); PUTC('\n',mif);        FPRINTF(ASCERR,"No solution exists for the discrete variable '");
1080        FPRINTF(mif,"when solving the logical relation:\n");        print_dis_name(ASCERR,sys,dvar);
1081        print_logrel_name(mif,sys,lrel); PUTC('\n',mif);        FPRINTF(ASCERR,"' when solving the logical relation '");
1082          print_logrel_name(ASCERR,sys,lrel);
1083          FPRINTF(ASCERR,"'.");
1084          error_reporter_end_flush();
1085        iteration_ends(sys);        iteration_ends(sys);
1086        update_status(sys);        update_status(sys);
1087        return;        return 7;
1088      }      }
1089    } else {    } else {
1090      FPRINTF(lif,"block number = %d \n",sys->s.block.current_block);      FPRINTF(lif,"block number = %d \n",sys->s.block.current_block);
# Line 1102  static void slv9a_iterate(slv_system_t s Line 1102  static void slv9a_iterate(slv_system_t s
1102        debug_out_logrel_residuals(LIF(sys), sys);        debug_out_logrel_residuals(LIF(sys), sys);
1103        FPRINTF(ASCERR,"********************************************\n");        FPRINTF(ASCERR,"********************************************\n");
1104  #endif /* DEBUG */  #endif /* DEBUG */
1105      return 0;
1106  }  }
1107    
1108    
1109  static void slv9a_solve(slv_system_t server, SlvClientToken asys)  static int slv9a_solve(slv_system_t server, SlvClientToken asys){
 {  
1110    slv9a_system_t sys;    slv9a_system_t sys;
1111      int err = 0;
1112    sys = SLV9A(asys);    sys = SLV9A(asys);
1113    if (server == NULL || sys==NULL) return;    if (server == NULL || sys==NULL) return -1;
1114    if (check_system(sys)) return;    if (check_system(sys)) return -2;
1115    while( sys->s.ready_to_solve ) slv9a_iterate(server,sys);    while( sys->s.ready_to_solve )err |= slv9a_iterate(server,sys);
1116      return err;
1117  }  }
1118    
1119    

Legend:
Removed from v.1067  
changed lines
  Added in v.1068

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