alpar@1: /* glpapi04.c (problem scaling routines) */ 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 "glpapi.h" alpar@1: alpar@1: /*********************************************************************** alpar@1: * NAME alpar@1: * alpar@1: * glp_set_rii - set (change) row scale factor alpar@1: * alpar@1: * SYNOPSIS alpar@1: * alpar@1: * void glp_set_rii(glp_prob *lp, int i, double rii); alpar@1: * alpar@1: * DESCRIPTION alpar@1: * alpar@1: * The routine glp_set_rii sets (changes) the scale factor r[i,i] for alpar@1: * i-th row of the specified problem object. */ alpar@1: alpar@1: void glp_set_rii(glp_prob *lp, int i, double rii) alpar@1: { if (!(1 <= i && i <= lp->m)) alpar@1: xerror("glp_set_rii: i = %d; row number out of range\n", i); alpar@1: if (rii <= 0.0) alpar@1: xerror("glp_set_rii: i = %d; rii = %g; invalid scale factor\n", alpar@1: i, rii); alpar@1: if (lp->valid && lp->row[i]->rii != rii) alpar@1: { GLPAIJ *aij; alpar@1: for (aij = lp->row[i]->ptr; aij != NULL; aij = aij->r_next) alpar@1: { if (aij->col->stat == GLP_BS) alpar@1: { /* invalidate the basis factorization */ alpar@1: lp->valid = 0; alpar@1: break; alpar@1: } alpar@1: } alpar@1: } alpar@1: lp->row[i]->rii = rii; alpar@1: return; alpar@1: } alpar@1: alpar@1: /*********************************************************************** alpar@1: * NAME alpar@1: * alpar@1: * glp_set sjj - set (change) column scale factor alpar@1: * alpar@1: * SYNOPSIS alpar@1: * alpar@1: * void glp_set_sjj(glp_prob *lp, int j, double sjj); alpar@1: * alpar@1: * DESCRIPTION alpar@1: * alpar@1: * The routine glp_set_sjj sets (changes) the scale factor s[j,j] for alpar@1: * j-th column of the specified problem object. */ alpar@1: alpar@1: void glp_set_sjj(glp_prob *lp, int j, double sjj) alpar@1: { if (!(1 <= j && j <= lp->n)) alpar@1: xerror("glp_set_sjj: j = %d; column number out of range\n", j); alpar@1: if (sjj <= 0.0) alpar@1: xerror("glp_set_sjj: j = %d; sjj = %g; invalid scale factor\n", alpar@1: j, sjj); alpar@1: if (lp->valid && lp->col[j]->sjj != sjj && lp->col[j]->stat == alpar@1: GLP_BS) alpar@1: { /* invalidate the basis factorization */ alpar@1: lp->valid = 0; alpar@1: } alpar@1: lp->col[j]->sjj = sjj; alpar@1: return; alpar@1: } alpar@1: alpar@1: /*********************************************************************** alpar@1: * NAME alpar@1: * alpar@1: * glp_get_rii - retrieve row scale factor alpar@1: * alpar@1: * SYNOPSIS alpar@1: * alpar@1: * double glp_get_rii(glp_prob *lp, int i); alpar@1: * alpar@1: * RETURNS alpar@1: * alpar@1: * The routine glp_get_rii returns current scale factor r[i,i] for i-th alpar@1: * row of the specified problem object. */ alpar@1: alpar@1: double glp_get_rii(glp_prob *lp, int i) alpar@1: { if (!(1 <= i && i <= lp->m)) alpar@1: xerror("glp_get_rii: i = %d; row number out of range\n", i); alpar@1: return lp->row[i]->rii; alpar@1: } alpar@1: alpar@1: /*********************************************************************** alpar@1: * NAME alpar@1: * alpar@1: * glp_get_sjj - retrieve column scale factor alpar@1: * alpar@1: * SYNOPSIS alpar@1: * alpar@1: * double glp_get_sjj(glp_prob *lp, int j); alpar@1: * alpar@1: * RETURNS alpar@1: * alpar@1: * The routine glp_get_sjj returns current scale factor s[j,j] for j-th alpar@1: * column of the specified problem object. */ alpar@1: alpar@1: double glp_get_sjj(glp_prob *lp, int j) alpar@1: { if (!(1 <= j && j <= lp->n)) alpar@1: xerror("glp_get_sjj: j = %d; column number out of range\n", j); alpar@1: return lp->col[j]->sjj; alpar@1: } alpar@1: alpar@1: /*********************************************************************** alpar@1: * NAME alpar@1: * alpar@1: * glp_unscale_prob - unscale problem data alpar@1: * alpar@1: * SYNOPSIS alpar@1: * alpar@1: * void glp_unscale_prob(glp_prob *lp); alpar@1: * alpar@1: * DESCRIPTION alpar@1: * alpar@1: * The routine glp_unscale_prob performs unscaling of problem data for alpar@1: * the specified problem object. alpar@1: * alpar@1: * "Unscaling" means replacing the current scaling matrices R and S by alpar@1: * unity matrices that cancels the scaling effect. */ alpar@1: alpar@1: void glp_unscale_prob(glp_prob *lp) alpar@1: { int m = glp_get_num_rows(lp); alpar@1: int n = glp_get_num_cols(lp); alpar@1: int i, j; alpar@1: for (i = 1; i <= m; i++) glp_set_rii(lp, i, 1.0); alpar@1: for (j = 1; j <= n; j++) glp_set_sjj(lp, j, 1.0); alpar@1: return; alpar@1: } alpar@1: alpar@1: /* eof */