Exemple #1
0
   SEXP ralgencan(SEXP evalf_ptr,SEXP evalg_ptr,SEXP evalh_ptr,
   SEXP evalc_ptr,SEXP evaljac_ptr,SEXP evalhc_ptr,SEXP evalfc_ptr,
   SEXP evalgjac_ptr, SEXP evalgjacp_ptr, SEXP evalhl_ptr, 
   SEXP evalhlp_ptr,SEXP inip_ptr, SEXP endp_ptr,SEXP param_ptr,
   SEXP environment_ptr) {

   int checkder,inform,iprint,m,n,ncomp;
   double cnorm,f,nlpsupn,efacc,eoacc,epsfeas,epsopt,snorm;

   int coded[11];
   int *equatn,*linear;
   double *l,*lambda,*u,*x;
   SEXP return_value;

   evalf_r       = evalf_ptr;
   evalg_r       = evalg_ptr;
   evalh_r       = evalh_ptr;
   evalc_r       = evalc_ptr;
   evaljac_r     = evaljac_ptr;
   evalhc_r      = evalhc_ptr;
   evalfc_r      = evalfc_ptr;
   evalgjac_r    = evalgjac_ptr;
   evalgjacp_r    = evalgjacp_ptr;
   evalhl_r      = evalhl_ptr;
   evalhlp_r     = evalhlp_ptr;
   inip_r        = inip_ptr;
   endp_r        = endp_ptr;
   param_r       = param_ptr;
   environment_r = environment_ptr;

/* SET SOME SOLVER ARGUMENTS */
   param(&epsfeas,&epsopt,&efacc,&eoacc,&iprint,&ncomp);

/* SET UP PROBLEM DATA */
   inip(&n,&x,&l,&u,&m,&lambda,&equatn,&linear,coded,&checkder);

   C2FLOGICALV(equatn,m);
   C2FLOGICALV(linear,m);
   C2FLOGICALV(coded,11);

   Algencan(epsfeas,epsopt,efacc,eoacc,iprint,ncomp,n,x,l,u,m,lambda,
   equatn,linear,coded,checkder,f,cnorm,snorm,nlpsupn,inform);

/* WRITE ADDITIONAL OUTPUT INFORMATION CODED BY THE USER */
   endp(n,x,l,u,m,lambda,equatn,linear);


   defineVar(install("AlgencanReturnValue"),createRIntScalar(0),
   environment_r);
   defineVar(install("f"),createRRealScalar(f),environment_r);
   defineVar(install("cnorm"),createRRealScalar(cnorm),environment_r);
   defineVar(install("snorm"),createRRealScalar(snorm),environment_r);
   defineVar(install("nlpsupn"),createRRealScalar(nlpsupn),environment_r);
   defineVar(install("inform"),createRIntScalar(inform),environment_r);

   return_value = findVar(install("AlgencanReturnValue"),environment_r);

   return return_value;

   }
Exemple #2
0
static PyObject *pywrapper_solver(PyObject *self,PyObject *args) {

  int checkder,inform,iprint,m,n,ncomp;
  double cnorm,f,nlpsupn,epsfeas,epsopt,snorm;

  int coded[10];
  int *equatn,*linear;
  double *l,*lambda,*u,*x;

  return_value = Py_None;
  setbuf(stderr,(char *) malloc(BUFSIZ));

  if (!PyArg_ParseTuple(args,"O!O!O!O!O!O!O!O!O!O!O!O!O!:solver",
                        &PyFunction_Type,&evalf_py,
                        &PyFunction_Type,&evalg_py,
                        &PyFunction_Type,&evalh_py,
                        &PyFunction_Type,&evalc_py,
                        &PyFunction_Type,&evaljac_py,
                        &PyFunction_Type,&evalhc_py,
                        &PyFunction_Type,&evalfc_py,
                        &PyFunction_Type,&evalgjac_py,
                        &PyFunction_Type,&evalhl_py,
                        &PyFunction_Type,&evalhlp_py,
                        &PyFunction_Type,&inip_py,
                        &PyFunction_Type,&endp_py,
                        &PyDict_Type,&param_py)) goto cleanup;

  Py_INCREF(evalf_py   );
  Py_INCREF(evalg_py   );
  Py_INCREF(evalh_py   );
  Py_INCREF(evalc_py   );
  Py_INCREF(evaljac_py );
  Py_INCREF(evalhc_py  );
  Py_INCREF(evalfc_py  );
  Py_INCREF(evalgjac_py);
  Py_INCREF(evalhl_py  );
  Py_INCREF(evalhlp_py );
  Py_INCREF(inip_py    );
  Py_INCREF(endp_py    );
  Py_INCREF(param_py   );

  param(&epsfeas,&epsopt,&iprint,&ncomp);
  if (return_value == NULL) goto cleanup;

  inip(&n,&x,&l,&u,&m,&lambda,&equatn,&linear,coded,&checkder);
  if (return_value == NULL) goto cleanup;

  C2FLOGICALV(equatn,m);
  C2FLOGICALV(linear,m);
  C2FLOGICALV(coded,10);

  Algencan(epsfeas,epsopt,iprint,ncomp,n,x,l,u,m,lambda,equatn,
  linear,coded,checkder,f,cnorm,snorm,nlpsupn,inform);
  if (return_value == NULL) goto cleanup;

  endp(n,x,l,u,m,lambda,equatn,linear);
  if (return_value == NULL) goto cleanup;

 cleanup:
  Py_XDECREF(evalf_py   );
  Py_XDECREF(evalg_py   );
  Py_XDECREF(evalh_py   );
  Py_XDECREF(evalc_py   );
  Py_XDECREF(evaljac_py );
  Py_XDECREF(evalhc_py  );
  Py_XDECREF(evalfc_py  );
  Py_XDECREF(evalgjac_py);
  Py_XDECREF(evalhl_py  );
  Py_XDECREF(evalhlp_py );
  Py_XDECREF(inip_py    );
  Py_XDECREF(endp_py    );
  Py_XDECREF(param_py   );

  fflush(stdout);
  fflush(stderr);

  Py_XINCREF(return_value);
  return return_value;

}