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