lemon-project-template-glpk
diff deps/glpk/src/glpapi03.c @ 9:33de93886c88
Import GLPK 4.47
author | Alpar Juttner <alpar@cs.elte.hu> |
---|---|
date | Sun, 06 Nov 2011 20:59:10 +0100 |
parents | |
children |
line diff
1.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 1.2 +++ b/deps/glpk/src/glpapi03.c Sun Nov 06 20:59:10 2011 +0100 1.3 @@ -0,0 +1,166 @@ 1.4 +/* glpapi03.c (row and column searching routines) */ 1.5 + 1.6 +/*********************************************************************** 1.7 +* This code is part of GLPK (GNU Linear Programming Kit). 1.8 +* 1.9 +* Copyright (C) 2000, 2001, 2002, 2003, 2004, 2005, 2006, 2007, 2008, 1.10 +* 2009, 2010, 2011 Andrew Makhorin, Department for Applied Informatics, 1.11 +* Moscow Aviation Institute, Moscow, Russia. All rights reserved. 1.12 +* E-mail: <mao@gnu.org>. 1.13 +* 1.14 +* GLPK is free software: you can redistribute it and/or modify it 1.15 +* under the terms of the GNU General Public License as published by 1.16 +* the Free Software Foundation, either version 3 of the License, or 1.17 +* (at your option) any later version. 1.18 +* 1.19 +* GLPK is distributed in the hope that it will be useful, but WITHOUT 1.20 +* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY 1.21 +* or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public 1.22 +* License for more details. 1.23 +* 1.24 +* You should have received a copy of the GNU General Public License 1.25 +* along with GLPK. If not, see <http://www.gnu.org/licenses/>. 1.26 +***********************************************************************/ 1.27 + 1.28 +#include "glpapi.h" 1.29 + 1.30 +/*********************************************************************** 1.31 +* NAME 1.32 +* 1.33 +* glp_create_index - create the name index 1.34 +* 1.35 +* SYNOPSIS 1.36 +* 1.37 +* void glp_create_index(glp_prob *lp); 1.38 +* 1.39 +* DESCRIPTION 1.40 +* 1.41 +* The routine glp_create_index creates the name index for the 1.42 +* specified problem object. The name index is an auxiliary data 1.43 +* structure, which is intended to quickly (i.e. for logarithmic time) 1.44 +* find rows and columns by their names. 1.45 +* 1.46 +* This routine can be called at any time. If the name index already 1.47 +* exists, the routine does nothing. */ 1.48 + 1.49 +void glp_create_index(glp_prob *lp) 1.50 +{ GLPROW *row; 1.51 + GLPCOL *col; 1.52 + int i, j; 1.53 + /* create row name index */ 1.54 + if (lp->r_tree == NULL) 1.55 + { lp->r_tree = avl_create_tree(avl_strcmp, NULL); 1.56 + for (i = 1; i <= lp->m; i++) 1.57 + { row = lp->row[i]; 1.58 + xassert(row->node == NULL); 1.59 + if (row->name != NULL) 1.60 + { row->node = avl_insert_node(lp->r_tree, row->name); 1.61 + avl_set_node_link(row->node, row); 1.62 + } 1.63 + } 1.64 + } 1.65 + /* create column name index */ 1.66 + if (lp->c_tree == NULL) 1.67 + { lp->c_tree = avl_create_tree(avl_strcmp, NULL); 1.68 + for (j = 1; j <= lp->n; j++) 1.69 + { col = lp->col[j]; 1.70 + xassert(col->node == NULL); 1.71 + if (col->name != NULL) 1.72 + { col->node = avl_insert_node(lp->c_tree, col->name); 1.73 + avl_set_node_link(col->node, col); 1.74 + } 1.75 + } 1.76 + } 1.77 + return; 1.78 +} 1.79 + 1.80 +/*********************************************************************** 1.81 +* NAME 1.82 +* 1.83 +* glp_find_row - find row by its name 1.84 +* 1.85 +* SYNOPSIS 1.86 +* 1.87 +* int glp_find_row(glp_prob *lp, const char *name); 1.88 +* 1.89 +* RETURNS 1.90 +* 1.91 +* The routine glp_find_row returns the ordinal number of a row, 1.92 +* which is assigned (by the routine glp_set_row_name) the specified 1.93 +* symbolic name. If no such row exists, the routine returns 0. */ 1.94 + 1.95 +int glp_find_row(glp_prob *lp, const char *name) 1.96 +{ AVLNODE *node; 1.97 + int i = 0; 1.98 + if (lp->r_tree == NULL) 1.99 + xerror("glp_find_row: row name index does not exist\n"); 1.100 + if (!(name == NULL || name[0] == '\0' || strlen(name) > 255)) 1.101 + { node = avl_find_node(lp->r_tree, name); 1.102 + if (node != NULL) 1.103 + i = ((GLPROW *)avl_get_node_link(node))->i; 1.104 + } 1.105 + return i; 1.106 +} 1.107 + 1.108 +/*********************************************************************** 1.109 +* NAME 1.110 +* 1.111 +* glp_find_col - find column by its name 1.112 +* 1.113 +* SYNOPSIS 1.114 +* 1.115 +* int glp_find_col(glp_prob *lp, const char *name); 1.116 +* 1.117 +* RETURNS 1.118 +* 1.119 +* The routine glp_find_col returns the ordinal number of a column, 1.120 +* which is assigned (by the routine glp_set_col_name) the specified 1.121 +* symbolic name. If no such column exists, the routine returns 0. */ 1.122 + 1.123 +int glp_find_col(glp_prob *lp, const char *name) 1.124 +{ AVLNODE *node; 1.125 + int j = 0; 1.126 + if (lp->c_tree == NULL) 1.127 + xerror("glp_find_col: column name index does not exist\n"); 1.128 + if (!(name == NULL || name[0] == '\0' || strlen(name) > 255)) 1.129 + { node = avl_find_node(lp->c_tree, name); 1.130 + if (node != NULL) 1.131 + j = ((GLPCOL *)avl_get_node_link(node))->j; 1.132 + } 1.133 + return j; 1.134 +} 1.135 + 1.136 +/*********************************************************************** 1.137 +* NAME 1.138 +* 1.139 +* glp_delete_index - delete the name index 1.140 +* 1.141 +* SYNOPSIS 1.142 +* 1.143 +* void glp_delete_index(glp_prob *lp); 1.144 +* 1.145 +* DESCRIPTION 1.146 +* 1.147 +* The routine glp_delete_index deletes the name index previously 1.148 +* created by the routine glp_create_index and frees the memory 1.149 +* allocated to this auxiliary data structure. 1.150 +* 1.151 +* This routine can be called at any time. If the name index does not 1.152 +* exist, the routine does nothing. */ 1.153 + 1.154 +void glp_delete_index(glp_prob *lp) 1.155 +{ int i, j; 1.156 + /* delete row name index */ 1.157 + if (lp->r_tree != NULL) 1.158 + { for (i = 1; i <= lp->m; i++) lp->row[i]->node = NULL; 1.159 + avl_delete_tree(lp->r_tree), lp->r_tree = NULL; 1.160 + } 1.161 + /* delete column name index */ 1.162 + if (lp->c_tree != NULL) 1.163 + { for (j = 1; j <= lp->n; j++) lp->col[j]->node = NULL; 1.164 + avl_delete_tree(lp->c_tree), lp->c_tree = NULL; 1.165 + } 1.166 + return; 1.167 +} 1.168 + 1.169 +/* eof */