/[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 1534 by jpye, Thu Jul 5 14:43:47 2007 UTC revision 1535 by jpye, Mon Jul 9 14:58:15 2007 UTC
# Line 120  struct IpoptSystemStruct{ Line 120  struct IpoptSystemStruct{
120      Number* x;                    /* starting point and solution vector */      Number* x;                    /* starting point and solution vector */
121      Number* mult_x_L;             /* lower bound multipliers at the solution */      Number* mult_x_L;             /* lower bound multipliers at the solution */
122      Number* mult_x_U;             /* upper bound multipliers at the solution */      Number* mult_x_U;             /* upper bound multipliers at the solution */
     Number objval;                /* objective value */  
123      Index i;                      /* generic counter */      Index i;                      /* generic counter */
124  };  };
125    
# Line 307  Bool ipopt_eval_f(Index n, Number *x, Bo Line 306  Bool ipopt_eval_f(Index n, Number *x, Bo
306      int res;      int res;
307    
308      asc_assert(n==sys->n);      asc_assert(n==sys->n);
309        asc_assert(sys->obj!=NULL);
310    
311      if(new_x){      if(new_x){
312          res = ipopt_update_model(sys,x);          res = ipopt_update_model(sys,x);
313          if(res)return 0; /* fail model update */          if(res)return 0; /* fail model update */
314      }      }
315    
316        sys->calc_ok = TRUE;
317    
318      double val = 0;      *obj_value = relman_eval(sys->obj,&(sys->calc_ok),SAFE_CALC);
     /* evaluate f(x) somehow */  
319    
320      *obj_value = val;      return sys->calc_ok;
   
     return 0; /* fail: not yet implemented */  
321  }  }
322    
323    /**
324        @return 1 on success
325    */
326  Bool ipopt_eval_grad_f(Index n, Number* x, Bool new_x, Number* grad_f, void *user_data){  Bool ipopt_eval_grad_f(Index n, Number* x, Bool new_x, Number* grad_f, void *user_data){
327      IpoptSystem *sys;      IpoptSystem *sys;
328      sys = SYS(user_data);      sys = SYS(user_data);
329      int j, res;      int j, res, len;
330        double *derivatives;
331        int *variables;
332        static var_filter_t vfilter = {
333            VAR_ACTIVE | VAR_INCIDENT | VAR_SVAR
334            ,VAR_ACTIVE | VAR_INCIDENT | VAR_SVAR | VAR_FIXED
335        };
336    
337      asc_assert(n==sys->n);      asc_assert(n==sys->n);
338        asc_assert(sys->obj);
339    
340      if(new_x){      if(new_x){
341          res = ipopt_update_model(sys,x);          res = ipopt_update_model(sys,x);
# Line 339  Bool ipopt_eval_grad_f(Index n, Number* Line 347  Bool ipopt_eval_grad_f(Index n, Number*
347      for(j=0; j<n; ++j){      for(j=0; j<n; ++j){
348          grad_f[j] = 0;          grad_f[j] = 0;
349      }      }
350        
351        len = rel_n_incidences(sys->obj);
352        variables = ASC_NEW_ARRAY(int,len);
353        derivatives = ASC_NEW_ARRAY(double,len);
354    
355      return 0; /* fail: not yet implemented */      relman_diff2(
356            sys->obj,&vfilter,derivatives,variables
357            , &(obj_count),SAFE_CALC
358        );
359    
360        for(j=0; j<len; ++j){
361            grad_f[variables[j]] = derivatives[j];
362        }
363    
364        ASC_FREE(variables);
365        ASC_FREE(derivatives);
366    
367        return 1; /* success, presumably */
368  }  }
369    
370  Bool ipopt_eval_g(Index n, Number* x, Bool new_x, Index m, Number *g, void *user_data){  Bool ipopt_eval_g(Index n, Number* x, Bool new_x, Index m, Number *g, void *user_data){
# Line 689  static const SlvFunctionsT ipopt_interna Line 713  static const SlvFunctionsT ipopt_interna
713  };  };
714    
715  int ipopt_register(void){  int ipopt_register(void){
716      ERROR_REPORTER_HERE(ASC_PROG_ERR,"Failed to load IPOPT");      return solver_register(&tron_internals);
     return 1;  
     /* return solver_register(&tron_internals); */  
717  }  }

Legend:
Removed from v.1534  
changed lines
  Added in v.1535

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