void find_interior_DS(int nlhs, mxArray * plhs[], int nrhs, const mxArray * prhs[]) { /* uses Dual Simplex method */ /* We would like to find an iterior point for a polyhedron in H representation A x <= b. */ dd_ErrorType error=dd_NoError; dd_LPSolverType solver=dd_DualSimplex; dd_LPPtr lp, lp1; /* pointer to LP data structure that is not visible by user. */ dd_MatrixPtr A; int j; dd_set_global_constants(); /* First, this must be called once to use cddlib. */ /* Input an LP using the cdd library */ /* lp = MB_get_LP_MatrixPtr(prhs[0]); */ if (A=FT_get_H_MatrixPtr(prhs[0])) { /* set objective */ A->objective = dd_LPmin; for (j = 0; j < A->colsize; j++) dd_set_d(A->rowvec[j],0.0); lp=dd_Matrix2LP(A, &error); dd_FreeMatrix(A); }else{ mexErrMsgTxt("Error in the setting of LP matrix."); } lp1=dd_MakeLPforInteriorFinding(lp); dd_LPSolve(lp1,solver,&error); if (error!=dd_NoError) dd_WriteErrorMessages(stdout, error); /* Take the solution. */ plhs[0] = MB_set_LPsol_MatrixPtr(lp1); /* Free allocated spaces. */ dd_FreeLPData(lp); dd_FreeLPData(lp1); }
int main(int argc, char *argv[]) { /* The original LP data m x n matrix = | b -A | | c0 c^T |, where the LP to be solved is to maximize c^T x + c0 subj. to A x <= b. */ dd_ErrorType err=dd_NoError; dd_LPSolverType solver=dd_DualSimplex; /* either DualSimplex or CrissCross */ dd_LPPtr lp,lp1; /* pointer to LP data structure that is not visible by user. */ dd_LPSolutionPtr lps,lps1; /* pointer to LP solution data that is visible by user. */ dd_MatrixPtr M; dd_colrange j; dd_DataFileType inputfile; dd_set_global_constants(); printf("\n--- Solving an LP with dd_LPSolve, and Finding an Interior Point ---\n"); /* Input an LP using the cdd library */ dd_SetInputFile(&reading,inputfile,&err); if (err!=dd_NoError) goto _L99; M=dd_PolyFile2Matrix(reading, &err); if (err!=dd_NoError) goto _L99; /* dd_WriteMatrix(stdout, M); */ lp=dd_Matrix2LP(M, &err); if (err!=dd_NoError) goto _L99; /* Solve the LP by cdd LP solver. */ printf("\n--- Running dd_LPSolve ---\n"); solver=dd_DualSimplex; dd_LPSolve(lp, solver, &err); /* Solve the LP */ if (err!=dd_NoError) goto _L99; /* Write the LP solutions by cdd LP reporter. */ /* dd_WriteLPResult(stdout, lp, err); */ /* dd_WriteLPResult(writing, lp, err); */ /* One can access the solutions by loading them. See dd_WriteLPResult for outputing the results correctly. */ lps=dd_CopyLPSolution(lp); if (lps->LPS==dd_Optimal){ printf("Optimal solution found:\n"); printf(" primal_solution\n"); for (j=1; j<lps->d; j++) { printf(" %3ld : ",j); dd_WriteNumber(stdout,lps->sol[j]); printf("\n"); } printf(" dual_solution\n"); for (j=1; j<lps->d; j++){ if (lps->nbindex[j+1]>0) { printf(" %3ld : ",lps->nbindex[j+1]); dd_WriteNumber(stdout,lps->dsol[j]); printf("\n"); } } printf(" optimal_value : "); dd_WriteNumber(stdout,lps->optvalue); printf("\n"); } /* Find an interior point with cdd LP library. */ printf("\n--- Running dd_FindInteriorPoint ---\n"); lp1=dd_MakeLPforInteriorFinding(lp); printf("The LP to be solved for finding an interior point:\n"); dd_WriteLP(stdout,lp1); dd_LPSolve(lp1,solver,&err); if (err!=dd_NoError) goto _L99; /* Write an interior point. */ lps1=dd_CopyLPSolution(lp1); if (dd_Positive(lps1->optvalue)){ printf("\nAn interior point found: ("); for (j=1; j <(lps1->d)-1; j++) { dd_WriteNumber(stdout,lps1->sol[j]); } printf(")\n"); } if (dd_Negative(lps1->optvalue)) printf("\nThe feasible region is empty.\n"); if (dd_EqualToZero(lps1->optvalue)) printf("\nThe feasible region is nonempty but has no interior point.\n"); /* Free allocated spaces. */ dd_FreeLPSolution(lps); dd_FreeLPData(lp); dd_FreeLPSolution(lps1); dd_FreeLPData(lp1); dd_FreeMatrix(M); _L99:; if (err!=dd_NoError) dd_WriteErrorMessages(stdout, err); dd_free_global_constants(); /* At the end, this should be called. */ return 0; }