![]() | |||||||||||||||||||||||||
| |||||||||||||||||||||||||
UG - Examples from 'BCL Reference Manual' Description The following examples are discussed in detail in the 'BCL User Guide and Reference Manual':
Source Files By clicking on a file name, a preview is opened at the bottom of this page.
Data Files xbqpr12.c /******************************************************** BCL Example Problems ==================== file xbqpr12.c `````````````` Small Quadratic Programming example. minimize x1 + x1^2 +2x1x2 +2x2^2 +x4^2 s.t. C1: x1 +2x2 -4x4 >= 0 C2: 3x1 -2x3 - x4 <= 100 C3: 10 <= x1 +3x2 +3x3 -2x4 <= 30 0<=x1<=20 0<=x2,x3 x4 free (c) 2008 Fair Isaac Corporation author: S.Heipcke, Jan. 2000, rev. Mar. 2011 ********************************************************/ #include <stdio.h> #include "xprb.h" #define NVar 4 /***********************************************************************/ int main(int argc, char **argv) { XPRBctr cobj, c; XPRBvar x[NVar]; int i; XPRBprob prob; prob=XPRBnewprob("QPr12"); /* Initialize a new problem in BCL */ /**** VARIABLES ****/ x[0] = XPRBnewvar(prob,XPRB_PL,"x1",0,20); x[1] = XPRBnewvar(prob,XPRB_PL,"x2",0,XPRB_INFINITY); x[2] = XPRBnewvar(prob,XPRB_PL,"x3",0,XPRB_INFINITY); x[3] = XPRBnewvar(prob,XPRB_PL,"x4",-XPRB_INFINITY,XPRB_INFINITY); /****OBJECTIVE****/ cobj = XPRBnewctr(prob,"OBJ",XPRB_N); XPRBaddterm(cobj, x[0],1); /* Define quadratic part of the objective */ XPRBaddqterm(cobj,x[0],x[0],1); XPRBaddqterm(cobj,x[0],x[1],2); XPRBaddqterm(cobj,x[1],x[1],2); XPRBaddqterm(cobj,x[3],x[3],1); XPRBsetobj(prob,cobj); /**** CONSTRAINTS ****/ c = XPRBnewctr(prob,"C1",XPRB_G); XPRBaddterm(c, x[0], 1); XPRBaddterm(c, x[1], 2); XPRBaddterm(c, x[3], -4); c = XPRBnewctr(prob,"C2",XPRB_L); XPRBaddterm(c, x[0], 3); XPRBaddterm(c, x[2], -2); XPRBaddterm(c, x[3], -1); XPRBaddterm(c, NULL, 100); c = XPRBnewctr(prob,"C3",XPRB_L); XPRBaddterm(c, x[0], 1); XPRBaddterm(c, x[1], 3); XPRBaddterm(c, x[2], 3); XPRBaddterm(c, x[3], -2); XPRBsetrange(c, 10, 30); /****SOLVING + OUTPUT****/ XPRBprintprob(prob); /* Print out the problem definition */ XPRBexportprob(prob,XPRB_MPS,"QPr12"); /* Output the matrix in MPS format */ XPRBexportprob(prob,XPRB_LP,"QPr12"); /* Output the matrix in LP format */ XPRBsetsense(prob,XPRB_MINIM); /* Choose the sense of optimization */ XPRBlpoptimize(prob,""); /* Solve the QP-problem */ printf("Objective function value: %g\n", XPRBgetobjval(prob)); for(i=0;i<NVar;i++) printf("%s: %g, ", XPRBgetvarname(x[i]), XPRBgetsol(x[i])); printf("\n"); return 0; }
| |||||||||||||||||||||||||
© Copyright 2023 Fair Isaac Corporation. |