⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 ipslv.c

📁 matlab整数规划工具箱
💻 C
字号:
/* This file contains functions for the interface of LP_SOLVE to MATLAB.   This file is not part of the LP_SOLVE package. *//* * MATLAB Compiler: 2.0.1 * Date: Fri Jul 13 15:32:32 2001 * Arguments: "-x" "ipslv"  */#include "ipslv.h"#include "lpkit.h"#include <stdio.h>void lp2mat(REAL* f, REAL* L, REAL* b, int m, int n, REAL* intlist, REAL* ub, REAL* lb, REAL* ctype, REAL* kind, REAL* solution);/* * The function "Mipslv" is the implementation version of the "ipslv" * M-function from file "ipslv.m" (lines * 1-31). It contains the actual compiled code for that M-function. It is a * static function and must only be called from one of the interface functions, * appearing below. *//* * function [res, kind] = ipslv(f, L, B, intlist, ub, lb, ctype) */static mxArray * Mipslv(mxArray * * kind,                        int nargout_,                        const mxArray * f,                        const mxArray * L,                        const mxArray * B,                        const mxArray * intlist,                        const mxArray * ub,                        const mxArray * lb,                        const mxArray * ctype) {    mxArray *res, *tkind;    double *pres, *pkind, *pf, *pL, *pb, *pintlist, *pub, *plb, *pctype;    int m, n, i;        /* Apparently not available in Matlab 6, so removed ...    mclValidateInputs("ipslv", 7, &f, &L, &B, &intlist, &ub, &lb, &ctype);    */    /*     *      * %  IPSLV - Basic Interface to the Mixed Integer Program Solver LP_SOLVE     * %     * %  [res, kind] = ipslv(f, L, B, intlist, ub, lb, ctype)     * %     * %  In principle the following type of program is considered:      * %  min f'x  such that Lx <= b, ub >= x >= lb,      * %  x >= 0, and x(i) is integer for all i such that intlist(i) ~= 0     * %  However each row may specify a different type of constraint: <=, =, or      * %  >=. Thus we have:     * %  L(i,:)x <= b(i) for ctype(i) = -1     * %  L(i,:)x  = b(i) for ctype(i) =  0     * %  L(i,:)x >= b(i) for ctype(i) =  1     * %     * %  ub[i] < 0 if x(i) has an infinite upper bound.     * %     * %  The function returns the optimal x in res; kind is set to the     * %  kind of termination: OPTIMAL (0), MILP_FAIL (1), INFEASIBLE (2),      * %  UNBOUNDED (3), or FAILURE (4).     *      * [m, n] = size(L);    mlfSize(mlfVarargout(&m, &n, NULL), L, NULL);     */         m = mxGetM(L); n = mxGetN(L); /* get the number of rows and columns*/    /* printf("\n Hello-1! %d x %d\n", m, n); */    res = mxCreateNumericArray(1, &n, mxDOUBLE_CLASS, mxREAL); /* creates nx1 array */    i = 1;    /* printf("\n Hello-2!\n"); */    tkind = mxCreateNumericArray(1, &i, mxDOUBLE_CLASS, mxREAL); /* creates 1x1 array */    /* printf("\n Hello-3!\n"); */    pkind = mxGetPr(tkind);    /* printf("\n Hello-4!\n"); */    pf = mxGetPr(f);    pL = mxGetPr(L);    pb = mxGetPr(B);    pintlist = mxGetPr(intlist);    pub = mxGetPr(ub);    plb = mxGetPr(lb);    pctype = mxGetPr(ctype);    pres = mxGetPr(res);    /* printf("\n Hello-5!\n");*/    lp2mat(pf, pL, pb, m, n, pintlist, pub, plb, pctype, pkind, pres);     /* printf("\n Hello-6!\n");*/    mlfAssign(kind, tkind);    /*printf("\n Hello-7!\n");*/    /* Apparently not available in Matlab 6, so removed    mclValidateOutputs("ipslv", 2, nargout_, &res, kind);    */    /* Do not mxDestroyArray(tkind); this would destroy *kind as well. */    return res;}/* * The function "mlfIpslv" contains the normal interface for the "ipslv" * M-function from file "ipslv.m" (lines * 1-31). This function processes any input arguments and passes them to the * implementation version of the function, appearing above. */mxArray * mlfIpslv(mxArray * * kind,                   mxArray * f,                   mxArray * L,                   mxArray * B,                   mxArray * intlist,                   mxArray * ub,                   mxArray * lb,                   mxArray * ctype) {    int nargout = 1;    mxArray * res = mclGetUninitializedArray();    mxArray * kind__ = mclGetUninitializedArray();    mlfEnterNewContext(1, 7, kind, f, L, B, intlist, ub, lb, ctype);    if (kind != NULL) {        ++nargout;    }    res = Mipslv(&kind__, nargout, f, L, B, intlist, ub, lb, ctype);    mlfRestorePreviousContext(1, 7, kind, f, L, B, intlist, ub, lb, ctype);    if (kind != NULL) {        mclCopyOutputArg(kind, kind__);    } else {        mxDestroyArray(kind__);    }    return mlfReturnValue(res);}/* * The function "mlxIpslv" contains the feval interface for the "ipslv" * M-function from file "ipslv.m" (lines * 1-31). The feval function calls the implementation version of ipslv through * this function. This function processes any input arguments and passes them * to the implementation version of the function, appearing above. */void mlxIpslv(int nlhs, mxArray * plhs[], int nrhs, mxArray * prhs[]) {    const mxArray * mprhs[7];    mxArray * mplhs[2];    int i;    if (nlhs > 2) {        mlfError(          mxCreateString(            "Run-time Error: File: ipslv Line: 1 Column: 0 The function \"ipslv"            "\" was called with more than the declared number of outputs (2)"));    }    if (nrhs > 7) {        mlfError(          mxCreateString(            "Run-time Error: File: ipslv Line: 1 Column: 0 The function \"ipslv"            "\" was called with more than the declared number of inputs (7)"));    }    for (i = 0; i < 2; ++i) {        mplhs[i] = NULL;    }    for (i = 0; i < 7 && i < nrhs; ++i) {        mprhs[i] = prhs[i];    }    for (; i < 7; ++i) {        mprhs[i] = NULL;    }    mlfEnterNewContext(      0,      7,      mprhs[0],      mprhs[1],      mprhs[2],      mprhs[3],      mprhs[4],      mprhs[5],      mprhs[6]);    mplhs[0]      = Mipslv(          &mplhs[1],          nlhs,          mprhs[0],          mprhs[1],          mprhs[2],          mprhs[3],          mprhs[4],          mprhs[5],          mprhs[6]);    mlfRestorePreviousContext(      0,      7,      mprhs[0],      mprhs[1],      mprhs[2],      mprhs[3],      mprhs[4],      mprhs[5],      mprhs[6]);    plhs[0] = mplhs[0];    for (i = 1; i < 2 && i < nlhs; ++i) {        plhs[i] = mplhs[i];    }    for (; i < 2; ++i) {        mxDestroyArray(mplhs[i]);    }}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -