intqld.c

Go to the documentation of this file.
00001 #include <string.h>
00002 #include "stack-c.h"
00003 #include "Scierror.h"
00004 extern double C2F(dlamch)  __PARAMS((char *CMACH, unsigned long int));
00005 
00006 int ql0001_(int *m,int *me,int *mmax,int *n,int *nmax,int *mnn,
00007             double *c,double *d,double *a,double *b,double *xl,
00008             double *xu,double *x,double *u,int *iout,int *ifail,
00009             int *iprint,double *war,int *lwar,int *iwar,int *liwar,
00010             double *eps1);
00011 
00012 int C2F(intqld)(fname) 
00013      char *fname;
00014 { 
00015   static int un=1,zero=0;
00016 
00017   static int Q, n, nbis;
00018   static int p, unbis;
00019   static int C, mmax, m, mnn;
00020   static int b, mbis;
00021   static int me, pipo;
00022   static int lb, ub, leps;
00023   static int x, lambda, inform, ifail;
00024   int next;
00025 
00026   static int war, lwar, iwar, iout, C_mmax, b_mmax, k, l;
00027   static double eps1;
00028 
00029   /*    Define minls=1, maxlhs, minrhs, maxrhs   */
00030   static int minlhs=1, minrhs=7, maxlhs=3, maxrhs=8;
00031 
00032   /*   Check rhs and lhs   */  
00033   CheckRhs(minrhs,maxrhs) ;
00034   CheckLhs(minlhs,maxlhs) ;
00035 
00036   /* RhsVar: qld(Q,p,C,b,lb,ub,me,eps) */
00037   /*             1,2,3,4,5 ,6 ,7, 8  */
00038   eps1=C2F(dlamch)("e",1L);
00039   next= Rhs+1;
00040   /*   Variable 1 (Q)   */
00041   GetRhsVar(1, "d", &n, &nbis, &Q);
00042   CheckSquare(1,n,nbis);
00043 
00044   /*   Variable 2 (p)   */
00045   GetRhsVar(2, "d", &nbis, &unbis, &p);
00046   CheckLength(2,nbis*unbis,n);
00047   
00048   /*   Variable 3 (C)   */
00049   GetRhsVar(3, "d", &m, &nbis, &C);
00050   if (( nbis != n ) && (m > 0)) 
00051     {
00052       Scierror(205,"qld: Argument 3: wrong number of columns %d expected \r\n", n);
00053       return 0;
00054     }
00055   mmax = m+1;
00056   mnn = m+n+n;
00057 
00058   /*   Variable 4 (b)   */  
00059   GetRhsVar(4, "d", &mbis, &unbis, &b);
00060   CheckLength(4,mbis*unbis,m);
00061 
00062   /*   Variable 5 (lb)   */
00063   GetRhsVar(5, "d", &nbis, &unbis, &lb);
00064   if (nbis*unbis==0) {
00065     CreateVar(next+1, "d", &n, &un, &lb);
00066     for(k=0; k<n; k++)
00067     stk(lb)[k] = -C2F(dlamch)("o",1L);
00068     next=next+1;
00069   }
00070   else
00071     CheckLength(5,nbis*unbis,n);
00072 
00073 
00074   /*   Variable 6 (ub)   */
00075   GetRhsVar(6, "d", &nbis, &unbis, &ub);
00076   if (nbis*unbis==0) {
00077     CreateVar(next+1, "d", &n, &un, &ub);
00078     for(k=0; k<n; k++)
00079     stk(ub)[k] = C2F(dlamch)("o",1L);
00080     next=next+1;
00081   }
00082   else
00083     CheckLength(6,nbis*unbis,n);
00084  
00085   /*   Variable 7 (me)   */  
00086   GetRhsVar(7, "i", &pipo, &unbis, &me);
00087   CheckScalar(7,pipo,unbis);
00088   if ((*istk(me)<0) || (*istk(me)>n))
00089     {
00090       Err = 7;
00091       Error(116);
00092       return 0;
00093     }
00094 
00095   if(Rhs==8) {
00096     /*   Variable 8 (eps1)   */  
00097     GetRhsVar(8, "d", &pipo, &unbis, &leps);
00098     CheckScalar(8,pipo,unbis);
00099     eps1= Max(eps1,*stk(leps));
00100   }
00101 
00102   next=Rhs;
00103   /* Internal variables: x, lambda, inform, C_mmax, b_mmax */
00104   CreateVar(next+1, "d", &n, &un, &x);
00105 
00106   CreateVar(next+2, "d", &mnn, &un, &lambda);
00107  
00108   CreateVar(next+3, "i", &un, &un, &inform);
00109   
00110 
00111   lwar = 3*n*n/2+10*n+2*mmax+2;
00112   CreateVar(next+4, "d", &lwar, &un, &war);
00113   CreateVar(next+5, "i", &n, &un, &iwar);
00114   istk(iwar)[0]=0;
00115  
00116   /* extend C and B to add a row and change the sign of C*/
00117   CreateVar(next+6, "d", &mmax, &n, &C_mmax);
00118   for(k=0; k<n; k++) {
00119     for(l=0; l<m; l++)
00120       stk(C_mmax)[k*mmax+l] = -stk(C)[k*m+l];
00121     stk(C_mmax)[k*mmax+m] = 0.0;}
00122 
00123   CreateVar(next+7, "d", &mmax, &un, &b_mmax);
00124   for(k=0; k<m; k++)
00125     stk(b_mmax)[k] = stk(b)[k];
00126   stk(b_mmax)[m] = 0.0;
00127 
00128   iout = 0;
00129   ifail=0;
00130   C2F(ql0001)(&m, istk(me), &mmax, &n, &n, &mnn, stk(Q), stk(p), stk(C_mmax),
00131           stk(b_mmax), stk(lb), stk(ub), stk(x), stk(lambda), &iout,
00132           &ifail, &zero, stk(war), &lwar, istk(iwar), &n, &eps1);
00133 
00134 
00135   /* LhsVar: [x, lambda, inform] = qld(...) */
00136 
00137   if (ifail==0) {
00138     LhsVar(1) = next+1;
00139     LhsVar(2) = next+2;
00140     if (Lhs==3) {
00141       LhsVar(3) = next+3;
00142       *istk(inform)=ifail;
00143     }
00144     C2F(putlhsvar)();
00145   }
00146   else if (ifail==1)
00147     Scierror(24,"qld: Too many iterations (more than %d) \r\n", 40*(n+m));
00148   else if (ifail==2)
00149     Scierror(24,"qld: Accuracy insufficient to statify convergence criterion.\r\n");
00150   else if (ifail==5)
00151     Scierror(999,"qld: Length of working array is too short.\r\n");
00152  else if (ifail>10)
00153     Scierror(999,"qld: The constraints are inconsistent.\r\n");
00154 
00155 
00156   return 0;
00157 }

Generated on Sun Mar 4 15:03:58 2007 for Scilab [trunk] by  doxygen 1.5.1