alpar@1: /* glpnpp02.c */ 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: #include "glpnpp.h" alpar@1: alpar@1: /*********************************************************************** alpar@1: * NAME alpar@1: * alpar@1: * npp_free_row - process free (unbounded) row alpar@1: * alpar@1: * SYNOPSIS alpar@1: * alpar@1: * #include "glpnpp.h" alpar@1: * void npp_free_row(NPP *npp, NPPROW *p); alpar@1: * alpar@1: * DESCRIPTION alpar@1: * alpar@1: * The routine npp_free_row processes row p, which is free (i.e. has alpar@1: * no finite bounds): alpar@1: * alpar@1: * -inf < sum a[p,j] x[j] < +inf. (1) alpar@1: * j alpar@1: * alpar@1: * PROBLEM TRANSFORMATION alpar@1: * alpar@1: * Constraint (1) cannot be active, so it is redundant and can be alpar@1: * removed from the original problem. alpar@1: * alpar@1: * Removing row p leads to removing a column of multiplier pi[p] for alpar@1: * this row in the dual system. Since row p has no bounds, pi[p] = 0, alpar@1: * so removing the column does not affect the dual solution. alpar@1: * alpar@1: * RECOVERING BASIC SOLUTION alpar@1: * alpar@1: * In solution to the original problem row p is inactive constraint, alpar@1: * so it is assigned status GLP_BS, and multiplier pi[p] is assigned alpar@1: * zero value. alpar@1: * alpar@1: * RECOVERING INTERIOR-POINT SOLUTION alpar@1: * alpar@1: * In solution to the original problem row p is inactive constraint, alpar@1: * so its multiplier pi[p] is assigned zero value. alpar@1: * alpar@1: * RECOVERING MIP SOLUTION alpar@1: * alpar@1: * None needed. */ alpar@1: alpar@1: struct free_row alpar@1: { /* free (unbounded) row */ alpar@1: int p; alpar@1: /* row reference number */ alpar@1: }; alpar@1: alpar@1: static int rcv_free_row(NPP *npp, void *info); alpar@1: alpar@1: void npp_free_row(NPP *npp, NPPROW *p) alpar@1: { /* process free (unbounded) row */ alpar@1: struct free_row *info; alpar@1: /* the row must be free */ alpar@1: xassert(p->lb == -DBL_MAX && p->ub == +DBL_MAX); alpar@1: /* create transformation stack entry */ alpar@1: info = npp_push_tse(npp, alpar@1: rcv_free_row, sizeof(struct free_row)); alpar@1: info->p = p->i; alpar@1: /* remove the row from the problem */ alpar@1: npp_del_row(npp, p); alpar@1: return; alpar@1: } alpar@1: alpar@1: static int rcv_free_row(NPP *npp, void *_info) alpar@1: { /* recover free (unbounded) row */ alpar@1: struct free_row *info = _info; alpar@1: if (npp->sol == GLP_SOL) alpar@1: npp->r_stat[info->p] = GLP_BS; alpar@1: if (npp->sol != GLP_MIP) alpar@1: npp->r_pi[info->p] = 0.0; alpar@1: return 0; alpar@1: } alpar@1: alpar@1: /*********************************************************************** alpar@1: * NAME alpar@1: * alpar@1: * npp_geq_row - process row of 'not less than' type alpar@1: * alpar@1: * SYNOPSIS alpar@1: * alpar@1: * #include "glpnpp.h" alpar@1: * void npp_geq_row(NPP *npp, NPPROW *p); alpar@1: * alpar@1: * DESCRIPTION alpar@1: * alpar@1: * The routine npp_geq_row processes row p, which is 'not less than' alpar@1: * inequality constraint: alpar@1: * alpar@1: * L[p] <= sum a[p,j] x[j] (<= U[p]), (1) alpar@1: * j alpar@1: * alpar@1: * where L[p] < U[p], and upper bound may not exist (U[p] = +oo). alpar@1: * alpar@1: * PROBLEM TRANSFORMATION alpar@1: * alpar@1: * Constraint (1) can be replaced by equality constraint: alpar@1: * alpar@1: * sum a[p,j] x[j] - s = L[p], (2) alpar@1: * j alpar@1: * alpar@1: * where alpar@1: * alpar@1: * 0 <= s (<= U[p] - L[p]) (3) alpar@1: * alpar@1: * is a non-negative surplus variable. alpar@1: * alpar@1: * Since in the primal system there appears column s having the only alpar@1: * non-zero coefficient in row p, in the dual system there appears a alpar@1: * new row: alpar@1: * alpar@1: * (-1) pi[p] + lambda = 0, (4) alpar@1: * alpar@1: * where (-1) is coefficient of column s in row p, pi[p] is multiplier alpar@1: * of row p, lambda is multiplier of column q, 0 is coefficient of alpar@1: * column s in the objective row. alpar@1: * alpar@1: * RECOVERING BASIC SOLUTION alpar@1: * alpar@1: * Status of row p in solution to the original problem is determined alpar@1: * by its status and status of column q in solution to the transformed alpar@1: * problem as follows: alpar@1: * alpar@1: * +--------------------------------------+------------------+ alpar@1: * | Transformed problem | Original problem | alpar@1: * +-----------------+--------------------+------------------+ alpar@1: * | Status of row p | Status of column s | Status of row p | alpar@1: * +-----------------+--------------------+------------------+ alpar@1: * | GLP_BS | GLP_BS | N/A | alpar@1: * | GLP_BS | GLP_NL | GLP_BS | alpar@1: * | GLP_BS | GLP_NU | GLP_BS | alpar@1: * | GLP_NS | GLP_BS | GLP_BS | alpar@1: * | GLP_NS | GLP_NL | GLP_NL | alpar@1: * | GLP_NS | GLP_NU | GLP_NU | alpar@1: * +-----------------+--------------------+------------------+ alpar@1: * alpar@1: * Value of row multiplier pi[p] in solution to the original problem alpar@1: * is the same as in solution to the transformed problem. alpar@1: * alpar@1: * 1. In solution to the transformed problem row p and column q cannot alpar@1: * be basic at the same time; otherwise the basis matrix would have alpar@1: * two linear dependent columns: unity column of auxiliary variable alpar@1: * of row p and unity column of variable s. alpar@1: * alpar@1: * 2. Though in the transformed problem row p is equality constraint, alpar@1: * it may be basic due to primal degenerate solution. alpar@1: * alpar@1: * RECOVERING INTERIOR-POINT SOLUTION alpar@1: * alpar@1: * Value of row multiplier pi[p] in solution to the original problem alpar@1: * is the same as in solution to the transformed problem. alpar@1: * alpar@1: * RECOVERING MIP SOLUTION alpar@1: * alpar@1: * None needed. */ alpar@1: alpar@1: struct ineq_row alpar@1: { /* inequality constraint row */ alpar@1: int p; alpar@1: /* row reference number */ alpar@1: int s; alpar@1: /* column reference number for slack/surplus variable */ alpar@1: }; alpar@1: alpar@1: static int rcv_geq_row(NPP *npp, void *info); alpar@1: alpar@1: void npp_geq_row(NPP *npp, NPPROW *p) alpar@1: { /* process row of 'not less than' type */ alpar@1: struct ineq_row *info; alpar@1: NPPCOL *s; alpar@1: /* the row must have lower bound */ alpar@1: xassert(p->lb != -DBL_MAX); alpar@1: xassert(p->lb < p->ub); alpar@1: /* create column for surplus variable */ alpar@1: s = npp_add_col(npp); alpar@1: s->lb = 0.0; alpar@1: s->ub = (p->ub == +DBL_MAX ? +DBL_MAX : p->ub - p->lb); alpar@1: /* and add it to the transformed problem */ alpar@1: npp_add_aij(npp, p, s, -1.0); alpar@1: /* create transformation stack entry */ alpar@1: info = npp_push_tse(npp, alpar@1: rcv_geq_row, sizeof(struct ineq_row)); alpar@1: info->p = p->i; alpar@1: info->s = s->j; alpar@1: /* replace the row by equality constraint */ alpar@1: p->ub = p->lb; alpar@1: return; alpar@1: } alpar@1: alpar@1: static int rcv_geq_row(NPP *npp, void *_info) alpar@1: { /* recover row of 'not less than' type */ alpar@1: struct ineq_row *info = _info; alpar@1: if (npp->sol == GLP_SOL) alpar@1: { if (npp->r_stat[info->p] == GLP_BS) alpar@1: { if (npp->c_stat[info->s] == GLP_BS) alpar@1: { npp_error(); alpar@1: return 1; alpar@1: } alpar@1: else if (npp->c_stat[info->s] == GLP_NL || alpar@1: npp->c_stat[info->s] == GLP_NU) alpar@1: npp->r_stat[info->p] = GLP_BS; alpar@1: else alpar@1: { npp_error(); alpar@1: return 1; alpar@1: } alpar@1: } alpar@1: else if (npp->r_stat[info->p] == GLP_NS) alpar@1: { if (npp->c_stat[info->s] == GLP_BS) alpar@1: npp->r_stat[info->p] = GLP_BS; alpar@1: else if (npp->c_stat[info->s] == GLP_NL) alpar@1: npp->r_stat[info->p] = GLP_NL; alpar@1: else if (npp->c_stat[info->s] == GLP_NU) alpar@1: npp->r_stat[info->p] = GLP_NU; alpar@1: else alpar@1: { npp_error(); alpar@1: return 1; alpar@1: } alpar@1: } alpar@1: else alpar@1: { npp_error(); alpar@1: return 1; alpar@1: } alpar@1: } alpar@1: return 0; alpar@1: } alpar@1: alpar@1: /*********************************************************************** alpar@1: * NAME alpar@1: * alpar@1: * npp_leq_row - process row of 'not greater than' type alpar@1: * alpar@1: * SYNOPSIS alpar@1: * alpar@1: * #include "glpnpp.h" alpar@1: * void npp_leq_row(NPP *npp, NPPROW *p); alpar@1: * alpar@1: * DESCRIPTION alpar@1: * alpar@1: * The routine npp_leq_row processes row p, which is 'not greater than' alpar@1: * inequality constraint: alpar@1: * alpar@1: * (L[p] <=) sum a[p,j] x[j] <= U[p], (1) alpar@1: * j alpar@1: * alpar@1: * where L[p] < U[p], and lower bound may not exist (L[p] = +oo). alpar@1: * alpar@1: * PROBLEM TRANSFORMATION alpar@1: * alpar@1: * Constraint (1) can be replaced by equality constraint: alpar@1: * alpar@1: * sum a[p,j] x[j] + s = L[p], (2) alpar@1: * j alpar@1: * alpar@1: * where alpar@1: * alpar@1: * 0 <= s (<= U[p] - L[p]) (3) alpar@1: * alpar@1: * is a non-negative slack variable. alpar@1: * alpar@1: * Since in the primal system there appears column s having the only alpar@1: * non-zero coefficient in row p, in the dual system there appears a alpar@1: * new row: alpar@1: * alpar@1: * (+1) pi[p] + lambda = 0, (4) alpar@1: * alpar@1: * where (+1) is coefficient of column s in row p, pi[p] is multiplier alpar@1: * of row p, lambda is multiplier of column q, 0 is coefficient of alpar@1: * column s in the objective row. alpar@1: * alpar@1: * RECOVERING BASIC SOLUTION alpar@1: * alpar@1: * Status of row p in solution to the original problem is determined alpar@1: * by its status and status of column q in solution to the transformed alpar@1: * problem as follows: alpar@1: * alpar@1: * +--------------------------------------+------------------+ alpar@1: * | Transformed problem | Original problem | alpar@1: * +-----------------+--------------------+------------------+ alpar@1: * | Status of row p | Status of column s | Status of row p | alpar@1: * +-----------------+--------------------+------------------+ alpar@1: * | GLP_BS | GLP_BS | N/A | alpar@1: * | GLP_BS | GLP_NL | GLP_BS | alpar@1: * | GLP_BS | GLP_NU | GLP_BS | alpar@1: * | GLP_NS | GLP_BS | GLP_BS | alpar@1: * | GLP_NS | GLP_NL | GLP_NU | alpar@1: * | GLP_NS | GLP_NU | GLP_NL | alpar@1: * +-----------------+--------------------+------------------+ alpar@1: * alpar@1: * Value of row multiplier pi[p] in solution to the original problem alpar@1: * is the same as in solution to the transformed problem. alpar@1: * alpar@1: * 1. In solution to the transformed problem row p and column q cannot alpar@1: * be basic at the same time; otherwise the basis matrix would have alpar@1: * two linear dependent columns: unity column of auxiliary variable alpar@1: * of row p and unity column of variable s. alpar@1: * alpar@1: * 2. Though in the transformed problem row p is equality constraint, alpar@1: * it may be basic due to primal degeneracy. alpar@1: * alpar@1: * RECOVERING INTERIOR-POINT SOLUTION alpar@1: * alpar@1: * Value of row multiplier pi[p] in solution to the original problem alpar@1: * is the same as in solution to the transformed problem. alpar@1: * alpar@1: * RECOVERING MIP SOLUTION alpar@1: * alpar@1: * None needed. */ alpar@1: alpar@1: static int rcv_leq_row(NPP *npp, void *info); alpar@1: alpar@1: void npp_leq_row(NPP *npp, NPPROW *p) alpar@1: { /* process row of 'not greater than' type */ alpar@1: struct ineq_row *info; alpar@1: NPPCOL *s; alpar@1: /* the row must have upper bound */ alpar@1: xassert(p->ub != +DBL_MAX); alpar@1: xassert(p->lb < p->ub); alpar@1: /* create column for slack variable */ alpar@1: s = npp_add_col(npp); alpar@1: s->lb = 0.0; alpar@1: s->ub = (p->lb == -DBL_MAX ? +DBL_MAX : p->ub - p->lb); alpar@1: /* and add it to the transformed problem */ alpar@1: npp_add_aij(npp, p, s, +1.0); alpar@1: /* create transformation stack entry */ alpar@1: info = npp_push_tse(npp, alpar@1: rcv_leq_row, sizeof(struct ineq_row)); alpar@1: info->p = p->i; alpar@1: info->s = s->j; alpar@1: /* replace the row by equality constraint */ alpar@1: p->lb = p->ub; alpar@1: return; alpar@1: } alpar@1: alpar@1: static int rcv_leq_row(NPP *npp, void *_info) alpar@1: { /* recover row of 'not greater than' type */ alpar@1: struct ineq_row *info = _info; alpar@1: if (npp->sol == GLP_SOL) alpar@1: { if (npp->r_stat[info->p] == GLP_BS) alpar@1: { if (npp->c_stat[info->s] == GLP_BS) alpar@1: { npp_error(); alpar@1: return 1; alpar@1: } alpar@1: else if (npp->c_stat[info->s] == GLP_NL || alpar@1: npp->c_stat[info->s] == GLP_NU) alpar@1: npp->r_stat[info->p] = GLP_BS; alpar@1: else alpar@1: { npp_error(); alpar@1: return 1; alpar@1: } alpar@1: } alpar@1: else if (npp->r_stat[info->p] == GLP_NS) alpar@1: { if (npp->c_stat[info->s] == GLP_BS) alpar@1: npp->r_stat[info->p] = GLP_BS; alpar@1: else if (npp->c_stat[info->s] == GLP_NL) alpar@1: npp->r_stat[info->p] = GLP_NU; alpar@1: else if (npp->c_stat[info->s] == GLP_NU) alpar@1: npp->r_stat[info->p] = GLP_NL; alpar@1: else alpar@1: { npp_error(); alpar@1: return 1; alpar@1: } alpar@1: } alpar@1: else alpar@1: { npp_error(); alpar@1: return 1; alpar@1: } alpar@1: } alpar@1: return 0; alpar@1: } alpar@1: alpar@1: /*********************************************************************** alpar@1: * NAME alpar@1: * alpar@1: * npp_free_col - process free (unbounded) column alpar@1: * alpar@1: * SYNOPSIS alpar@1: * alpar@1: * #include "glpnpp.h" alpar@1: * void npp_free_col(NPP *npp, NPPCOL *q); alpar@1: * alpar@1: * DESCRIPTION alpar@1: * alpar@1: * The routine npp_free_col processes column q, which is free (i.e. has alpar@1: * no finite bounds): alpar@1: * alpar@1: * -oo < x[q] < +oo. (1) alpar@1: * alpar@1: * PROBLEM TRANSFORMATION alpar@1: * alpar@1: * Free (unbounded) variable can be replaced by the difference of two alpar@1: * non-negative variables: alpar@1: * alpar@1: * x[q] = s' - s'', s', s'' >= 0. (2) alpar@1: * alpar@1: * Assuming that in the transformed problem x[q] becomes s', alpar@1: * transformation (2) causes new column s'' to appear, which differs alpar@1: * from column s' only in the sign of coefficients in constraint and alpar@1: * objective rows. Thus, if in the dual system the following row alpar@1: * corresponds to column s': alpar@1: * alpar@1: * sum a[i,q] pi[i] + lambda' = c[q], (3) alpar@1: * i alpar@1: * alpar@1: * the row which corresponds to column s'' is the following: alpar@1: * alpar@1: * sum (-a[i,q]) pi[i] + lambda'' = -c[q]. (4) alpar@1: * i alpar@1: * alpar@1: * Then from (3) and (4) it follows that: alpar@1: * alpar@1: * lambda' + lambda'' = 0 => lambda' = lmabda'' = 0, (5) alpar@1: * alpar@1: * where lambda' and lambda'' are multipliers for columns s' and s'', alpar@1: * resp. alpar@1: * alpar@1: * RECOVERING BASIC SOLUTION alpar@1: * alpar@1: * With respect to (5) status of column q in solution to the original alpar@1: * problem is determined by statuses of columns s' and s'' in solution alpar@1: * to the transformed problem as follows: alpar@1: * alpar@1: * +--------------------------------------+------------------+ alpar@1: * | Transformed problem | Original problem | alpar@1: * +------------------+-------------------+------------------+ alpar@1: * | Status of col s' | Status of col s'' | Status of col q | alpar@1: * +------------------+-------------------+------------------+ alpar@1: * | GLP_BS | GLP_BS | N/A | alpar@1: * | GLP_BS | GLP_NL | GLP_BS | alpar@1: * | GLP_NL | GLP_BS | GLP_BS | alpar@1: * | GLP_NL | GLP_NL | GLP_NF | alpar@1: * +------------------+-------------------+------------------+ alpar@1: * alpar@1: * Value of column q is computed with formula (2). alpar@1: * alpar@1: * 1. In solution to the transformed problem columns s' and s'' cannot alpar@1: * be basic at the same time, because they differ only in the sign, alpar@1: * hence, are linear dependent. alpar@1: * alpar@1: * 2. Though column q is free, it can be non-basic due to dual alpar@1: * degeneracy. alpar@1: * alpar@1: * 3. If column q is integral, columns s' and s'' are also integral. alpar@1: * alpar@1: * RECOVERING INTERIOR-POINT SOLUTION alpar@1: * alpar@1: * Value of column q is computed with formula (2). alpar@1: * alpar@1: * RECOVERING MIP SOLUTION alpar@1: * alpar@1: * Value of column q is computed with formula (2). */ alpar@1: alpar@1: struct free_col alpar@1: { /* free (unbounded) column */ alpar@1: int q; alpar@1: /* column reference number for variables x[q] and s' */ alpar@1: int s; alpar@1: /* column reference number for variable s'' */ alpar@1: }; alpar@1: alpar@1: static int rcv_free_col(NPP *npp, void *info); alpar@1: alpar@1: void npp_free_col(NPP *npp, NPPCOL *q) alpar@1: { /* process free (unbounded) column */ alpar@1: struct free_col *info; alpar@1: NPPCOL *s; alpar@1: NPPAIJ *aij; alpar@1: /* the column must be free */ alpar@1: xassert(q->lb == -DBL_MAX && q->ub == +DBL_MAX); alpar@1: /* variable x[q] becomes s' */ alpar@1: q->lb = 0.0, q->ub = +DBL_MAX; alpar@1: /* create variable s'' */ alpar@1: s = npp_add_col(npp); alpar@1: s->is_int = q->is_int; alpar@1: s->lb = 0.0, s->ub = +DBL_MAX; alpar@1: /* duplicate objective coefficient */ alpar@1: s->coef = -q->coef; alpar@1: /* duplicate column of the constraint matrix */ alpar@1: for (aij = q->ptr; aij != NULL; aij = aij->c_next) alpar@1: npp_add_aij(npp, aij->row, s, -aij->val); alpar@1: /* create transformation stack entry */ alpar@1: info = npp_push_tse(npp, alpar@1: rcv_free_col, sizeof(struct free_col)); alpar@1: info->q = q->j; alpar@1: info->s = s->j; alpar@1: return; alpar@1: } alpar@1: alpar@1: static int rcv_free_col(NPP *npp, void *_info) alpar@1: { /* recover free (unbounded) column */ alpar@1: struct free_col *info = _info; alpar@1: if (npp->sol == GLP_SOL) alpar@1: { if (npp->c_stat[info->q] == GLP_BS) alpar@1: { if (npp->c_stat[info->s] == GLP_BS) alpar@1: { npp_error(); alpar@1: return 1; alpar@1: } alpar@1: else if (npp->c_stat[info->s] == GLP_NL) alpar@1: npp->c_stat[info->q] = GLP_BS; alpar@1: else alpar@1: { npp_error(); alpar@1: return -1; alpar@1: } alpar@1: } alpar@1: else if (npp->c_stat[info->q] == GLP_NL) alpar@1: { if (npp->c_stat[info->s] == GLP_BS) alpar@1: npp->c_stat[info->q] = GLP_BS; alpar@1: else if (npp->c_stat[info->s] == GLP_NL) alpar@1: npp->c_stat[info->q] = GLP_NF; alpar@1: else alpar@1: { npp_error(); alpar@1: return -1; alpar@1: } alpar@1: } alpar@1: else alpar@1: { npp_error(); alpar@1: return -1; alpar@1: } alpar@1: } alpar@1: /* compute value of x[q] with formula (2) */ alpar@1: npp->c_value[info->q] -= npp->c_value[info->s]; alpar@1: return 0; alpar@1: } alpar@1: alpar@1: /*********************************************************************** alpar@1: * NAME alpar@1: * alpar@1: * npp_lbnd_col - process column with (non-zero) lower bound alpar@1: * alpar@1: * SYNOPSIS alpar@1: * alpar@1: * #include "glpnpp.h" alpar@1: * void npp_lbnd_col(NPP *npp, NPPCOL *q); alpar@1: * alpar@1: * DESCRIPTION alpar@1: * alpar@1: * The routine npp_lbnd_col processes column q, which has (non-zero) alpar@1: * lower bound: alpar@1: * alpar@1: * l[q] <= x[q] (<= u[q]), (1) alpar@1: * alpar@1: * where l[q] < u[q], and upper bound may not exist (u[q] = +oo). alpar@1: * alpar@1: * PROBLEM TRANSFORMATION alpar@1: * alpar@1: * Column q can be replaced as follows: alpar@1: * alpar@1: * x[q] = l[q] + s, (2) alpar@1: * alpar@1: * where alpar@1: * alpar@1: * 0 <= s (<= u[q] - l[q]) (3) alpar@1: * alpar@1: * is a non-negative variable. alpar@1: * alpar@1: * Substituting x[q] from (2) into the objective row, we have: alpar@1: * alpar@1: * z = sum c[j] x[j] + c0 = alpar@1: * j alpar@1: * alpar@1: * = sum c[j] x[j] + c[q] x[q] + c0 = alpar@1: * j!=q alpar@1: * alpar@1: * = sum c[j] x[j] + c[q] (l[q] + s) + c0 = alpar@1: * j!=q alpar@1: * alpar@1: * = sum c[j] x[j] + c[q] s + c~0, alpar@1: * alpar@1: * where alpar@1: * alpar@1: * c~0 = c0 + c[q] l[q] (4) alpar@1: * alpar@1: * is the constant term of the objective in the transformed problem. alpar@1: * Similarly, substituting x[q] into constraint row i, we have: alpar@1: * alpar@1: * L[i] <= sum a[i,j] x[j] <= U[i] ==> alpar@1: * j alpar@1: * alpar@1: * L[i] <= sum a[i,j] x[j] + a[i,q] x[q] <= U[i] ==> alpar@1: * j!=q alpar@1: * alpar@1: * L[i] <= sum a[i,j] x[j] + a[i,q] (l[q] + s) <= U[i] ==> alpar@1: * j!=q alpar@1: * alpar@1: * L~[i] <= sum a[i,j] x[j] + a[i,q] s <= U~[i], alpar@1: * j!=q alpar@1: * alpar@1: * where alpar@1: * alpar@1: * L~[i] = L[i] - a[i,q] l[q], U~[i] = U[i] - a[i,q] l[q] (5) alpar@1: * alpar@1: * are lower and upper bounds of row i in the transformed problem, alpar@1: * resp. alpar@1: * alpar@1: * Transformation (2) does not affect the dual system. alpar@1: * alpar@1: * RECOVERING BASIC SOLUTION alpar@1: * alpar@1: * Status of column q in solution to the original problem is the same alpar@1: * as in solution to the transformed problem (GLP_BS, GLP_NL or GLP_NU). alpar@1: * Value of column q is computed with formula (2). alpar@1: * alpar@1: * RECOVERING INTERIOR-POINT SOLUTION alpar@1: * alpar@1: * Value of column q is computed with formula (2). alpar@1: * alpar@1: * RECOVERING MIP SOLUTION alpar@1: * alpar@1: * Value of column q is computed with formula (2). */ alpar@1: alpar@1: struct bnd_col alpar@1: { /* bounded column */ alpar@1: int q; alpar@1: /* column reference number for variables x[q] and s */ alpar@1: double bnd; alpar@1: /* lower/upper bound l[q] or u[q] */ alpar@1: }; alpar@1: alpar@1: static int rcv_lbnd_col(NPP *npp, void *info); alpar@1: alpar@1: void npp_lbnd_col(NPP *npp, NPPCOL *q) alpar@1: { /* process column with (non-zero) lower bound */ alpar@1: struct bnd_col *info; alpar@1: NPPROW *i; alpar@1: NPPAIJ *aij; alpar@1: /* the column must have non-zero lower bound */ alpar@1: xassert(q->lb != 0.0); alpar@1: xassert(q->lb != -DBL_MAX); alpar@1: xassert(q->lb < q->ub); alpar@1: /* create transformation stack entry */ alpar@1: info = npp_push_tse(npp, alpar@1: rcv_lbnd_col, sizeof(struct bnd_col)); alpar@1: info->q = q->j; alpar@1: info->bnd = q->lb; alpar@1: /* substitute x[q] into objective row */ alpar@1: npp->c0 += q->coef * q->lb; alpar@1: /* substitute x[q] into constraint rows */ alpar@1: for (aij = q->ptr; aij != NULL; aij = aij->c_next) alpar@1: { i = aij->row; alpar@1: if (i->lb == i->ub) alpar@1: i->ub = (i->lb -= aij->val * q->lb); alpar@1: else alpar@1: { if (i->lb != -DBL_MAX) alpar@1: i->lb -= aij->val * q->lb; alpar@1: if (i->ub != +DBL_MAX) alpar@1: i->ub -= aij->val * q->lb; alpar@1: } alpar@1: } alpar@1: /* column x[q] becomes column s */ alpar@1: if (q->ub != +DBL_MAX) alpar@1: q->ub -= q->lb; alpar@1: q->lb = 0.0; alpar@1: return; alpar@1: } alpar@1: alpar@1: static int rcv_lbnd_col(NPP *npp, void *_info) alpar@1: { /* recover column with (non-zero) lower bound */ alpar@1: struct bnd_col *info = _info; alpar@1: if (npp->sol == GLP_SOL) alpar@1: { if (npp->c_stat[info->q] == GLP_BS || alpar@1: npp->c_stat[info->q] == GLP_NL || alpar@1: npp->c_stat[info->q] == GLP_NU) alpar@1: npp->c_stat[info->q] = npp->c_stat[info->q]; alpar@1: else alpar@1: { npp_error(); alpar@1: return 1; alpar@1: } alpar@1: } alpar@1: /* compute value of x[q] with formula (2) */ alpar@1: npp->c_value[info->q] = info->bnd + npp->c_value[info->q]; alpar@1: return 0; alpar@1: } alpar@1: alpar@1: /*********************************************************************** alpar@1: * NAME alpar@1: * alpar@1: * npp_ubnd_col - process column with upper bound alpar@1: * alpar@1: * SYNOPSIS alpar@1: * alpar@1: * #include "glpnpp.h" alpar@1: * void npp_ubnd_col(NPP *npp, NPPCOL *q); alpar@1: * alpar@1: * DESCRIPTION alpar@1: * alpar@1: * The routine npp_ubnd_col processes column q, which has upper bound: alpar@1: * alpar@1: * (l[q] <=) x[q] <= u[q], (1) alpar@1: * alpar@1: * where l[q] < u[q], and lower bound may not exist (l[q] = -oo). alpar@1: * alpar@1: * PROBLEM TRANSFORMATION alpar@1: * alpar@1: * Column q can be replaced as follows: alpar@1: * alpar@1: * x[q] = u[q] - s, (2) alpar@1: * alpar@1: * where alpar@1: * alpar@1: * 0 <= s (<= u[q] - l[q]) (3) alpar@1: * alpar@1: * is a non-negative variable. alpar@1: * alpar@1: * Substituting x[q] from (2) into the objective row, we have: alpar@1: * alpar@1: * z = sum c[j] x[j] + c0 = alpar@1: * j alpar@1: * alpar@1: * = sum c[j] x[j] + c[q] x[q] + c0 = alpar@1: * j!=q alpar@1: * alpar@1: * = sum c[j] x[j] + c[q] (u[q] - s) + c0 = alpar@1: * j!=q alpar@1: * alpar@1: * = sum c[j] x[j] - c[q] s + c~0, alpar@1: * alpar@1: * where alpar@1: * alpar@1: * c~0 = c0 + c[q] u[q] (4) alpar@1: * alpar@1: * is the constant term of the objective in the transformed problem. alpar@1: * Similarly, substituting x[q] into constraint row i, we have: alpar@1: * alpar@1: * L[i] <= sum a[i,j] x[j] <= U[i] ==> alpar@1: * j alpar@1: * alpar@1: * L[i] <= sum a[i,j] x[j] + a[i,q] x[q] <= U[i] ==> alpar@1: * j!=q alpar@1: * alpar@1: * L[i] <= sum a[i,j] x[j] + a[i,q] (u[q] - s) <= U[i] ==> alpar@1: * j!=q alpar@1: * alpar@1: * L~[i] <= sum a[i,j] x[j] - a[i,q] s <= U~[i], alpar@1: * j!=q alpar@1: * alpar@1: * where alpar@1: * alpar@1: * L~[i] = L[i] - a[i,q] u[q], U~[i] = U[i] - a[i,q] u[q] (5) alpar@1: * alpar@1: * are lower and upper bounds of row i in the transformed problem, alpar@1: * resp. alpar@1: * alpar@1: * Note that in the transformed problem coefficients c[q] and a[i,q] alpar@1: * change their sign. Thus, the row of the dual system corresponding to alpar@1: * column q: alpar@1: * alpar@1: * sum a[i,q] pi[i] + lambda[q] = c[q] (6) alpar@1: * i alpar@1: * alpar@1: * in the transformed problem becomes the following: alpar@1: * alpar@1: * sum (-a[i,q]) pi[i] + lambda[s] = -c[q]. (7) alpar@1: * i alpar@1: * alpar@1: * Therefore: alpar@1: * alpar@1: * lambda[q] = - lambda[s], (8) alpar@1: * alpar@1: * where lambda[q] is multiplier for column q, lambda[s] is multiplier alpar@1: * for column s. alpar@1: * alpar@1: * RECOVERING BASIC SOLUTION alpar@1: * alpar@1: * With respect to (8) status of column q in solution to the original alpar@1: * problem is determined by status of column s in solution to the alpar@1: * transformed problem as follows: alpar@1: * alpar@1: * +-----------------------+--------------------+ alpar@1: * | Status of column s | Status of column q | alpar@1: * | (transformed problem) | (original problem) | alpar@1: * +-----------------------+--------------------+ alpar@1: * | GLP_BS | GLP_BS | alpar@1: * | GLP_NL | GLP_NU | alpar@1: * | GLP_NU | GLP_NL | alpar@1: * +-----------------------+--------------------+ alpar@1: * alpar@1: * Value of column q is computed with formula (2). alpar@1: * alpar@1: * RECOVERING INTERIOR-POINT SOLUTION alpar@1: * alpar@1: * Value of column q is computed with formula (2). alpar@1: * alpar@1: * RECOVERING MIP SOLUTION alpar@1: * alpar@1: * Value of column q is computed with formula (2). */ alpar@1: alpar@1: static int rcv_ubnd_col(NPP *npp, void *info); alpar@1: alpar@1: void npp_ubnd_col(NPP *npp, NPPCOL *q) alpar@1: { /* process column with upper bound */ alpar@1: struct bnd_col *info; alpar@1: NPPROW *i; alpar@1: NPPAIJ *aij; alpar@1: /* the column must have upper bound */ alpar@1: xassert(q->ub != +DBL_MAX); alpar@1: xassert(q->lb < q->ub); alpar@1: /* create transformation stack entry */ alpar@1: info = npp_push_tse(npp, alpar@1: rcv_ubnd_col, sizeof(struct bnd_col)); alpar@1: info->q = q->j; alpar@1: info->bnd = q->ub; alpar@1: /* substitute x[q] into objective row */ alpar@1: npp->c0 += q->coef * q->ub; alpar@1: q->coef = -q->coef; alpar@1: /* substitute x[q] into constraint rows */ alpar@1: for (aij = q->ptr; aij != NULL; aij = aij->c_next) alpar@1: { i = aij->row; alpar@1: if (i->lb == i->ub) alpar@1: i->ub = (i->lb -= aij->val * q->ub); alpar@1: else alpar@1: { if (i->lb != -DBL_MAX) alpar@1: i->lb -= aij->val * q->ub; alpar@1: if (i->ub != +DBL_MAX) alpar@1: i->ub -= aij->val * q->ub; alpar@1: } alpar@1: aij->val = -aij->val; alpar@1: } alpar@1: /* column x[q] becomes column s */ alpar@1: if (q->lb != -DBL_MAX) alpar@1: q->ub -= q->lb; alpar@1: else alpar@1: q->ub = +DBL_MAX; alpar@1: q->lb = 0.0; alpar@1: return; alpar@1: } alpar@1: alpar@1: static int rcv_ubnd_col(NPP *npp, void *_info) alpar@1: { /* recover column with upper bound */ alpar@1: struct bnd_col *info = _info; alpar@1: if (npp->sol == GLP_BS) alpar@1: { if (npp->c_stat[info->q] == GLP_BS) alpar@1: npp->c_stat[info->q] = GLP_BS; alpar@1: else if (npp->c_stat[info->q] == GLP_NL) alpar@1: npp->c_stat[info->q] = GLP_NU; alpar@1: else if (npp->c_stat[info->q] == GLP_NU) alpar@1: npp->c_stat[info->q] = GLP_NL; alpar@1: else alpar@1: { npp_error(); alpar@1: return 1; alpar@1: } alpar@1: } alpar@1: /* compute value of x[q] with formula (2) */ alpar@1: npp->c_value[info->q] = info->bnd - npp->c_value[info->q]; alpar@1: return 0; alpar@1: } alpar@1: alpar@1: /*********************************************************************** alpar@1: * NAME alpar@1: * alpar@1: * npp_dbnd_col - process non-negative column with upper bound alpar@1: * alpar@1: * SYNOPSIS alpar@1: * alpar@1: * #include "glpnpp.h" alpar@1: * void npp_dbnd_col(NPP *npp, NPPCOL *q); alpar@1: * alpar@1: * DESCRIPTION alpar@1: * alpar@1: * The routine npp_dbnd_col processes column q, which is non-negative alpar@1: * and has upper bound: alpar@1: * alpar@1: * 0 <= x[q] <= u[q], (1) alpar@1: * alpar@1: * where u[q] > 0. alpar@1: * alpar@1: * PROBLEM TRANSFORMATION alpar@1: * alpar@1: * Upper bound of column q can be replaced by the following equality alpar@1: * constraint: alpar@1: * alpar@1: * x[q] + s = u[q], (2) alpar@1: * alpar@1: * where s >= 0 is a non-negative complement variable. alpar@1: * alpar@1: * Since in the primal system along with new row (2) there appears a alpar@1: * new column s having the only non-zero coefficient in this row, in alpar@1: * the dual system there appears a new row: alpar@1: * alpar@1: * (+1)pi + lambda[s] = 0, (3) alpar@1: * alpar@1: * where (+1) is coefficient at column s in row (2), pi is multiplier alpar@1: * for row (2), lambda[s] is multiplier for column s, 0 is coefficient alpar@1: * at column s in the objective row. alpar@1: * alpar@1: * RECOVERING BASIC SOLUTION alpar@1: * alpar@1: * Status of column q in solution to the original problem is determined alpar@1: * by its status and status of column s in solution to the transformed alpar@1: * problem as follows: alpar@1: * alpar@1: * +-----------------------------------+------------------+ alpar@1: * | Transformed problem | Original problem | alpar@1: * +-----------------+-----------------+------------------+ alpar@1: * | Status of col q | Status of col s | Status of col q | alpar@1: * +-----------------+-----------------+------------------+ alpar@1: * | GLP_BS | GLP_BS | GLP_BS | alpar@1: * | GLP_BS | GLP_NL | GLP_NU | alpar@1: * | GLP_NL | GLP_BS | GLP_NL | alpar@1: * | GLP_NL | GLP_NL | GLP_NL (*) | alpar@1: * +-----------------+-----------------+------------------+ alpar@1: * alpar@1: * Value of column q in solution to the original problem is the same as alpar@1: * in solution to the transformed problem. alpar@1: * alpar@1: * 1. Formally, in solution to the transformed problem columns q and s alpar@1: * cannot be non-basic at the same time, since the constraint (2) alpar@1: * would be violated. However, if u[q] is close to zero, violation alpar@1: * may be less than a working precision even if both columns q and s alpar@1: * are non-basic. In this degenerate case row (2) can be only basic, alpar@1: * i.e. non-active constraint (otherwise corresponding row of the alpar@1: * basis matrix would be zero). This allows to pivot out auxiliary alpar@1: * variable and pivot in column s, in which case the row becomes alpar@1: * active while column s becomes basic. alpar@1: * alpar@1: * 2. If column q is integral, column s is also integral. alpar@1: * alpar@1: * RECOVERING INTERIOR-POINT SOLUTION alpar@1: * alpar@1: * Value of column q in solution to the original problem is the same as alpar@1: * in solution to the transformed problem. alpar@1: * alpar@1: * RECOVERING MIP SOLUTION alpar@1: * alpar@1: * Value of column q in solution to the original problem is the same as alpar@1: * in solution to the transformed problem. */ alpar@1: alpar@1: struct dbnd_col alpar@1: { /* double-bounded column */ alpar@1: int q; alpar@1: /* column reference number for variable x[q] */ alpar@1: int s; alpar@1: /* column reference number for complement variable s */ alpar@1: }; alpar@1: alpar@1: static int rcv_dbnd_col(NPP *npp, void *info); alpar@1: alpar@1: void npp_dbnd_col(NPP *npp, NPPCOL *q) alpar@1: { /* process non-negative column with upper bound */ alpar@1: struct dbnd_col *info; alpar@1: NPPROW *p; alpar@1: NPPCOL *s; alpar@1: /* the column must be non-negative with upper bound */ alpar@1: xassert(q->lb == 0.0); alpar@1: xassert(q->ub > 0.0); alpar@1: xassert(q->ub != +DBL_MAX); alpar@1: /* create variable s */ alpar@1: s = npp_add_col(npp); alpar@1: s->is_int = q->is_int; alpar@1: s->lb = 0.0, s->ub = +DBL_MAX; alpar@1: /* create equality constraint (2) */ alpar@1: p = npp_add_row(npp); alpar@1: p->lb = p->ub = q->ub; alpar@1: npp_add_aij(npp, p, q, +1.0); alpar@1: npp_add_aij(npp, p, s, +1.0); alpar@1: /* create transformation stack entry */ alpar@1: info = npp_push_tse(npp, alpar@1: rcv_dbnd_col, sizeof(struct dbnd_col)); alpar@1: info->q = q->j; alpar@1: info->s = s->j; alpar@1: /* remove upper bound of x[q] */ alpar@1: q->ub = +DBL_MAX; alpar@1: return; alpar@1: } alpar@1: alpar@1: static int rcv_dbnd_col(NPP *npp, void *_info) alpar@1: { /* recover non-negative column with upper bound */ alpar@1: struct dbnd_col *info = _info; alpar@1: if (npp->sol == GLP_BS) alpar@1: { if (npp->c_stat[info->q] == GLP_BS) alpar@1: { if (npp->c_stat[info->s] == GLP_BS) alpar@1: npp->c_stat[info->q] = GLP_BS; alpar@1: else if (npp->c_stat[info->s] == GLP_NL) alpar@1: npp->c_stat[info->q] = GLP_NU; alpar@1: else alpar@1: { npp_error(); alpar@1: return 1; alpar@1: } alpar@1: } alpar@1: else if (npp->c_stat[info->q] == GLP_NL) alpar@1: { if (npp->c_stat[info->s] == GLP_BS || alpar@1: npp->c_stat[info->s] == GLP_NL) alpar@1: npp->c_stat[info->q] = GLP_NL; alpar@1: else alpar@1: { npp_error(); alpar@1: return 1; alpar@1: } alpar@1: } alpar@1: else alpar@1: { npp_error(); alpar@1: return 1; alpar@1: } alpar@1: } alpar@1: return 0; alpar@1: } alpar@1: alpar@1: /*********************************************************************** alpar@1: * NAME alpar@1: * alpar@1: * npp_fixed_col - process fixed column alpar@1: * alpar@1: * SYNOPSIS alpar@1: * alpar@1: * #include "glpnpp.h" alpar@1: * void npp_fixed_col(NPP *npp, NPPCOL *q); alpar@1: * alpar@1: * DESCRIPTION alpar@1: * alpar@1: * The routine npp_fixed_col processes column q, which is fixed: alpar@1: * alpar@1: * x[q] = s[q], (1) alpar@1: * alpar@1: * where s[q] is a fixed column value. alpar@1: * alpar@1: * PROBLEM TRANSFORMATION alpar@1: * alpar@1: * The value of a fixed column can be substituted into the objective alpar@1: * and constraint rows that allows removing the column from the problem. alpar@1: * alpar@1: * Substituting x[q] = s[q] into the objective row, we have: alpar@1: * alpar@1: * z = sum c[j] x[j] + c0 = alpar@1: * j alpar@1: * alpar@1: * = sum c[j] x[j] + c[q] x[q] + c0 = alpar@1: * j!=q alpar@1: * alpar@1: * = sum c[j] x[j] + c[q] s[q] + c0 = alpar@1: * j!=q alpar@1: * alpar@1: * = sum c[j] x[j] + c~0, alpar@1: * j!=q alpar@1: * alpar@1: * where alpar@1: * alpar@1: * c~0 = c0 + c[q] s[q] (2) alpar@1: * alpar@1: * is the constant term of the objective in the transformed problem. alpar@1: * Similarly, substituting x[q] = s[q] into constraint row i, we have: alpar@1: * alpar@1: * L[i] <= sum a[i,j] x[j] <= U[i] ==> alpar@1: * j alpar@1: * alpar@1: * L[i] <= sum a[i,j] x[j] + a[i,q] x[q] <= U[i] ==> alpar@1: * j!=q alpar@1: * alpar@1: * L[i] <= sum a[i,j] x[j] + a[i,q] s[q] <= U[i] ==> alpar@1: * j!=q alpar@1: * alpar@1: * L~[i] <= sum a[i,j] x[j] + a[i,q] s <= U~[i], alpar@1: * j!=q alpar@1: * alpar@1: * where alpar@1: * alpar@1: * L~[i] = L[i] - a[i,q] s[q], U~[i] = U[i] - a[i,q] s[q] (3) alpar@1: * alpar@1: * are lower and upper bounds of row i in the transformed problem, alpar@1: * resp. alpar@1: * alpar@1: * RECOVERING BASIC SOLUTION alpar@1: * alpar@1: * Column q is assigned status GLP_NS and its value is assigned s[q]. alpar@1: * alpar@1: * RECOVERING INTERIOR-POINT SOLUTION alpar@1: * alpar@1: * Value of column q is assigned s[q]. alpar@1: * alpar@1: * RECOVERING MIP SOLUTION alpar@1: * alpar@1: * Value of column q is assigned s[q]. */ alpar@1: alpar@1: struct fixed_col alpar@1: { /* fixed column */ alpar@1: int q; alpar@1: /* column reference number for variable x[q] */ alpar@1: double s; alpar@1: /* value, at which x[q] is fixed */ alpar@1: }; alpar@1: alpar@1: static int rcv_fixed_col(NPP *npp, void *info); alpar@1: alpar@1: void npp_fixed_col(NPP *npp, NPPCOL *q) alpar@1: { /* process fixed column */ alpar@1: struct fixed_col *info; alpar@1: NPPROW *i; alpar@1: NPPAIJ *aij; alpar@1: /* the column must be fixed */ alpar@1: xassert(q->lb == q->ub); alpar@1: /* create transformation stack entry */ alpar@1: info = npp_push_tse(npp, alpar@1: rcv_fixed_col, sizeof(struct fixed_col)); alpar@1: info->q = q->j; alpar@1: info->s = q->lb; alpar@1: /* substitute x[q] = s[q] into objective row */ alpar@1: npp->c0 += q->coef * q->lb; alpar@1: /* substitute x[q] = s[q] into constraint rows */ alpar@1: for (aij = q->ptr; aij != NULL; aij = aij->c_next) alpar@1: { i = aij->row; alpar@1: if (i->lb == i->ub) alpar@1: i->ub = (i->lb -= aij->val * q->lb); alpar@1: else alpar@1: { if (i->lb != -DBL_MAX) alpar@1: i->lb -= aij->val * q->lb; alpar@1: if (i->ub != +DBL_MAX) alpar@1: i->ub -= aij->val * q->lb; alpar@1: } alpar@1: } alpar@1: /* remove the column from the problem */ alpar@1: npp_del_col(npp, q); alpar@1: return; alpar@1: } alpar@1: alpar@1: static int rcv_fixed_col(NPP *npp, void *_info) alpar@1: { /* recover fixed column */ alpar@1: struct fixed_col *info = _info; alpar@1: if (npp->sol == GLP_SOL) alpar@1: npp->c_stat[info->q] = GLP_NS; alpar@1: npp->c_value[info->q] = info->s; alpar@1: return 0; alpar@1: } alpar@1: alpar@1: /*********************************************************************** alpar@1: * NAME alpar@1: * alpar@1: * npp_make_equality - process row with almost identical bounds alpar@1: * alpar@1: * SYNOPSIS alpar@1: * alpar@1: * #include "glpnpp.h" alpar@1: * int npp_make_equality(NPP *npp, NPPROW *p); alpar@1: * alpar@1: * DESCRIPTION alpar@1: * alpar@1: * The routine npp_make_equality processes row p: alpar@1: * alpar@1: * L[p] <= sum a[p,j] x[j] <= U[p], (1) alpar@1: * j alpar@1: * alpar@1: * where -oo < L[p] < U[p] < +oo, i.e. which is double-sided inequality alpar@1: * constraint. alpar@1: * alpar@1: * RETURNS alpar@1: * alpar@1: * 0 - row bounds have not been changed; alpar@1: * alpar@1: * 1 - row has been replaced by equality constraint. alpar@1: * alpar@1: * PROBLEM TRANSFORMATION alpar@1: * alpar@1: * If bounds of row (1) are very close to each other: alpar@1: * alpar@1: * U[p] - L[p] <= eps, (2) alpar@1: * alpar@1: * where eps is an absolute tolerance for row value, the row can be alpar@1: * replaced by the following almost equivalent equiality constraint: alpar@1: * alpar@1: * sum a[p,j] x[j] = b, (3) alpar@1: * j alpar@1: * alpar@1: * where b = (L[p] + U[p]) / 2. If the right-hand side in (3) happens alpar@1: * to be very close to its nearest integer: alpar@1: * alpar@1: * |b - floor(b + 0.5)| <= eps, (4) alpar@1: * alpar@1: * it is reasonable to use this nearest integer as the right-hand side. alpar@1: * alpar@1: * RECOVERING BASIC SOLUTION alpar@1: * alpar@1: * Status of row p in solution to the original problem is determined alpar@1: * by its status and the sign of its multiplier pi[p] in solution to alpar@1: * the transformed problem as follows: alpar@1: * alpar@1: * +-----------------------+---------+--------------------+ alpar@1: * | Status of row p | Sign of | Status of row p | alpar@1: * | (transformed problem) | pi[p] | (original problem) | alpar@1: * +-----------------------+---------+--------------------+ alpar@1: * | GLP_BS | + / - | GLP_BS | alpar@1: * | GLP_NS | + | GLP_NL | alpar@1: * | GLP_NS | - | GLP_NU | alpar@1: * +-----------------------+---------+--------------------+ alpar@1: * alpar@1: * Value of row multiplier pi[p] in solution to the original problem is alpar@1: * the same as in solution to the transformed problem. alpar@1: * alpar@1: * RECOVERING INTERIOR POINT SOLUTION alpar@1: * alpar@1: * Value of row multiplier pi[p] in solution to the original problem is alpar@1: * the same as in solution to the transformed problem. alpar@1: * alpar@1: * RECOVERING MIP SOLUTION alpar@1: * alpar@1: * None needed. */ alpar@1: alpar@1: struct make_equality alpar@1: { /* row with almost identical bounds */ alpar@1: int p; alpar@1: /* row reference number */ alpar@1: }; alpar@1: alpar@1: static int rcv_make_equality(NPP *npp, void *info); alpar@1: alpar@1: int npp_make_equality(NPP *npp, NPPROW *p) alpar@1: { /* process row with almost identical bounds */ alpar@1: struct make_equality *info; alpar@1: double b, eps, nint; alpar@1: /* the row must be double-sided inequality */ alpar@1: xassert(p->lb != -DBL_MAX); alpar@1: xassert(p->ub != +DBL_MAX); alpar@1: xassert(p->lb < p->ub); alpar@1: /* check row bounds */ alpar@1: eps = 1e-9 + 1e-12 * fabs(p->lb); alpar@1: if (p->ub - p->lb > eps) return 0; alpar@1: /* row bounds are very close to each other */ alpar@1: /* create transformation stack entry */ alpar@1: info = npp_push_tse(npp, alpar@1: rcv_make_equality, sizeof(struct make_equality)); alpar@1: info->p = p->i; alpar@1: /* compute right-hand side */ alpar@1: b = 0.5 * (p->ub + p->lb); alpar@1: nint = floor(b + 0.5); alpar@1: if (fabs(b - nint) <= eps) b = nint; alpar@1: /* replace row p by almost equivalent equality constraint */ alpar@1: p->lb = p->ub = b; alpar@1: return 1; alpar@1: } alpar@1: alpar@1: int rcv_make_equality(NPP *npp, void *_info) alpar@1: { /* recover row with almost identical bounds */ alpar@1: struct make_equality *info = _info; alpar@1: if (npp->sol == GLP_SOL) alpar@1: { if (npp->r_stat[info->p] == GLP_BS) alpar@1: npp->r_stat[info->p] = GLP_BS; alpar@1: else if (npp->r_stat[info->p] == GLP_NS) alpar@1: { if (npp->r_pi[info->p] >= 0.0) alpar@1: npp->r_stat[info->p] = GLP_NL; alpar@1: else alpar@1: npp->r_stat[info->p] = GLP_NU; alpar@1: } alpar@1: else alpar@1: { npp_error(); alpar@1: return 1; alpar@1: } alpar@1: } alpar@1: return 0; alpar@1: } alpar@1: alpar@1: /*********************************************************************** alpar@1: * NAME alpar@1: * alpar@1: * npp_make_fixed - process column with almost identical bounds alpar@1: * alpar@1: * SYNOPSIS alpar@1: * alpar@1: * #include "glpnpp.h" alpar@1: * int npp_make_fixed(NPP *npp, NPPCOL *q); alpar@1: * alpar@1: * DESCRIPTION alpar@1: * alpar@1: * The routine npp_make_fixed processes column q: alpar@1: * alpar@1: * l[q] <= x[q] <= u[q], (1) alpar@1: * alpar@1: * where -oo < l[q] < u[q] < +oo, i.e. which has both lower and upper alpar@1: * bounds. alpar@1: * alpar@1: * RETURNS alpar@1: * alpar@1: * 0 - column bounds have not been changed; alpar@1: * alpar@1: * 1 - column has been fixed. alpar@1: * alpar@1: * PROBLEM TRANSFORMATION alpar@1: * alpar@1: * If bounds of column (1) are very close to each other: alpar@1: * alpar@1: * u[q] - l[q] <= eps, (2) alpar@1: * alpar@1: * where eps is an absolute tolerance for column value, the column can alpar@1: * be fixed: alpar@1: * alpar@1: * x[q] = s[q], (3) alpar@1: * alpar@1: * where s[q] = (l[q] + u[q]) / 2. And if the fixed column value s[q] alpar@1: * happens to be very close to its nearest integer: alpar@1: * alpar@1: * |s[q] - floor(s[q] + 0.5)| <= eps, (4) alpar@1: * alpar@1: * it is reasonable to use this nearest integer as the fixed value. alpar@1: * alpar@1: * RECOVERING BASIC SOLUTION alpar@1: * alpar@1: * In the dual system of the original (as well as transformed) problem alpar@1: * column q corresponds to the following row: alpar@1: * alpar@1: * sum a[i,q] pi[i] + lambda[q] = c[q]. (5) alpar@1: * i alpar@1: * alpar@1: * Since multipliers pi[i] are known for all rows from solution to the alpar@1: * transformed problem, formula (5) allows computing value of multiplier alpar@1: * (reduced cost) for column q: alpar@1: * alpar@1: * lambda[q] = c[q] - sum a[i,q] pi[i]. (6) alpar@1: * i alpar@1: * alpar@1: * Status of column q in solution to the original problem is determined alpar@1: * by its status and the sign of its multiplier lambda[q] in solution to alpar@1: * the transformed problem as follows: alpar@1: * alpar@1: * +-----------------------+-----------+--------------------+ alpar@1: * | Status of column q | Sign of | Status of column q | alpar@1: * | (transformed problem) | lambda[q] | (original problem) | alpar@1: * +-----------------------+-----------+--------------------+ alpar@1: * | GLP_BS | + / - | GLP_BS | alpar@1: * | GLP_NS | + | GLP_NL | alpar@1: * | GLP_NS | - | GLP_NU | alpar@1: * +-----------------------+-----------+--------------------+ alpar@1: * alpar@1: * Value of column q in solution to the original problem is the same as alpar@1: * in solution to the transformed problem. alpar@1: * alpar@1: * RECOVERING INTERIOR POINT SOLUTION alpar@1: * alpar@1: * Value of column q in solution to the original problem is the same as alpar@1: * in solution to the transformed problem. alpar@1: * alpar@1: * RECOVERING MIP SOLUTION alpar@1: * alpar@1: * None needed. */ alpar@1: alpar@1: struct make_fixed alpar@1: { /* column with almost identical bounds */ alpar@1: int q; alpar@1: /* column reference number */ alpar@1: double c; alpar@1: /* objective coefficient at x[q] */ alpar@1: NPPLFE *ptr; alpar@1: /* list of non-zero coefficients a[i,q] */ alpar@1: }; alpar@1: alpar@1: static int rcv_make_fixed(NPP *npp, void *info); alpar@1: alpar@1: int npp_make_fixed(NPP *npp, NPPCOL *q) alpar@1: { /* process column with almost identical bounds */ alpar@1: struct make_fixed *info; alpar@1: NPPAIJ *aij; alpar@1: NPPLFE *lfe; alpar@1: double s, eps, nint; alpar@1: /* the column must be double-bounded */ alpar@1: xassert(q->lb != -DBL_MAX); alpar@1: xassert(q->ub != +DBL_MAX); alpar@1: xassert(q->lb < q->ub); alpar@1: /* check column bounds */ alpar@1: eps = 1e-9 + 1e-12 * fabs(q->lb); alpar@1: if (q->ub - q->lb > eps) return 0; alpar@1: /* column bounds are very close to each other */ alpar@1: /* create transformation stack entry */ alpar@1: info = npp_push_tse(npp, alpar@1: rcv_make_fixed, sizeof(struct make_fixed)); alpar@1: info->q = q->j; alpar@1: info->c = q->coef; alpar@1: info->ptr = NULL; alpar@1: /* save column coefficients a[i,q] (needed for basic solution alpar@1: only) */ alpar@1: if (npp->sol == GLP_SOL) alpar@1: { for (aij = q->ptr; aij != NULL; aij = aij->c_next) alpar@1: { lfe = dmp_get_atom(npp->stack, sizeof(NPPLFE)); alpar@1: lfe->ref = aij->row->i; alpar@1: lfe->val = aij->val; alpar@1: lfe->next = info->ptr; alpar@1: info->ptr = lfe; alpar@1: } alpar@1: } alpar@1: /* compute column fixed value */ alpar@1: s = 0.5 * (q->ub + q->lb); alpar@1: nint = floor(s + 0.5); alpar@1: if (fabs(s - nint) <= eps) s = nint; alpar@1: /* make column q fixed */ alpar@1: q->lb = q->ub = s; alpar@1: return 1; alpar@1: } alpar@1: alpar@1: static int rcv_make_fixed(NPP *npp, void *_info) alpar@1: { /* recover column with almost identical bounds */ alpar@1: struct make_fixed *info = _info; alpar@1: NPPLFE *lfe; alpar@1: double lambda; alpar@1: if (npp->sol == GLP_SOL) alpar@1: { if (npp->c_stat[info->q] == GLP_BS) alpar@1: npp->c_stat[info->q] = GLP_BS; alpar@1: else if (npp->c_stat[info->q] == GLP_NS) alpar@1: { /* compute multiplier for column q with formula (6) */ alpar@1: lambda = info->c; alpar@1: for (lfe = info->ptr; lfe != NULL; lfe = lfe->next) alpar@1: lambda -= lfe->val * npp->r_pi[lfe->ref]; alpar@1: /* assign status to non-basic column */ alpar@1: if (lambda >= 0.0) alpar@1: npp->c_stat[info->q] = GLP_NL; alpar@1: else alpar@1: npp->c_stat[info->q] = GLP_NU; alpar@1: } alpar@1: else alpar@1: { npp_error(); alpar@1: return 1; alpar@1: } alpar@1: } alpar@1: return 0; alpar@1: } alpar@1: alpar@1: /* eof */