📄 lpmex.c
字号:
else if (strcmp("unscale",cmd)==0) { if (nrhs != 2) mexErrMsgTxt("unscale requires 1 argument."); unscale(lp[h]); } /* Start Change*/ /* lpmex('get_no_rows', lp_handle) */ else if (strcmp("get_no_rows",cmd)==0) { if (nrhs != 2) mexErrMsgTxt("get_no_rows requires 1 argument."); plhs[0] = mxCreateDoubleMatrix(1,1,0); pr = mxGetPr(plhs[0]); pr[0]=lp[h]->rows; } /* lpmex('get_no_cols', lp_handle) */ else if (strcmp("get_no_cols",cmd)==0) { if (nrhs != 2) mexErrMsgTxt("get_no_cols requires 1 argument."); plhs[0] = mxCreateDoubleMatrix(1,1,0); pr = mxGetPr(plhs[0]); pr[0]=lp[h]->columns; } /* lpmex('get_orig_rh_vec', lp_handle) */ else if (strcmp("get_orig_rh_vec",cmd)==0) { if (nrhs != 2) { mexErrMsgTxt("get_orig_rh_vec requires 1 argument."); } plhs[0] = mxCreateDoubleMatrix(lp[h]->rows,1,0); pr = mxGetPr(plhs[0]); for (i=0; i<lp[h]->rows; i++) { if (lp[h]->ch_sign[i+1]) pr[i] = -1*lp[h]->orig_rh[i+1]; else pr[i] = lp[h]->orig_rh[i+1]; } } /* lpmex('get_obj_fun', lp_handle) */ else if (strcmp("get_obj_fun",cmd)==0) { if (nrhs != 2) mexErrMsgTxt("get_obj_fun requires 1 argument."); vec = mxCalloc(1+lp[h]->columns,sizeof(REAL)); get_row(lp[h],0,vec); plhs[0] = mxCreateDoubleMatrix(1,lp[h]->columns,0); pr = mxGetPr(plhs[0]); for (i=0; i<lp[h]->columns; i++) { pr[i] = vec[i+1]; } mxFree(vec); } /* lpmex('get_orig_lowbo', lp_handle) */ else if (strcmp("get_orig_lowbo",cmd)==0) { if (nrhs != 2) mexErrMsgTxt("get_orig_lowbo requires 1 argument."); plhs[0] = mxCreateDoubleMatrix(1,lp[h]->columns,0); pr = mxGetPr(plhs[0]); for (i=0; i<lp[h]->columns; i++) { pr[i] = lp[h]->orig_lowbo[lp[h]->rows+i+1]; } } /* lpmex('get_orig_upbo', lp_handle) */ else if (strcmp("get_orig_upbo",cmd)==0) { if (nrhs != 2) mexErrMsgTxt("get_orig_upbo requires 1 argument."); plhs[0] = mxCreateDoubleMatrix(1,lp[h]->columns,0); pr = mxGetPr(plhs[0]); for (i=0; i<lp[h]->columns; i++) { pr[i] = lp[h]->orig_upbo[lp[h]->rows+i+1]; } } /* lpmex('get_constr_types', lp_handle) */ else if (strcmp("get_constr_types",cmd)==0) { if (nrhs != 2) { mexErrMsgTxt("get_constr_types requires 1 argument."); } plhs[0] = mxCreateDoubleMatrix(lp[h]->rows,1,0); pr = mxGetPr(plhs[0]); for (i=0; i<lp[h]->rows; i++) { if (lp[h]->orig_upbo[i+1]==0) pr[i] = 1;/* equality constraint*/ else if (lp[h]->ch_sign[i+1]) pr[i] = 2;/* GE-row*/ else pr[i]=0;/*LE-row*/ } } /* lpmex('get_nonzeros', lp_handle) */ else if (strcmp("get_nonzeros",cmd)==0) { if (nrhs != 2) { mexErrMsgTxt("get_nonzeros requires 1 argument."); } plhs[0] = mxCreateDoubleMatrix(1,1,0); pr = mxGetPr(plhs[0]); pr[0]=lp[h]->non_zeros; } /* lpmex('get_col_names', lp_handle) */ else if (strcmp("get_col_names",cmd)==0) { if (nrhs != 2) { mexErrMsgTxt("get_col_names requires 1 argument."); } plhs[0] = mxCreateCellMatrix(1,lp[h]->columns); for (i=0; i<lp[h]->columns; i++) { pa=mxCreateString(lp[h]->col_name[i+1]); mxSetCell(plhs[0],i,pa); } } /* lpmex('get_row_names', lp_handle) */ else if (strcmp("get_row_names",cmd)==0) { if (nrhs != 2) { mexErrMsgTxt("get_row_names requires 1 argument."); } plhs[0] = mxCreateCellMatrix(lp[h]->rows,1); for (i=0; i<lp[h]->rows; i++) { pa=mxCreateString(lp[h]->row_name[i+1]); mxSetCell(plhs[0],i,pa); } } /* lpmex('get_objective_name', lp_handle) */ else if (strcmp("get_objective_name",cmd)==0) { if (nrhs != 2) { mexErrMsgTxt("get_objective_name requires 1 argument."); } plhs[0] = mxCreateString(lp[h]->row_name[0]); } /* lpmex('get_problem_name', lp_handle) */ else if (strcmp("get_problem_name",cmd)==0) { if (nrhs != 2) { mexErrMsgTxt("get_problem_name requires 1 argument."); } plhs[0] = mxCreateString(lp[h]->lp_name); } /* lpmex('get_int', lp_handle) */ else if (strcmp("get_int",cmd)==0) { if (nrhs != 2) { mexErrMsgTxt("get_int requires 1 argument."); } plhs[0] = mxCreateDoubleMatrix(1,lp[h]->columns,0); pr = mxGetPr(plhs[0]); for (i=0; i<lp[h]->columns; i++) { pr[i] = lp[h]->must_be_int[lp[h]->rows+i+1]; } } /*End Change*//* functions with at least two arguments */ else if (nrhs < 3 ) { strcpy(errmsg,cmd); strncat(errmsg,": Unimplemented or requires at least 2 arguments.",180); mexErrMsgTxt(errmsg); } /* lpmex('add_column', lp_handle, col_vec) */ else if (strcmp("add_column",cmd)==0) { if (nrhs != 3) { mexErrMsgTxt("add_column requires 2 arguments."); } vec = mxCalloc(1+lp[h]->rows,sizeof(REAL)); /* GetRealVector can handle both full and sparse matrix */ GetRealVector(prhs[2],vec,lp[h]->rows); add_column(lp[h],vec); mxFree(vec); } /* [ans]=lpmex('column_in_lp', lp_handle, col_vec) */ /* returns TRUE if col_vec is already present as a column in lp. */ /*(Does not look at bounds and types, only looks at matrix values) */ else if (strcmp("column_in_lp",cmd)==0) { if (nrhs != 3) { mexErrMsgTxt("column_in_lp needs 2 arguments."); } vec = mxCalloc(2+lp[h]->rows,sizeof(REAL)); /* GetRealVector can handle both full and sparse matrix */ GetRealVector(prhs[2],vec,1+lp[h]->rows); plhs[0] = mxCreateDoubleMatrix(1,1,0); pr = mxGetPr(plhs[0]); pr[0] = column_in_lp(lp[h],vec+1); mxFree(vec); } /* lpmex('del_column', lp_handle, col) */ else if (strcmp("del_column",cmd)==0) { if (nrhs != 3) { mexErrMsgTxt("del_column requires 2 arguments."); } col = GetRealScalar(prhs[2]); if ((col >= 1) && (col <= lp[h]->columns)) { del_column(lp[h],col); } else { mexErrMsgTxt("column number out of bounds."); } } /* lpmex('del_constraint', lp_handle, row) */ else if (strcmp("del_constraint",cmd)==0) { if (nrhs != 3) { mexErrMsgTxt("del_constraint requires 2 arguments."); } row = GetRealScalar(prhs[2]); if ((row >= 1) && (row <= lp[h]->rows)) { del_constraint(lp[h],row); } else { mexErrMsgTxt("constraint number out of bounds."); } } /* [col_vec] = lpmex('get_column', lp_handle, col) */ else if (strcmp("get_column",cmd)==0) { if (nrhs != 3) { mexErrMsgTxt("get_column requires 2 arguments."); } col = GetRealScalar(prhs[2]); if ((col < 1) || (col > lp[h]->columns)) { mexErrMsgTxt("column out of range."); } vec = mxCalloc(1+lp[h]->rows,sizeof(REAL)); get_column(lp[h],col,vec); plhs[0] = mxCreateDoubleMatrix(lp[h]->rows,1,0); pr = mxGetPr(plhs[0]); for (i=0; i<lp[h]->rows; i++) { pr[i] = vec[i+1]; } mxFree(vec); } /* [row_vec] = lpmex('get_row', lp_handle, row) */ else if (strcmp("get_row",cmd)==0) { if (nrhs != 3) mexErrMsgTxt("get_row requires 2 arguments."); row = GetRealScalar(prhs[2]); if ((row < 1) || (row > lp[h]->rows)) { mexErrMsgTxt("row out of range."); } vec = mxCalloc(1+lp[h]->columns,sizeof(REAL)); get_row(lp[h],row,vec); plhs[0] = mxCreateDoubleMatrix(1,lp[h]->columns,0); pr = mxGetPr(plhs[0]); for (i=0; i<lp[h]->columns; i++) { pr[i] = vec[i+1]; } mxFree(vec); } /* [ans]=lpmex('is_feasible', lp_handle, sol_vec) */ /* returns TRUE if the vector in values is a feasible solution to the lp */ else if (strcmp("is_feasible",cmd)==0) { if (nrhs != 3) { mexErrMsgTxt("is_feasible needs 2 arguments."); } vec = mxCalloc(1+lp[h]->rows,sizeof(REAL)); /* GetRealVector can handle both full and sparse matrix */ GetRealVector(prhs[2],vec,lp[h]->rows); plhs[0] = mxCreateDoubleMatrix(1,1,0); pr = mxGetPr(plhs[0]); pr[0] = is_feasible(lp[h],vec); mxFree(vec); } /* lpmex('lp_options', lp_handle, opt_str) */ /* Set options for the lp. See README_MEX for details*/ else if (strcmp("lp_options",cmd)==0) { if (nrhs != 3) { mexErrMsgTxt("lp_options needs 2 arguments."); } str = mxCalloc(73,sizeof(char)); mxGetString(prhs[2], str, 73); lp[h]->verbose = (strstr(str,"-v")) ? TRUE:FALSE; lp[h]->debug = (strstr(str,"-d")) ? TRUE:FALSE; lp[h]->print_duals = (strstr(str,"-p")) ? TRUE:FALSE; lp[h]->print_sol = (strstr(str,"-i")) ? TRUE:FALSE; lp[h]->floor_first = (strstr(str,"-c")) ? FALSE:TRUE; lp[h]->print_at_invert = (strstr(str,"-I")) ? TRUE:FALSE; lp[h]->trace = (strstr(str,"-t")) ? TRUE:FALSE; lp[h]->anti_degen = (strstr(str,"-degen")) ? TRUE:FALSE; if (strstr(str,"-s")) auto_scale(lp[h]); else unscale(lp[h]); if (str1=strstr(str,"-b")) lp[h]->obj_bound = atof(str1 + 3); else lp[h]->obj_bound = (REAL)DEF_INFINITE; if (str1=strstr(str,"-e")) lp[h]->epsilon = atof(str1 + 3); else lp[h]->epsilon = (REAL)DEF_EPSILON; mxFree(str); } /* lpmex('set_mat', lp_handle, a) Full matrix argument */ /* lpmex('set_mat', lp_handle, a) Sparse matrix argument */ /* lpmex('set_mat', lp_handle, row, col, value) */ else if (strcmp("set_mat",cmd)==0) { if ( (nrhs!=3) && (nrhs!=5) ) mexErrMsgTxt("incorrect number of arguments."); if (nrhs == 5) { row = GetRealScalar(prhs[2]); if ((lp[h]->rows < row)||(row < 0)) { mexErrMsgTxt("set_mat invalid row."); } col = GetRealScalar(prhs[3]); if ((lp[h]->columns < col)||(col < 0)) { mexErrMsgTxt("set_mat invalid column."); } value = GetRealScalar(prhs[4]); set_mat(lp[h],row,col,value); } else if (nrhs == 3) { /* Called with a matrix argument */ m = mxGetM(prhs[2]); n = mxGetN(prhs[2]); if ((lp[h]->rows != m) || (lp[h]->columns != n) || !mxIsNumeric(prhs[2]) || mxIsComplex(prhs[2])) { mexErrMsgTxt("invalid argument."); } pr = mxGetPr(prhs[2]); if (!mxIsSparse(prhs[2])) { for (j=0; j<n; j++) { for (l=0; l<m; l++) { set_mat(lp[h],l+1,j+1,pr[l+j*m]); } } } if (mxIsSparse(prhs[2])) { jc = mxGetJc(prhs[2]); ir = mxGetIr(prhs[2]); for (j=0; j<n; j++) { for (k = jc[j]; k<jc[j+1]; k++) { i = ir[k]; set_mat(lp[h],i+1,j+1,pr[k]); } } } } } /* lpmex('set_obj_fn', lp_handle, vec) Sparse or Full arguments */ else if (strcmp("set_obj_fn",cmd)==0) { if (nrhs != 3) { mexErrMsgTxt("set_obj_fn requires 2 arguments."); } vec = mxCalloc(1+lp[h]->columns,sizeof(REAL)); /* GetRealVector can handle both full and sparse matrix */ GetRealVector(prhs[2],vec,lp[h]->columns); set_obj_fn(lp[h],vec); mxFree(vec); } /* lpmex('set_rh', lp_handle, row, value) */ else if (strcmp("set_rh",cmd)==0) { if (nrhs != 4) { mexErrMsgTxt("set_rh requires 3 arguments."); } row = GetRealScalar(prhs[2]); value = GetRealScalar(prhs[3]); set_rh(lp[h],row,value); } /* lpmex('set_rh_vec', lp_handle, vec) Sparse of Full arguments */ else if (strcmp("set_rh_vec",cmd)==0) { if (nrhs != 3) { mexErrMsgTxt("set_rh_vec requires 2 arguments."); } vec = mxCalloc(1+lp[h]->rows,sizeof(REAL)); /* GetRealVector can handle both full and sparse matrix */ GetRealVector(prhs[2],vec,lp[h]->rows); set_rh_vec(lp[h],vec); mxFree(vec); } /* lpmex('write_LP', lp_handle, filename) */ /* Write lp to a LP file */ else if (strcmp("write_LP",cmd)==0) { if (nrhs != 3) { mexErrMsgTxt("write_LP requires 2 arguments."); } mxGetString(prhs[2], filename, NAMELEN); if ((fp = fopen(filename, "w")) == NULL) { mexErrMsgTxt("write_LP can't write to the file."); } write_LP(lp[h], fp); fclose(fp); } /* lpmex('write_MPS', lp_handle, filename) */ /* Write lp to a MPS file */ else if (strcmp("write_MPS",cmd)==0) { if (nrhs != 3) { mexErrMsgTxt("write_MPS requires 2 arguments."); } mxGetString(prhs[2], filename, NAMELEN); if ((fp = fopen(filename, "w")) == NULL) { mexErrMsgTxt("write_MPS can't write to the file."); } write_MPS(lp[h], fp); fclose(fp); }/* functions with at least three arguments */ else if (nrhs < 4 ) { strcpy(errmsg,cmd); strncat(errmsg,": Unimplemented or requires at least 3 arguments.",180); mexErrMsgTxt(errmsg); } /* [value] = lpmex('mat_elm',lp_handle,row,col) get a single element from the matrix.*/ else if (strcmp("mat_elm",cmd)==0) { if (nrhs != 4) { mexErrMsgTxt("mat_elm needs 3 arguments."); } row = GetRealScalar(prhs[2]); if ((row < 1) || (row > lp[h]->rows)) { mexErrMsgTxt("row number out of bounds."); } col = GetRealScalar(prhs[3]); if ((col < 1) && (col > lp[h]->columns)) { mexErrMsgTxt("column number out of bounds."); } plhs[0] = mxCreateDoubleMatrix(1,1,0); pr = mxGetPr(plhs[0]); pr[0] = mat_elm(lp[h],row,col); } /* lpmex('set_constr_type', lp_handle, row, type) */ else if (strcmp("set_constr_type",cmd)==0) { if (nrhs != 4) { mexErrMsgTxt("set_constr_type needs 3 arguments."); } row = GetRealScalar(prhs[2]); if ((row < 1) || (row > lp[h]->rows)) { mexErrMsgTxt("row number out of bounds."); } type = GetRealScalar(prhs[3]); if ((type!=EQ) && (type!=LE) && (type!=GE)) { mexErrMsgTxt("invalid constraint type."); } set_constr_type(lp[h],row,type); } /* lpmex('set_int', lp_handle, col, type) */ else if (strcmp("set_int",cmd)==0) { if (nrhs != 4) { mexErrMsgTxt("set_int requires 3 arguments."); } col = GetRealScalar(prhs[2]); type = GetRealScalar(prhs[3]); if (type == 0) set_int(lp[h],col,FALSE); else set_int(lp[h],col,TRUE); } /* lpmex('set_lowbo', lp_handle, col,value) */ else if (strcmp("set_lowbo",cmd)==0) { if (nrhs != 4) { mexErrMsgTxt("set_lowbo requires 3 arguments."); } col = GetRealScalar(prhs[2]); value = GetRealScalar(prhs[3]); set_lowbo(lp[h],col,value); } /* lpmex('set_upbo', lp_handle, col, value) */ else if (strcmp("set_upbo",cmd)==0) { if (nrhs != 4) { mexErrMsgTxt("set_upbo requires 3 arguments."); } col = GetRealScalar(prhs[2]); value = GetRealScalar(prhs[3]); set_upbo(lp[h],col,value); }/* functions with more than three arguments */ else if (nrhs < 5 ) { strcpy(errmsg,cmd); strncat(errmsg,": Unimplemented or requires at least 4 arguments.",180); mexErrMsgTxt(errmsg); } /* lpmex('add_constraint', lp_handle, vec, type, rh) Sparse or Full arguments */ else if (strcmp("add_constraint", cmd)==0) { if (nrhs != 5) { mexErrMsgTxt("add_constraint requires 4 arguments."); } type = GetRealScalar(prhs[3]); if ((type!=LE) && (type!=EQ) && (type!=GE)) { mexErrMsgTxt("invalid constraint type."); } value = GetRealScalar(prhs[4]); vec = mxCalloc(1+lp[h]->columns,sizeof(REAL)); /* GetRealVector can handle both full and sparse matrix */ GetRealVector(prhs[2],vec,lp[h]->columns); add_constraint(lp[h],vec,type,value); mxFree(vec); } else { strcpy(errmsg,cmd); strncat(errmsg,": Unimplemented.",180); mexErrMsgTxt(errmsg); }}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -