alpar@1: /* glpnpp.h (LP/MIP preprocessor) */ 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 GLPNPP_H alpar@1: #define GLPNPP_H alpar@1: alpar@1: #include "glpapi.h" alpar@1: alpar@1: typedef struct NPP NPP; alpar@1: typedef struct NPPROW NPPROW; alpar@1: typedef struct NPPCOL NPPCOL; alpar@1: typedef struct NPPAIJ NPPAIJ; alpar@1: typedef struct NPPTSE NPPTSE; alpar@1: typedef struct NPPLFE NPPLFE; alpar@1: alpar@1: struct NPP alpar@1: { /* LP/MIP preprocessor workspace */ alpar@1: /*--------------------------------------------------------------*/ alpar@1: /* original problem segment */ alpar@1: int orig_dir; alpar@1: /* optimization direction flag: alpar@1: GLP_MIN - minimization alpar@1: GLP_MAX - maximization */ alpar@1: int orig_m; alpar@1: /* number of rows */ alpar@1: int orig_n; alpar@1: /* number of columns */ alpar@1: int orig_nnz; alpar@1: /* number of non-zero constraint coefficients */ alpar@1: /*--------------------------------------------------------------*/ alpar@1: /* transformed problem segment (always minimization) */ alpar@1: DMP *pool; alpar@1: /* memory pool to store problem components */ 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: double c0; alpar@1: /* constant term of the objective function */ alpar@1: int nrows; alpar@1: /* number of rows introduced into the problem; this count alpar@1: increases by one every time a new row is added and never alpar@1: decreases; thus, actual number of rows may be less than nrows alpar@1: due to row deletions */ alpar@1: int ncols; alpar@1: /* number of columns introduced into the problem; this count alpar@1: increases by one every time a new column is added and never alpar@1: decreases; thus, actual number of column may be less than alpar@1: ncols due to column deletions */ alpar@1: NPPROW *r_head; alpar@1: /* pointer to the beginning of the row list */ alpar@1: NPPROW *r_tail; alpar@1: /* pointer to the end of the row list */ alpar@1: NPPCOL *c_head; alpar@1: /* pointer to the beginning of the column list */ alpar@1: NPPCOL *c_tail; alpar@1: /* pointer to the end of the column list */ alpar@1: /*--------------------------------------------------------------*/ alpar@1: /* transformation history */ alpar@1: DMP *stack; alpar@1: /* memory pool to store transformation entries */ alpar@1: NPPTSE *top; alpar@1: /* pointer to most recent transformation entry */ alpar@1: #if 0 /* 16/XII-2009 */ alpar@1: int count[1+25]; alpar@1: /* transformation statistics */ alpar@1: #endif alpar@1: /*--------------------------------------------------------------*/ alpar@1: /* resultant (preprocessed) problem segment */ alpar@1: int m; alpar@1: /* number of rows */ alpar@1: int n; alpar@1: /* number of columns */ alpar@1: int nnz; alpar@1: /* number of non-zero constraint coefficients */ alpar@1: int *row_ref; /* int row_ref[1+m]; */ alpar@1: /* row_ref[i], 1 <= i <= m, is the reference number assigned to alpar@1: a row, which is i-th row of the resultant problem */ alpar@1: int *col_ref; /* int col_ref[1+n]; */ alpar@1: /* col_ref[j], 1 <= j <= n, is the reference number assigned to alpar@1: a column, which is j-th column of the resultant problem */ alpar@1: /*--------------------------------------------------------------*/ alpar@1: /* recovered solution segment */ alpar@1: int sol; alpar@1: /* solution indicator: alpar@1: GLP_SOL - basic solution alpar@1: GLP_IPT - interior-point solution alpar@1: GLP_MIP - mixed integer solution */ alpar@1: int scaling; alpar@1: /* scaling option: alpar@1: GLP_OFF - scaling is disabled alpar@1: GLP_ON - scaling is enabled */ alpar@1: int p_stat; alpar@1: /* status of primal basic solution: 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 d_stat; alpar@1: /* status of dual basic solution: 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: int t_stat; alpar@1: /* status of interior-point solution: alpar@1: GLP_UNDEF - interior solution is undefined alpar@1: GLP_OPT - interior solution is optimal */ alpar@1: int i_stat; alpar@1: /* status of mixed integer solution: 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: char *r_stat; /* char r_stat[1+nrows]; */ alpar@1: /* r_stat[i], 1 <= i <= nrows, is status of i-th row: alpar@1: GLP_BS - inactive constraint alpar@1: GLP_NL - active constraint on lower bound alpar@1: GLP_NU - active constraint on upper bound alpar@1: GLP_NF - active free row alpar@1: GLP_NS - active equality constraint */ alpar@1: char *c_stat; /* char c_stat[1+nrows]; */ alpar@1: /* c_stat[j], 1 <= j <= nrows, is status of j-th column: 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: double *r_pi; /* double r_pi[1+nrows]; */ alpar@1: /* r_pi[i], 1 <= i <= nrows, is Lagrange multiplier (dual value) alpar@1: for i-th row (constraint) */ alpar@1: double *c_value; /* double c_value[1+ncols]; */ alpar@1: /* c_value[j], 1 <= j <= ncols, is primal value of j-th column alpar@1: (structural variable) */ alpar@1: }; alpar@1: alpar@1: struct NPPROW alpar@1: { /* row (constraint) */ alpar@1: int i; alpar@1: /* reference number assigned to the row, 1 <= i <= nrows */ alpar@1: char *name; alpar@1: /* row name (1 to 255 chars); NULL means no name is assigned to alpar@1: the row */ alpar@1: double lb; alpar@1: /* lower bound; -DBL_MAX means the row has no lower bound */ alpar@1: double ub; alpar@1: /* upper bound; +DBL_MAX means the row has no upper bound */ alpar@1: NPPAIJ *ptr; alpar@1: /* pointer to the linked list of constraint coefficients */ alpar@1: int temp; alpar@1: /* working field used by preprocessor routines */ alpar@1: NPPROW *prev; alpar@1: /* pointer to previous row in the row list */ alpar@1: NPPROW *next; alpar@1: /* pointer to next row in the row list */ alpar@1: }; alpar@1: alpar@1: struct NPPCOL alpar@1: { /* column (variable) */ alpar@1: int j; alpar@1: /* reference number assigned to the column, 1 <= j <= ncols */ alpar@1: char *name; alpar@1: /* column name (1 to 255 chars); NULL means no name is assigned alpar@1: to the column */ alpar@1: char is_int; alpar@1: /* 0 means continuous variable; 1 means integer variable */ alpar@1: double lb; alpar@1: /* lower bound; -DBL_MAX means the column has no lower bound */ alpar@1: double ub; alpar@1: /* upper bound; +DBL_MAX means the column has no upper bound */ alpar@1: double coef; alpar@1: /* objective coefficient */ alpar@1: NPPAIJ *ptr; alpar@1: /* pointer to the linked list of constraint coefficients */ alpar@1: int temp; alpar@1: /* working field used by preprocessor routines */ alpar@1: #if 1 /* 28/XII-2009 */ alpar@1: union alpar@1: { double ll; alpar@1: /* implied column lower bound */ alpar@1: int pos; alpar@1: /* vertex ordinal number corresponding to this binary column alpar@1: in the conflict graph (0, if the vertex does not exist) */ alpar@1: } ll; alpar@1: union alpar@1: { double uu; alpar@1: /* implied column upper bound */ alpar@1: int neg; alpar@1: /* vertex ordinal number corresponding to complement of this alpar@1: binary column in the conflict graph (0, if the vertex does alpar@1: not exist) */ alpar@1: } uu; alpar@1: #endif alpar@1: NPPCOL *prev; alpar@1: /* pointer to previous column in the column list */ alpar@1: NPPCOL *next; alpar@1: /* pointer to next column in the column list */ alpar@1: }; alpar@1: alpar@1: struct NPPAIJ alpar@1: { /* constraint coefficient */ alpar@1: NPPROW *row; alpar@1: /* pointer to corresponding row */ alpar@1: NPPCOL *col; alpar@1: /* pointer to corresponding column */ alpar@1: double val; alpar@1: /* (non-zero) coefficient value */ alpar@1: NPPAIJ *r_prev; alpar@1: /* pointer to previous coefficient in the same row */ alpar@1: NPPAIJ *r_next; alpar@1: /* pointer to next coefficient in the same row */ alpar@1: NPPAIJ *c_prev; alpar@1: /* pointer to previous coefficient in the same column */ alpar@1: NPPAIJ *c_next; alpar@1: /* pointer to next coefficient in the same column */ alpar@1: }; alpar@1: alpar@1: struct NPPTSE alpar@1: { /* transformation stack entry */ alpar@1: int (*func)(NPP *npp, void *info); alpar@1: /* pointer to routine performing back transformation */ alpar@1: void *info; alpar@1: /* pointer to specific info (depends on the transformation) */ alpar@1: NPPTSE *link; alpar@1: /* pointer to another entry created *before* this entry */ alpar@1: }; alpar@1: alpar@1: struct NPPLFE alpar@1: { /* linear form element */ alpar@1: int ref; alpar@1: /* row/column reference number */ alpar@1: double val; alpar@1: /* (non-zero) coefficient value */ alpar@1: NPPLFE *next; alpar@1: /* pointer to another element */ alpar@1: }; alpar@1: alpar@1: #define npp_create_wksp _glp_npp_create_wksp alpar@1: NPP *npp_create_wksp(void); alpar@1: /* create LP/MIP preprocessor workspace */ alpar@1: alpar@1: #define npp_insert_row _glp_npp_insert_row alpar@1: void npp_insert_row(NPP *npp, NPPROW *row, int where); alpar@1: /* insert row to the row list */ alpar@1: alpar@1: #define npp_remove_row _glp_npp_remove_row alpar@1: void npp_remove_row(NPP *npp, NPPROW *row); alpar@1: /* remove row from the row list */ alpar@1: alpar@1: #define npp_activate_row _glp_npp_activate_row alpar@1: void npp_activate_row(NPP *npp, NPPROW *row); alpar@1: /* make row active */ alpar@1: alpar@1: #define npp_deactivate_row _glp_npp_deactivate_row alpar@1: void npp_deactivate_row(NPP *npp, NPPROW *row); alpar@1: /* make row inactive */ alpar@1: alpar@1: #define npp_insert_col _glp_npp_insert_col alpar@1: void npp_insert_col(NPP *npp, NPPCOL *col, int where); alpar@1: /* insert column to the column list */ alpar@1: alpar@1: #define npp_remove_col _glp_npp_remove_col alpar@1: void npp_remove_col(NPP *npp, NPPCOL *col); alpar@1: /* remove column from the column list */ alpar@1: alpar@1: #define npp_activate_col _glp_npp_activate_col alpar@1: void npp_activate_col(NPP *npp, NPPCOL *col); alpar@1: /* make column active */ alpar@1: alpar@1: #define npp_deactivate_col _glp_npp_deactivate_col alpar@1: void npp_deactivate_col(NPP *npp, NPPCOL *col); alpar@1: /* make column inactive */ alpar@1: alpar@1: #define npp_add_row _glp_npp_add_row alpar@1: NPPROW *npp_add_row(NPP *npp); alpar@1: /* add new row to the current problem */ alpar@1: alpar@1: #define npp_add_col _glp_npp_add_col alpar@1: NPPCOL *npp_add_col(NPP *npp); alpar@1: /* add new column to the current problem */ alpar@1: alpar@1: #define npp_add_aij _glp_npp_add_aij alpar@1: NPPAIJ *npp_add_aij(NPP *npp, NPPROW *row, NPPCOL *col, double val); alpar@1: /* add new element to the constraint matrix */ alpar@1: alpar@1: #define npp_row_nnz _glp_npp_row_nnz alpar@1: int npp_row_nnz(NPP *npp, NPPROW *row); alpar@1: /* count number of non-zero coefficients in row */ alpar@1: alpar@1: #define npp_col_nnz _glp_npp_col_nnz alpar@1: int npp_col_nnz(NPP *npp, NPPCOL *col); alpar@1: /* count number of non-zero coefficients in column */ alpar@1: alpar@1: #define npp_push_tse _glp_npp_push_tse alpar@1: void *npp_push_tse(NPP *npp, int (*func)(NPP *npp, void *info), alpar@1: int size); alpar@1: /* push new entry to the transformation stack */ alpar@1: alpar@1: #define npp_erase_row _glp_npp_erase_row alpar@1: void npp_erase_row(NPP *npp, NPPROW *row); alpar@1: /* erase row content to make it empty */ alpar@1: alpar@1: #define npp_del_row _glp_npp_del_row alpar@1: void npp_del_row(NPP *npp, NPPROW *row); alpar@1: /* remove row from the current problem */ alpar@1: alpar@1: #define npp_del_col _glp_npp_del_col alpar@1: void npp_del_col(NPP *npp, NPPCOL *col); alpar@1: /* remove column from the current problem */ alpar@1: alpar@1: #define npp_del_aij _glp_npp_del_aij alpar@1: void npp_del_aij(NPP *npp, NPPAIJ *aij); alpar@1: /* remove element from the constraint matrix */ alpar@1: alpar@1: #define npp_load_prob _glp_npp_load_prob alpar@1: void npp_load_prob(NPP *npp, glp_prob *orig, int names, int sol, alpar@1: int scaling); alpar@1: /* load original problem into the preprocessor workspace */ alpar@1: alpar@1: #define npp_build_prob _glp_npp_build_prob alpar@1: void npp_build_prob(NPP *npp, glp_prob *prob); alpar@1: /* build resultant (preprocessed) problem */ alpar@1: alpar@1: #define npp_postprocess _glp_npp_postprocess alpar@1: void npp_postprocess(NPP *npp, glp_prob *prob); alpar@1: /* postprocess solution from the resultant problem */ alpar@1: alpar@1: #define npp_unload_sol _glp_npp_unload_sol alpar@1: void npp_unload_sol(NPP *npp, glp_prob *orig); alpar@1: /* store solution to the original problem */ alpar@1: alpar@1: #define npp_delete_wksp _glp_npp_delete_wksp alpar@1: void npp_delete_wksp(NPP *npp); alpar@1: /* delete LP/MIP preprocessor workspace */ alpar@1: alpar@1: #define npp_error() alpar@1: alpar@1: #define npp_free_row _glp_npp_free_row alpar@1: void npp_free_row(NPP *npp, NPPROW *p); alpar@1: /* process free (unbounded) row */ alpar@1: alpar@1: #define npp_geq_row _glp_npp_geq_row alpar@1: void npp_geq_row(NPP *npp, NPPROW *p); alpar@1: /* process row of 'not less than' type */ alpar@1: alpar@1: #define npp_leq_row _glp_npp_leq_row alpar@1: void npp_leq_row(NPP *npp, NPPROW *p); alpar@1: /* process row of 'not greater than' type */ alpar@1: alpar@1: #define npp_free_col _glp_npp_free_col alpar@1: void npp_free_col(NPP *npp, NPPCOL *q); alpar@1: /* process free (unbounded) column */ alpar@1: alpar@1: #define npp_lbnd_col _glp_npp_lbnd_col alpar@1: void npp_lbnd_col(NPP *npp, NPPCOL *q); alpar@1: /* process column with (non-zero) lower bound */ alpar@1: alpar@1: #define npp_ubnd_col _glp_npp_ubnd_col alpar@1: void npp_ubnd_col(NPP *npp, NPPCOL *q); alpar@1: /* process column with upper bound */ alpar@1: alpar@1: #define npp_dbnd_col _glp_npp_dbnd_col alpar@1: void npp_dbnd_col(NPP *npp, NPPCOL *q); alpar@1: /* process non-negative column with upper bound */ alpar@1: alpar@1: #define npp_fixed_col _glp_npp_fixed_col alpar@1: void npp_fixed_col(NPP *npp, NPPCOL *q); alpar@1: /* process fixed column */ alpar@1: alpar@1: #define npp_make_equality _glp_npp_make_equality alpar@1: int npp_make_equality(NPP *npp, NPPROW *p); alpar@1: /* process row with almost identical bounds */ alpar@1: alpar@1: #define npp_make_fixed _glp_npp_make_fixed alpar@1: int npp_make_fixed(NPP *npp, NPPCOL *q); alpar@1: /* process column with almost identical bounds */ alpar@1: alpar@1: #define npp_empty_row _glp_npp_empty_row alpar@1: int npp_empty_row(NPP *npp, NPPROW *p); alpar@1: /* process empty row */ alpar@1: alpar@1: #define npp_empty_col _glp_npp_empty_col alpar@1: int npp_empty_col(NPP *npp, NPPCOL *q); alpar@1: /* process empty column */ alpar@1: alpar@1: #define npp_implied_value _glp_npp_implied_value alpar@1: int npp_implied_value(NPP *npp, NPPCOL *q, double s); alpar@1: /* process implied column value */ alpar@1: alpar@1: #define npp_eq_singlet _glp_npp_eq_singlet alpar@1: int npp_eq_singlet(NPP *npp, NPPROW *p); alpar@1: /* process row singleton (equality constraint) */ alpar@1: alpar@1: #define npp_implied_lower _glp_npp_implied_lower alpar@1: int npp_implied_lower(NPP *npp, NPPCOL *q, double l); alpar@1: /* process implied column lower bound */ alpar@1: alpar@1: #define npp_implied_upper _glp_npp_implied_upper alpar@1: int npp_implied_upper(NPP *npp, NPPCOL *q, double u); alpar@1: /* process implied upper bound of column */ alpar@1: alpar@1: #define npp_ineq_singlet _glp_npp_ineq_singlet alpar@1: int npp_ineq_singlet(NPP *npp, NPPROW *p); alpar@1: /* process row singleton (inequality constraint) */ alpar@1: alpar@1: #define npp_implied_slack _glp_npp_implied_slack alpar@1: void npp_implied_slack(NPP *npp, NPPCOL *q); alpar@1: /* process column singleton (implied slack variable) */ alpar@1: alpar@1: #define npp_implied_free _glp_npp_implied_free alpar@1: int npp_implied_free(NPP *npp, NPPCOL *q); alpar@1: /* process column singleton (implied free variable) */ alpar@1: alpar@1: #define npp_eq_doublet _glp_npp_eq_doublet alpar@1: NPPCOL *npp_eq_doublet(NPP *npp, NPPROW *p); alpar@1: /* process row doubleton (equality constraint) */ alpar@1: alpar@1: #define npp_forcing_row _glp_npp_forcing_row alpar@1: int npp_forcing_row(NPP *npp, NPPROW *p, int at); alpar@1: /* process forcing row */ alpar@1: alpar@1: #define npp_analyze_row _glp_npp_analyze_row alpar@1: int npp_analyze_row(NPP *npp, NPPROW *p); alpar@1: /* perform general row analysis */ alpar@1: alpar@1: #define npp_inactive_bound _glp_npp_inactive_bound alpar@1: void npp_inactive_bound(NPP *npp, NPPROW *p, int which); alpar@1: /* remove row lower/upper inactive bound */ alpar@1: alpar@1: #define npp_implied_bounds _glp_npp_implied_bounds alpar@1: void npp_implied_bounds(NPP *npp, NPPROW *p); alpar@1: /* determine implied column bounds */ alpar@1: alpar@1: #define npp_binarize_prob _glp_npp_binarize_prob alpar@1: int npp_binarize_prob(NPP *npp); alpar@1: /* binarize MIP problem */ alpar@1: alpar@1: #define npp_is_packing _glp_npp_is_packing alpar@1: int npp_is_packing(NPP *npp, NPPROW *row); alpar@1: /* test if constraint is packing inequality */ alpar@1: alpar@1: #define npp_hidden_packing _glp_npp_hidden_packing alpar@1: int npp_hidden_packing(NPP *npp, NPPROW *row); alpar@1: /* identify hidden packing inequality */ alpar@1: alpar@1: #define npp_implied_packing _glp_npp_implied_packing alpar@1: int npp_implied_packing(NPP *npp, NPPROW *row, int which, alpar@1: NPPCOL *var[], char set[]); alpar@1: /* identify implied packing inequality */ alpar@1: alpar@1: #define npp_is_covering _glp_npp_is_covering alpar@1: int npp_is_covering(NPP *npp, NPPROW *row); alpar@1: /* test if constraint is covering inequality */ alpar@1: alpar@1: #define npp_hidden_covering _glp_npp_hidden_covering alpar@1: int npp_hidden_covering(NPP *npp, NPPROW *row); alpar@1: /* identify hidden covering inequality */ alpar@1: alpar@1: #define npp_is_partitioning _glp_npp_is_partitioning alpar@1: int npp_is_partitioning(NPP *npp, NPPROW *row); alpar@1: /* test if constraint is partitioning equality */ alpar@1: alpar@1: #define npp_reduce_ineq_coef _glp_npp_reduce_ineq_coef alpar@1: int npp_reduce_ineq_coef(NPP *npp, NPPROW *row); alpar@1: /* reduce inequality constraint coefficients */ alpar@1: alpar@1: #define npp_clean_prob _glp_npp_clean_prob alpar@1: void npp_clean_prob(NPP *npp); alpar@1: /* perform initial LP/MIP processing */ alpar@1: alpar@1: #define npp_process_row _glp_npp_process_row alpar@1: int npp_process_row(NPP *npp, NPPROW *row, int hard); alpar@1: /* perform basic row processing */ alpar@1: alpar@1: #define npp_improve_bounds _glp_npp_improve_bounds alpar@1: int npp_improve_bounds(NPP *npp, NPPROW *row, int flag); alpar@1: /* improve current column bounds */ alpar@1: alpar@1: #define npp_process_col _glp_npp_process_col alpar@1: int npp_process_col(NPP *npp, NPPCOL *col); alpar@1: /* perform basic column processing */ alpar@1: alpar@1: #define npp_process_prob _glp_npp_process_prob alpar@1: int npp_process_prob(NPP *npp, int hard); alpar@1: /* perform basic LP/MIP processing */ alpar@1: alpar@1: #define npp_simplex _glp_npp_simplex alpar@1: int npp_simplex(NPP *npp, const glp_smcp *parm); alpar@1: /* process LP prior to applying primal/dual simplex method */ alpar@1: alpar@1: #define npp_integer _glp_npp_integer alpar@1: int npp_integer(NPP *npp, const glp_iocp *parm); alpar@1: /* process MIP prior to applying branch-and-bound method */ alpar@1: alpar@1: #endif alpar@1: alpar@1: /* eof */