/[ascend]/trunk/solvers/ipopt/asc_ipopt.c
ViewVC logotype

Diff of /trunk/solvers/ipopt/asc_ipopt.c

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

revision 2350 by jpye, Thu Jan 6 00:30:17 2011 UTC revision 2351 by jpye, Thu Jan 6 02:02:41 2011 UTC
# Line 257  static int32 ipopt_destroy(slv_system_t Line 257  static int32 ipopt_destroy(slv_system_t
257      slv_destroy_parms(&(sys->p));      slv_destroy_parms(&(sys->p));
258      if(sys->s.cost) ascfree(sys->s.cost);      if(sys->s.cost) ascfree(sys->s.cost);
259      ASC_FREE(sys);      ASC_FREE(sys);
260      ERROR_REPORTER_HERE(ASC_PROG_ERR,"ipopt_destroy still needs debugging");      ERROR_REPORTER_HERE(ASC_PROG_WARNING,"ipopt_destroy still needs debugging");
261      return 0;      return 0;
262  }    }  
263    
# Line 596  int ipopt_update_model(IpoptSystem *sys, Line 596  int ipopt_update_model(IpoptSystem *sys,
596      /* FIXME do we need to update any other stuff? */      /* FIXME do we need to update any other stuff? */
597      for(j = 0; j < sys->n; ++j){      for(j = 0; j < sys->n; ++j){
598          //CONSOLE_DEBUG("value of var[%d] = %g", j, x[j]);          //CONSOLE_DEBUG("value of var[%d] = %g", j, x[j]);
599              asc_assert(!isnan(x[j]));          asc_assert(!isnan(x[j]));
600          var_set_value(sys->vlist[j], x[j]);          var_set_value(sys->vlist[j], x[j]);
601      }      }
602    
# Line 652  Bool ipopt_eval_grad_f(Index n, Number* Line 652  Bool ipopt_eval_grad_f(Index n, Number*
652    
653      sys = SYS(user_data);      sys = SYS(user_data);
654    
     static var_filter_t vfilter = {  
         VAR_ACTIVE | VAR_INCIDENT | VAR_SVAR | VAR_FIXED  
         ,VAR_ACTIVE | VAR_INCIDENT | VAR_SVAR  
     };  
   
655      //CONSOLE_DEBUG("ipopt_eval_grad_f");      //CONSOLE_DEBUG("ipopt_eval_grad_f");
656    
657      asc_assert(n==sys->n);      asc_assert(n==sys->n);
# Line 752  Bool ipopt_eval_jac_g(Index n, Number* x Line 747  Bool ipopt_eval_jac_g(Index n, Number* x
747      int *variables;      int *variables;
748      double *derivatives;      double *derivatives;
749    
     static var_filter_t vfilter = {  
         VAR_ACTIVE | VAR_INCIDENT | VAR_SVAR | VAR_FIXED,  
         VAR_ACTIVE | VAR_INCIDENT | VAR_SVAR  
     };  
   
   
750      //CONSOLE_DEBUG("ipopt_eval_jac_g... nnzJ = %d",sys->nnzJ);      //CONSOLE_DEBUG("ipopt_eval_jac_g... nnzJ = %d",sys->nnzJ);
751      //CONSOLE_DEBUG("ipopt_eval_jac_g... n = %d",sys->n);      //CONSOLE_DEBUG("ipopt_eval_jac_g... n = %d",sys->n);
752      //CONSOLE_DEBUG("ipopt_eval_jac_g... m = %d",sys->m);      //CONSOLE_DEBUG("ipopt_eval_jac_g... m = %d",sys->m);
# Line 783  Bool ipopt_eval_jac_g(Index n, Number* x Line 772  Bool ipopt_eval_jac_g(Index n, Number* x
772                  for(j=0;j<len;j++){                  for(j=0;j<len;j++){
773                      /* looping through incident variables in current relation */                      /* looping through incident variables in current relation */
774                      if(var_apply_filter(incidence_list[j], &(sys->vfilt))){                      if(var_apply_filter(incidence_list[j], &(sys->vfilt))){
775                          CONSOLE_DEBUG("Location of Non Zero: {%d,%d}; k = %d",i,incidence_list[j]->sindex,k);                          CONSOLE_DEBUG("Non-zero #%d at [%d,%d]",k, i,incidence_list[j]->sindex);
776    
777                          /* valgrind says invalid write of size 4 here... */                          /* valgrind says invalid write of size 4 here... */
778                          iRow[k]=i; // should i use sindex of row here or is this ok?                          iRow[k]=i; // should i use sindex of row here or is this ok?
779                          jCol[k++]=incidence_list[j]->sindex;                          jCol[k++]=incidence_list[j]->sindex;
780                      }                      }
781                  }                        }
782                }else{
783                    CONSOLE_DEBUG("Filter removes relation %d",i);
784              }              }
785          }          }
786          CONSOLE_DEBUG("Finished Locating Non-Zero elements in Sparse Matrix");          CONSOLE_DEBUG("Found %d non-zero elements in jacobian", k);
787      }else{      }else{
788          /** @todo Allocating and Deallocating memory for each row??? you must be out of your mind :O */          //CONSOLE_DEBUG("Calculating jacobian...");
789          k=0;          k=0;
790            /** @TODO make use of some temporary allocated memory for these arrays... */
791          variables = ASC_NEW_ARRAY(int,n);          variables = ASC_NEW_ARRAY(int,n);
792          derivatives = ASC_NEW_ARRAY(double,n);          derivatives = ASC_NEW_ARRAY_CLEAR(double,n);
793          for(i=0; i<m;++i){          for(i=0; i<m;++i){
794              if(rel_apply_filter(sys->rlist[i], &(sys->rfilt))){                          if(rel_apply_filter(sys->rlist[i], &(sys->rfilt))){
795                  incidence_list = (struct var_variable**) rel_incidence_list(sys->rlist[i]);                  incidence_list = (struct var_variable**) rel_incidence_list(sys->rlist[i]);
796                  len = rel_n_incidences(sys->rlist[i]);                  len = rel_n_incidences(sys->rlist[i]);
                   
                   /*relman_diff2(sys->rlist[i],&vfilter,derivatives,variables  
                   ,&count,SLV_PARAM_BOOL(&(sys->p),ASCEND_PARAM_SAFEEVAL)  
                   );*/  
797    
798    #if 0
799                    relman_diff2(sys->rlist[i],&(sys->vfilt),derivatives,variables
800                        ,&count,SLV_PARAM_BOOL(&(sys->p),ASCEND_PARAM_SAFEEVAL)
801                    );
802    #else
803                  relman_diff2_rev(sys->rlist[i], &(sys->vfilt), derivatives                  relman_diff2_rev(sys->rlist[i], &(sys->vfilt), derivatives
804                      ,variables, &count, SLV_PARAM_BOOL(&(sys->p),ASCEND_PARAM_SAFEEVAL)                      ,variables, &count, SLV_PARAM_BOOL(&(sys->p),ASCEND_PARAM_SAFEEVAL)
805                  );                  );
806                  for(j=0;j<len;j++){  #endif
807    
808                    for(j=0;j<count;j++){ /* loop through only the returned (filtered) incidences, not all of them */
809                        asc_assert(k < sys->nnzJ);
810                        //CONSOLE_DEBUG("Recording values[%d] = derivatives[%d]",k,j);
811                      asc_assert(!isnan(derivatives[j]));                      asc_assert(!isnan(derivatives[j]));
812                      values[k++] = derivatives[j];                      values[k++] = derivatives[j];
813                  }                  }
# Line 845  Bool ipopt_eval_h(Index n, Number* x, Bo Line 842  Bool ipopt_eval_h(Index n, Number* x, Bo
842      Index col;      Index col;
843      Index idx;      Index idx;
844    
   
     static var_filter_t vfilter = {  
         VAR_ACTIVE | VAR_INCIDENT | VAR_SVAR | VAR_FIXED,  
         VAR_ACTIVE | VAR_INCIDENT | VAR_SVAR  
     };    
   
845      //CONSOLE_DEBUG("IN FUNCTION ipopt_eval_h");      //CONSOLE_DEBUG("IN FUNCTION ipopt_eval_h");
846      //CONSOLE_DEBUG("ipopt_eval_h... nnzH = %d",sys->nnzH);      //CONSOLE_DEBUG("nnzH = %d",sys->nnzH);
847      //CONSOLE_DEBUG("ipopt_eval_h... n = %d",sys->n);      //CONSOLE_DEBUG("n = %d, m = %d",sys->n, sys->m);
848    
849      asc_assert(sys!=NULL);      asc_assert(sys!=NULL);
850      asc_assert(n==sys->n);      asc_assert(n==sys->n);
# Line 861  Bool ipopt_eval_h(Index n, Number* x, Bo Line 852  Bool ipopt_eval_h(Index n, Number* x, Bo
852            
853      if(new_x){      if(new_x){
854          res = ipopt_update_model(sys,x);          res = ipopt_update_model(sys,x);
855          if(res)return 0; /* fail model update */          if(res)return FALSE; /* fail model update */
856      }      }
857    
858      if(values == NULL){      if(values == NULL){
# Line 898  Bool ipopt_eval_h(Index n, Number* x, Bo Line 889  Bool ipopt_eval_h(Index n, Number* x, Bo
889                    
890          /** Correction for objective function **/          /** Correction for objective function **/
891          //CONSOLE_DEBUG("Correction for Objective Relation underway");          //CONSOLE_DEBUG("Correction for Objective Relation underway");
892          relman_hess(sys->obj,&vfilter,hess_matrix,&count,n,SLV_PARAM_BOOL(&(sys->p),ASCEND_PARAM_SAFEEVAL));          relman_hess(sys->obj,&(sys->vfilt),hess_matrix,&count,n,SLV_PARAM_BOOL(&(sys->p),ASCEND_PARAM_SAFEEVAL));
893                    
894          idx = 0;          idx = 0;
895    
# Line 921  Bool ipopt_eval_h(Index n, Number* x, Bo Line 912  Bool ipopt_eval_h(Index n, Number* x, Bo
912              incidence_list = (struct var_variable**) rel_incidence_list(sys->rlist[i]);              incidence_list = (struct var_variable**) rel_incidence_list(sys->rlist[i]);
913              if(incidence_list!=NULL){              if(incidence_list!=NULL){
914                  //CONSOLE_DEBUG("Correction for Constraint Relation [%lu] underway",i);                  //CONSOLE_DEBUG("Correction for Constraint Relation [%lu] underway",i);
915                  relman_hess(sys->rlist[i],&vfilter,hess_matrix,&count,n,SLV_PARAM_BOOL(&(sys->p),ASCEND_PARAM_SAFEEVAL));                  relman_hess(sys->rlist[i],&(sys->vfilt),hess_matrix,&count,n,SLV_PARAM_BOOL(&(sys->p),ASCEND_PARAM_SAFEEVAL));
916                            
917                  idx=0;                  idx=0;
918    
# Line 971  static int ipopt_presolve(slv_system_t s Line 962  static int ipopt_presolve(slv_system_t s
962    
963      /** @todo work out if matrix creation is not again needed */      /** @todo work out if matrix creation is not again needed */
964    
965      /** @todo slv_sort_rels_and_vars(server,&(sys->m),&(sys->n)); */      slv_sort_rels_and_vars(server,&(sys->m),&(sys->n));
966    #if 0
967        /* ignore any errors here; if it fails, we may just have a single objective function and no constraining relations */
968        if(-1 == sys->n){
969            ERROR_REPORTER_HERE(ASC_PROG_ERR,"Failed to find any optimisable vars");
970            return -4;
971        }
972        if(-1 == sys->m){
973            sys->m = 0; /* no relations found, but that's OK if there's an objective? */
974        }
975        if(-1 == sys->m)sys->m = 0;
976        if(-1 == sys->n)sys->n = 0;
977    #endif
978    
979        CONSOLE_DEBUG("Got %d rels and %d vars",sys->m, sys->n);
980    
981    #if 1
982      /* count the number of optimisation variables */      /* count the number of optimisation variables */
983      sys->n = 0;      sys->n = 0;
984      for(i = 0; i < sys->vtot; i++){      for(i = 0; i < sys->vtot; i++){
# Line 982  static int ipopt_presolve(slv_system_t s Line 987  static int ipopt_presolve(slv_system_t s
987              sys->n++;              sys->n++;
988          }          }
989      }      }
990    #endif
991    
992      /* set all relations as being 'unsatisfied' to start with... */      /* set all relations as being 'unsatisfied' to start with... */
993      for(i=0; i < sys->rtot; ++i){      for(i=0; i < sys->rtot; ++i){
# Line 998  static int ipopt_presolve(slv_system_t s Line 1004  static int ipopt_presolve(slv_system_t s
1004      //CONSOLE_DEBUG("got objective rel %p",sys->obj);      //CONSOLE_DEBUG("got objective rel %p",sys->obj);
1005      /* @todo check if old_obj == obj ? */      /* @todo check if old_obj == obj ? */
1006    
1007    #if 1
1008      /* TODO are there cases where these should be different: answer: NO. they are always the same -- JP */      /* TODO are there cases where these should be different: answer: NO. they are always the same -- JP */
1009      sys->m = sys->rtot;      sys->m = sys->rtot;
1010    #endif
1011    
1012      //CONSOLE_DEBUG("Numbers of constraints = %d",sys->m);      //CONSOLE_DEBUG("Numbers of constraints = %d",sys->m);
1013    
1014      /** @todo we need to move the objective relation to the end of the list */      /** @todo we need to move the objective relation to the end of the list */

Legend:
Removed from v.2350  
changed lines
  Added in v.2351

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