1 /* glpapi03.c (row and column searching routines) */
3 /***********************************************************************
4 * This code is part of GLPK (GNU Linear Programming Kit).
6 * Copyright (C) 2000, 2001, 2002, 2003, 2004, 2005, 2006, 2007, 2008,
7 * 2009, 2010 Andrew Makhorin, Department for Applied Informatics,
8 * Moscow Aviation Institute, Moscow, Russia. All rights reserved.
9 * E-mail: <mao@gnu.org>.
11 * GLPK is free software: you can redistribute it and/or modify it
12 * under the terms of the GNU General Public License as published by
13 * the Free Software Foundation, either version 3 of the License, or
14 * (at your option) any later version.
16 * GLPK is distributed in the hope that it will be useful, but WITHOUT
17 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
18 * or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public
19 * License for more details.
21 * You should have received a copy of the GNU General Public License
22 * along with GLPK. If not, see <http://www.gnu.org/licenses/>.
23 ***********************************************************************/
27 /***********************************************************************
30 * glp_create_index - create the name index
34 * void glp_create_index(glp_prob *lp);
38 * The routine glp_create_index creates the name index for the
39 * specified problem object. The name index is an auxiliary data
40 * structure, which is intended to quickly (i.e. for logarithmic time)
41 * find rows and columns by their names.
43 * This routine can be called at any time. If the name index already
44 * exists, the routine does nothing. */
46 void glp_create_index(glp_prob *lp)
50 /* create row name index */
51 if (lp->r_tree == NULL)
52 { lp->r_tree = avl_create_tree(avl_strcmp, NULL);
53 for (i = 1; i <= lp->m; i++)
55 xassert(row->node == NULL);
56 if (row->name != NULL)
57 { row->node = avl_insert_node(lp->r_tree, row->name);
58 avl_set_node_link(row->node, row);
62 /* create column name index */
63 if (lp->c_tree == NULL)
64 { lp->c_tree = avl_create_tree(avl_strcmp, NULL);
65 for (j = 1; j <= lp->n; j++)
67 xassert(col->node == NULL);
68 if (col->name != NULL)
69 { col->node = avl_insert_node(lp->c_tree, col->name);
70 avl_set_node_link(col->node, col);
77 /***********************************************************************
80 * glp_find_row - find row by its name
84 * int glp_find_row(glp_prob *lp, const char *name);
88 * The routine glp_find_row returns the ordinal number of a row,
89 * which is assigned (by the routine glp_set_row_name) the specified
90 * symbolic name. If no such row exists, the routine returns 0. */
92 int glp_find_row(glp_prob *lp, const char *name)
95 if (lp->r_tree == NULL)
96 xerror("glp_find_row: row name index does not exist\n");
97 if (!(name == NULL || name[0] == '\0' || strlen(name) > 255))
98 { node = avl_find_node(lp->r_tree, name);
100 i = ((GLPROW *)avl_get_node_link(node))->i;
105 /***********************************************************************
108 * glp_find_col - find column by its name
112 * int glp_find_col(glp_prob *lp, const char *name);
116 * The routine glp_find_col returns the ordinal number of a column,
117 * which is assigned (by the routine glp_set_col_name) the specified
118 * symbolic name. If no such column exists, the routine returns 0. */
120 int glp_find_col(glp_prob *lp, const char *name)
123 if (lp->c_tree == NULL)
124 xerror("glp_find_col: column name index does not exist\n");
125 if (!(name == NULL || name[0] == '\0' || strlen(name) > 255))
126 { node = avl_find_node(lp->c_tree, name);
128 j = ((GLPCOL *)avl_get_node_link(node))->j;
133 /***********************************************************************
136 * glp_delete_index - delete the name index
140 * void glp_delete_index(glp_prob *lp);
144 * The routine glp_delete_index deletes the name index previously
145 * created by the routine glp_create_index and frees the memory
146 * allocated to this auxiliary data structure.
148 * This routine can be called at any time. If the name index does not
149 * exist, the routine does nothing. */
151 void glp_delete_index(glp_prob *lp)
153 /* delete row name index */
154 if (lp->r_tree != NULL)
155 { for (i = 1; i <= lp->m; i++) lp->row[i]->node = NULL;
156 avl_delete_tree(lp->r_tree), lp->r_tree = NULL;
158 /* delete column name index */
159 if (lp->c_tree != NULL)
160 { for (j = 1; j <= lp->n; j++) lp->col[j]->node = NULL;
161 avl_delete_tree(lp->c_tree), lp->c_tree = NULL;