alpar@1: /* glpapi.h (application program interface) */ alpar@1: alpar@1: /*********************************************************************** alpar@1: * This code is part of GLPK (GNU Linear Programming Kit). alpar@1: * alpar@1: * Copyright (C) 2000, 2001, 2002, 2003, 2004, 2005, 2006, 2007, 2008, alpar@1: * 2009, 2010 Andrew Makhorin, Department for Applied Informatics, alpar@1: * Moscow Aviation Institute, Moscow, Russia. All rights reserved. alpar@1: * E-mail: . alpar@1: * alpar@1: * GLPK is free software: you can redistribute it and/or modify it alpar@1: * under the terms of the GNU General Public License as published by alpar@1: * the Free Software Foundation, either version 3 of the License, or alpar@1: * (at your option) any later version. alpar@1: * alpar@1: * GLPK is distributed in the hope that it will be useful, but WITHOUT alpar@1: * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY alpar@1: * or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public alpar@1: * License for more details. alpar@1: * alpar@1: * You should have received a copy of the GNU General Public License alpar@1: * along with GLPK. If not, see . alpar@1: ***********************************************************************/ alpar@1: alpar@1: #ifndef GLPAPI_H alpar@1: #define GLPAPI_H alpar@1: alpar@1: #define GLP_PROB_DEFINED alpar@1: typedef struct glp_prob glp_prob; alpar@1: alpar@1: #include "glpk.h" alpar@1: #include "glpavl.h" alpar@1: #include "glpbfd.h" alpar@1: alpar@1: typedef struct GLPROW GLPROW; alpar@1: typedef struct GLPCOL GLPCOL; alpar@1: typedef struct GLPAIJ GLPAIJ; alpar@1: alpar@1: #define GLP_PROB_MAGIC 0xD7D9D6C2 alpar@1: alpar@1: struct glp_prob alpar@1: { /* LP/MIP problem object */ alpar@1: int magic; alpar@1: /* magic value used for debugging */ alpar@1: DMP *pool; alpar@1: /* memory pool to store problem object components */ alpar@1: glp_tree *tree; alpar@1: /* pointer to the search tree; set by the MIP solver when this alpar@1: object is used in the tree as a core MIP object */ alpar@1: void *parms; alpar@1: /* reserved for backward compatibility */ alpar@1: /*--------------------------------------------------------------*/ alpar@1: /* LP/MIP data */ alpar@1: char *name; alpar@1: /* problem name (1 to 255 chars); NULL means no name is assigned alpar@1: to the problem */ alpar@1: char *obj; alpar@1: /* objective function name (1 to 255 chars); NULL means no name alpar@1: is assigned to the objective function */ alpar@1: int dir; alpar@1: /* optimization direction flag (objective "sense"): alpar@1: GLP_MIN - minimization alpar@1: GLP_MAX - maximization */ alpar@1: double c0; alpar@1: /* constant term of the objective function ("shift") */ alpar@1: int m_max; alpar@1: /* length of the array of rows (enlarged automatically) */ alpar@1: int n_max; alpar@1: /* length of the array of columns (enlarged automatically) */ alpar@1: int m; alpar@1: /* number of rows, 0 <= m <= m_max */ alpar@1: int n; alpar@1: /* number of columns, 0 <= n <= n_max */ alpar@1: int nnz; alpar@1: /* number of non-zero constraint coefficients, nnz >= 0 */ alpar@1: GLPROW **row; /* GLPROW *row[1+m_max]; */ alpar@1: /* row[i], 1 <= i <= m, is a pointer to i-th row */ alpar@1: GLPCOL **col; /* GLPCOL *col[1+n_max]; */ alpar@1: /* col[j], 1 <= j <= n, is a pointer to j-th column */ alpar@1: AVL *r_tree; alpar@1: /* row index to find rows by their names; NULL means this index alpar@1: does not exist */ alpar@1: AVL *c_tree; alpar@1: /* column index to find columns by their names; NULL means this alpar@1: index does not exist */ alpar@1: /*--------------------------------------------------------------*/ alpar@1: /* basis factorization (LP) */ alpar@1: int valid; alpar@1: /* the factorization is valid only if this flag is set */ alpar@1: int *head; /* int head[1+m_max]; */ alpar@1: /* basis header (valid only if the factorization is valid); alpar@1: head[i] = k is the ordinal number of auxiliary (1 <= k <= m) alpar@1: or structural (m+1 <= k <= m+n) variable which corresponds to alpar@1: i-th basic variable xB[i], 1 <= i <= m */ alpar@1: glp_bfcp *bfcp; alpar@1: /* basis factorization control parameters; may be NULL */ alpar@1: BFD *bfd; /* BFD bfd[1:m,1:m]; */ alpar@1: /* basis factorization driver; may be NULL */ alpar@1: /*--------------------------------------------------------------*/ alpar@1: /* basic solution (LP) */ alpar@1: int pbs_stat; alpar@1: /* primal basic solution status: alpar@1: GLP_UNDEF - primal solution is undefined alpar@1: GLP_FEAS - primal solution is feasible alpar@1: GLP_INFEAS - primal solution is infeasible alpar@1: GLP_NOFEAS - no primal feasible solution exists */ alpar@1: int dbs_stat; alpar@1: /* dual basic solution status: alpar@1: GLP_UNDEF - dual solution is undefined alpar@1: GLP_FEAS - dual solution is feasible alpar@1: GLP_INFEAS - dual solution is infeasible alpar@1: GLP_NOFEAS - no dual feasible solution exists */ alpar@1: double obj_val; alpar@1: /* objective function value */ alpar@1: int it_cnt; alpar@1: /* simplex method iteration count; increased by one on performing alpar@1: one simplex iteration */ alpar@1: int some; alpar@1: /* ordinal number of some auxiliary or structural variable having alpar@1: certain property, 0 <= some <= m+n */ alpar@1: /*--------------------------------------------------------------*/ alpar@1: /* interior-point solution (LP) */ alpar@1: int ipt_stat; alpar@1: /* interior-point solution status: alpar@1: GLP_UNDEF - interior solution is undefined alpar@1: GLP_OPT - interior solution is optimal alpar@1: GLP_INFEAS - interior solution is infeasible alpar@1: GLP_NOFEAS - no feasible solution exists */ alpar@1: double ipt_obj; alpar@1: /* objective function value */ alpar@1: /*--------------------------------------------------------------*/ alpar@1: /* integer solution (MIP) */ alpar@1: int mip_stat; alpar@1: /* integer solution status: alpar@1: GLP_UNDEF - integer solution is undefined alpar@1: GLP_OPT - integer solution is optimal alpar@1: GLP_FEAS - integer solution is feasible alpar@1: GLP_NOFEAS - no integer solution exists */ alpar@1: double mip_obj; alpar@1: /* objective function value */ alpar@1: }; alpar@1: alpar@1: struct GLPROW alpar@1: { /* LP/MIP row (auxiliary variable) */ alpar@1: int i; alpar@1: /* ordinal number (1 to m) assigned to this row */ alpar@1: char *name; alpar@1: /* row name (1 to 255 chars); NULL means no name is assigned to alpar@1: this row */ alpar@1: AVLNODE *node; alpar@1: /* pointer to corresponding node in the row index; NULL means alpar@1: that either the row index does not exist or this row has no alpar@1: name assigned */ alpar@1: #if 1 /* 20/IX-2008 */ alpar@1: int level; alpar@1: unsigned char origin; alpar@1: unsigned char klass; alpar@1: #endif alpar@1: int type; alpar@1: /* type of the auxiliary variable: alpar@1: GLP_FR - free variable alpar@1: GLP_LO - variable with lower bound alpar@1: GLP_UP - variable with upper bound alpar@1: GLP_DB - double-bounded variable alpar@1: GLP_FX - fixed variable */ alpar@1: double lb; /* non-scaled */ alpar@1: /* lower bound; if the row has no lower bound, lb is zero */ alpar@1: double ub; /* non-scaled */ alpar@1: /* upper bound; if the row has no upper bound, ub is zero */ alpar@1: /* if the row type is GLP_FX, ub is equal to lb */ alpar@1: GLPAIJ *ptr; /* non-scaled */ alpar@1: /* pointer to doubly linked list of constraint coefficients which alpar@1: are placed in this row */ alpar@1: double rii; alpar@1: /* diagonal element r[i,i] of scaling matrix R for this row; alpar@1: if the scaling is not used, r[i,i] is 1 */ alpar@1: int stat; alpar@1: /* status of the auxiliary variable: alpar@1: GLP_BS - basic variable alpar@1: GLP_NL - non-basic variable on lower bound alpar@1: GLP_NU - non-basic variable on upper bound alpar@1: GLP_NF - non-basic free variable alpar@1: GLP_NS - non-basic fixed variable */ alpar@1: int bind; alpar@1: /* if the auxiliary variable is basic, head[bind] refers to this alpar@1: row, otherwise, bind is 0; this attribute is valid only if the alpar@1: basis factorization is valid */ alpar@1: double prim; /* non-scaled */ alpar@1: /* primal value of the auxiliary variable in basic solution */ alpar@1: double dual; /* non-scaled */ alpar@1: /* dual value of the auxiliary variable in basic solution */ alpar@1: double pval; /* non-scaled */ alpar@1: /* primal value of the auxiliary variable in interior solution */ alpar@1: double dval; /* non-scaled */ alpar@1: /* dual value of the auxiliary variable in interior solution */ alpar@1: double mipx; /* non-scaled */ alpar@1: /* primal value of the auxiliary variable in integer solution */ alpar@1: }; alpar@1: alpar@1: struct GLPCOL alpar@1: { /* LP/MIP column (structural variable) */ alpar@1: int j; alpar@1: /* ordinal number (1 to n) assigned to this column */ alpar@1: char *name; alpar@1: /* column name (1 to 255 chars); NULL means no name is assigned alpar@1: to this column */ alpar@1: AVLNODE *node; alpar@1: /* pointer to corresponding node in the column index; NULL means alpar@1: that either the column index does not exist or the column has alpar@1: no name assigned */ alpar@1: int kind; alpar@1: /* kind of the structural variable: alpar@1: GLP_CV - continuous variable alpar@1: GLP_IV - integer or binary variable */ alpar@1: int type; alpar@1: /* type of the structural variable: alpar@1: GLP_FR - free variable alpar@1: GLP_LO - variable with lower bound alpar@1: GLP_UP - variable with upper bound alpar@1: GLP_DB - double-bounded variable alpar@1: GLP_FX - fixed variable */ alpar@1: double lb; /* non-scaled */ alpar@1: /* lower bound; if the column has no lower bound, lb is zero */ alpar@1: double ub; /* non-scaled */ alpar@1: /* upper bound; if the column has no upper bound, ub is zero */ alpar@1: /* if the column type is GLP_FX, ub is equal to lb */ alpar@1: double coef; /* non-scaled */ alpar@1: /* objective coefficient at the structural variable */ alpar@1: GLPAIJ *ptr; /* non-scaled */ alpar@1: /* pointer to doubly linked list of constraint coefficients which alpar@1: are placed in this column */ alpar@1: double sjj; alpar@1: /* diagonal element s[j,j] of scaling matrix S for this column; alpar@1: if the scaling is not used, s[j,j] is 1 */ alpar@1: int stat; alpar@1: /* status of the structural variable: alpar@1: GLP_BS - basic variable alpar@1: GLP_NL - non-basic variable on lower bound alpar@1: GLP_NU - non-basic variable on upper bound alpar@1: GLP_NF - non-basic free variable alpar@1: GLP_NS - non-basic fixed variable */ alpar@1: int bind; alpar@1: /* if the structural variable is basic, head[bind] refers to alpar@1: this column; otherwise, bind is 0; this attribute is valid only alpar@1: if the basis factorization is valid */ alpar@1: double prim; /* non-scaled */ alpar@1: /* primal value of the structural variable in basic solution */ alpar@1: double dual; /* non-scaled */ alpar@1: /* dual value of the structural variable in basic solution */ alpar@1: double pval; /* non-scaled */ alpar@1: /* primal value of the structural variable in interior solution */ alpar@1: double dval; /* non-scaled */ alpar@1: /* dual value of the structural variable in interior solution */ alpar@1: double mipx; /* non-scaled */ alpar@1: /* primal value of the structural variable in integer solution */ alpar@1: }; alpar@1: alpar@1: struct GLPAIJ alpar@1: { /* constraint coefficient a[i,j] */ alpar@1: GLPROW *row; alpar@1: /* pointer to row, where this coefficient is placed */ alpar@1: GLPCOL *col; alpar@1: /* pointer to column, where this coefficient is placed */ alpar@1: double val; alpar@1: /* numeric (non-zero) value of this coefficient */ alpar@1: GLPAIJ *r_prev; alpar@1: /* pointer to previous coefficient in the same row */ alpar@1: GLPAIJ *r_next; alpar@1: /* pointer to next coefficient in the same row */ alpar@1: GLPAIJ *c_prev; alpar@1: /* pointer to previous coefficient in the same column */ alpar@1: GLPAIJ *c_next; alpar@1: /* pointer to next coefficient in the same column */ alpar@1: }; alpar@1: alpar@1: void _glp_check_kkt(glp_prob *P, int sol, int cond, double *ae_max, alpar@1: int *ae_ind, double *re_max, int *re_ind); alpar@1: /* check feasibility and optimality conditions */ alpar@1: alpar@1: #define lpx_put_solution _glp_put_solution alpar@1: void lpx_put_solution(glp_prob *lp, int inval, const int *p_stat, alpar@1: const int *d_stat, const double *obj_val, const int r_stat[], alpar@1: const double r_prim[], const double r_dual[], const int c_stat[], alpar@1: const double c_prim[], const double c_dual[]); alpar@1: /* store basic solution components */ alpar@1: alpar@1: #define lpx_put_mip_soln _glp_put_mip_soln alpar@1: void lpx_put_mip_soln(LPX *lp, int i_stat, double row_mipx[], alpar@1: double col_mipx[]); alpar@1: /* store mixed integer solution components */ alpar@1: alpar@1: #if 1 /* 28/XI-2009 */ alpar@1: int _glp_analyze_row(glp_prob *P, int len, const int ind[], alpar@1: const double val[], int type, double rhs, double eps, int *_piv, alpar@1: double *_x, double *_dx, double *_y, double *_dy, double *_dz); alpar@1: /* simulate one iteration of dual simplex method */ alpar@1: #endif alpar@1: alpar@1: #if 1 /* 08/XII-2009 */ alpar@1: void _glp_mpl_init_rand(glp_tran *tran, int seed); alpar@1: #endif alpar@1: alpar@1: #define glp_skpgen _glp_skpgen alpar@1: void glp_skpgen(int n, int r, int type, int v, int s, int a[], alpar@1: int *b, int c[]); alpar@1: /* Pisinger's 0-1 single knapsack problem generator */ alpar@1: alpar@1: #if 1 /* 28/V-2010 */ alpar@1: int _glp_intopt1(glp_prob *P, const glp_iocp *parm); alpar@1: #endif alpar@1: alpar@1: #endif alpar@1: alpar@1: /* eof */