Debian Codegraph @

external/glpk/glpapi15.c

raw symbols SCIP
1 /* glpapi15.c (basic graph and network routines) */cxx . . $ `<file>/external/glpk/glpapi15.c`/
2
3 /***********************************************************************
4 * This code is part of GLPK (GNU Linear Programming Kit).
5 *
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: <[email protected]>.
10 *
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.
15 *
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.
20 *
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 ***********************************************************************/
24
25 #include "glpapi.h"cxx . . $ `<file>/external/glpk/glpapi.h`/
26
27 /* CAUTION: DO NOT CHANGE THE LIMITS BELOW */
28
29 #define NV_MAXcxx . . $ `external/glpk/glpapi15.c:29:9`! 100000000 /* = 100*10^6 */
30 /* maximal number of vertices in the graph */
31
32 #define NA_MAXcxx . . $ `external/glpk/glpapi15.c:32:9`! 500000000 /* = 500*10^6 */
33 /* maximal number of arcs in the graph */
34
35 /***********************************************************************
36 * NAME
37 *
38 * glp_create_graph - create graph
39 *
40 * SYNOPSIS
41 *
42 * glp_graph *glp_create_graph(int v_size, int a_size);
43 *
44 * DESCRIPTION
45 *
46 * The routine creates a new graph, which initially is empty, i.e. has
47 * no vertices and arcs.
48 *
49 * The parameter v_size specifies the size of data associated with each
50 * vertex of the graph (0 to 256 bytes).
51 *
52 * The parameter a_size specifies the size of data associated with each
53 * arc of the graph (0 to 256 bytes).
54 *
55 * RETURNS
56 *
57 * The routine returns a pointer to the graph created. */
58
59 static void create_graphcxx . . $ create_graph(fd6d4ec766750ee3).(glp_graphcxx . . $ glp_graph# *G, int v_size, int a_size)
60 { G->poolcxx . . $ _glp_graph#pool. = dmp_create_poolcxx . . $ `external/glpk/glpdmp.h:58:9`!();
61 G->namecxx . . $ _glp_graph#name. = NULLcxx . . $ `/usr/lib/gcc/x86_64-linux-gnu/15/include/stddef.h:419:9`!;
62 G->nv_maxcxx . . $ _glp_graph#nv_max. = 50;
63 G->nvcxx . . $ _glp_graph#nv. = G->nacxx . . $ _glp_graph#na. = 0;
64 G->vcxx . . $ _glp_graph#v. = xcalloccxx . . $ `external/glpk/glpenv.h:171:9`!(1+G->nv_maxcxx . . $ _glp_graph#nv_max., sizeof(glp_vertexcxx . . $ glp_vertex# *));
65 G->indexcxx . . $ _glp_graph#index. = NULLcxx . . $ `/usr/lib/gcc/x86_64-linux-gnu/15/include/stddef.h:419:9`!;
66 G->v_sizecxx . . $ _glp_graph#v_size. = v_size;
67 G->a_sizecxx . . $ _glp_graph#a_size. = a_size;
68 return;
69 }
70
71 glp_graphcxx . . $ glp_graph# *glp_create_graphcxx . . $ glp_create_graph(db26b9e719c88335).(int v_size, int a_size)
72 { glp_graphcxx . . $ glp_graph# *G;
73 if (!(0 <= v_size && v_size <= 256))
74 xerrorcxx . . $ `external/glpk/glpenv.h:158:9`!("glp_create_graph: v_size = %d; invalid size of vertex "
75 "data\n", v_size);
76 if (!(0 <= a_size && a_size <= 256))
77 xerrorcxx . . $ `external/glpk/glpenv.h:158:9`!("glp_create_graph: a_size = %d; invalid size of arc dat"
78 "a\n", a_size);
79 G = xmalloccxx . . $ `external/glpk/glpenv.h:167:9`!(sizeof(glp_graphcxx . . $ glp_graph#));
80 create_graphcxx . . $ create_graph(fd6d4ec766750ee3).(G, v_size, a_size);
81 return G;
82 }
83
84 /***********************************************************************
85 * NAME
86 *
87 * glp_set_graph_name - assign (change) graph name
88 *
89 * SYNOPSIS
90 *
91 * void glp_set_graph_name(glp_graph *G, const char *name);
92 *
93 * DESCRIPTION
94 *
95 * The routine glp_set_graph_name assigns a symbolic name specified by
96 * the character string name (1 to 255 chars) to the graph.
97 *
98 * If the parameter name is NULL or an empty string, the routine erases
99 * the existing symbolic name of the graph. */
100
101 void glp_set_graph_namecxx . . $ glp_set_graph_name(2f581b6858c1a533).(glp_graphcxx . . $ glp_graph# *G, const char *name)
102 { if (G->namecxx . . $ _glp_graph#name. != NULLcxx . . $ `/usr/lib/gcc/x86_64-linux-gnu/15/include/stddef.h:419:9`!)
103 { dmp_free_atomcxx . . $ `external/glpk/glpdmp.h:66:9`!(G->poolcxx . . $ _glp_graph#pool., G->namecxx . . $ _glp_graph#name., strlencxx . . $ strlen(751346f8406fd082).(G->namecxx . . $ _glp_graph#name.)+1);
104 G->namecxx . . $ _glp_graph#name. = NULLcxx . . $ `/usr/lib/gcc/x86_64-linux-gnu/15/include/stddef.h:419:9`!;
105 }
106 if (!(name == NULLcxx . . $ `/usr/lib/gcc/x86_64-linux-gnu/15/include/stddef.h:419:9`! || name[0] == '\0'))
107 { int j;
108 for (j = 0; name[j] != '\0'; j++)
109 { if (j == 256)
110 xerrorcxx . . $ `external/glpk/glpenv.h:158:9`!("glp_set_graph_name: graph name too long\n");
111 if (iscntrlcxx . . $ `<external>/17904084882347303253/ctype.h:191:10`!((unsigned char)name[j]))
112 xerrorcxx . . $ `external/glpk/glpenv.h:158:9`!("glp_set_graph_name: graph name contains invalid "
113 "character(s)\n");
114 }
115 G->namecxx . . $ _glp_graph#name. = dmp_get_atomcxx . . $ `external/glpk/glpdmp.h:62:9`!(G->poolcxx . . $ _glp_graph#pool., strlencxx . . $ strlen(751346f8406fd082).(name)+1);
116 strcpycxx . . $ strcpy(b7b3a83273496486).(G->namecxx . . $ _glp_graph#name., name);
117 }
118 return;
119 }
120
121 /***********************************************************************
122 * NAME
123 *
124 * glp_add_vertices - add new vertices to graph
125 *
126 * SYNOPSIS
127 *
128 * int glp_add_vertices(glp_graph *G, int nadd);
129 *
130 * DESCRIPTION
131 *
132 * The routine glp_add_vertices adds nadd vertices to the specified
133 * graph. New vertices are always added to the end of the vertex list,
134 * so ordinal numbers of existing vertices remain unchanged.
135 *
136 * Being added each new vertex is isolated (has no incident arcs).
137 *
138 * RETURNS
139 *
140 * The routine glp_add_vertices returns an ordinal number of the first
141 * new vertex added to the graph. */
142
143 int glp_add_verticescxx . . $ glp_add_vertices(9d5fec13eee488ca).(glp_graphcxx . . $ glp_graph# *G, int nadd)
144 { int i, nv_new;
145 if (nadd < 1)
146 xerrorcxx . . $ `external/glpk/glpenv.h:158:9`!("glp_add_vertices: nadd = %d; invalid number of vertice"
147 "s\n", nadd);
148 if (nadd > NV_MAXcxx . . $ `external/glpk/glpapi15.c:29:9`! - G->nvcxx . . $ _glp_graph#nv.)
149 xerrorcxx . . $ `external/glpk/glpenv.h:158:9`!("glp_add_vertices: nadd = %d; too many vertices\n",
150 nadd);
151 /* determine new number of vertices */
152 nv_new = G->nvcxx . . $ _glp_graph#nv. + nadd;
153 /* increase the room, if necessary */
154 if (G->nv_maxcxx . . $ _glp_graph#nv_max. < nv_new)
155 { glp_vertexcxx . . $ glp_vertex# **save = G->vcxx . . $ _glp_graph#v.;
156 while (G->nv_maxcxx . . $ _glp_graph#nv_max. < nv_new)
157 { G->nv_maxcxx . . $ _glp_graph#nv_max. += G->nv_maxcxx . . $ _glp_graph#nv_max.;
158 xassertcxx . . $ `external/glpk/glpenv.h:162:9`!(G->nv_max > 0);
159 }
160 G->vcxx . . $ _glp_graph#v. = xcalloccxx . . $ `external/glpk/glpenv.h:171:9`!(1+G->nv_maxcxx . . $ _glp_graph#nv_max., sizeof(glp_vertexcxx . . $ glp_vertex# *));
161 memcpycxx . . $ memcpy(cc817cb175f282d).(&G->vcxx . . $ _glp_graph#v.[1], &save[1], G->nvcxx . . $ _glp_graph#nv. * sizeof(glp_vertexcxx . . $ glp_vertex# *));
162 xfreecxx . . $ `external/glpk/glpenv.h:175:9`!(save);
163 }
164 /* add new vertices to the end of the vertex list */
165 for (i = G->nvcxx . . $ _glp_graph#nv.+1; i <= nv_new; i++)
166 { glp_vertexcxx . . $ glp_vertex# *v;
167 G->vcxx . . $ _glp_graph#v.[i] = v = dmp_get_atomcxx . . $ `external/glpk/glpdmp.h:62:9`!(G->poolcxx . . $ _glp_graph#pool., sizeof(glp_vertexcxx . . $ glp_vertex#));
168 v->icxx . . $ _glp_vertex#i. = i;
169 v->namecxx . . $ _glp_vertex#name. = NULLcxx . . $ `/usr/lib/gcc/x86_64-linux-gnu/15/include/stddef.h:419:9`!;
170 v->entrycxx . . $ _glp_vertex#entry. = NULLcxx . . $ `/usr/lib/gcc/x86_64-linux-gnu/15/include/stddef.h:419:9`!;
171 if (G->v_sizecxx . . $ _glp_graph#v_size. == 0)
172 v->datacxx . . $ _glp_vertex#data. = NULLcxx . . $ `/usr/lib/gcc/x86_64-linux-gnu/15/include/stddef.h:419:9`!;
173 else
174 { v->datacxx . . $ _glp_vertex#data. = dmp_get_atomcxx . . $ `external/glpk/glpdmp.h:62:9`!(G->poolcxx . . $ _glp_graph#pool., G->v_sizecxx . . $ _glp_graph#v_size.);
175 memsetcxx . . $ memset(d1de1e4fb215f1c6).(v->datacxx . . $ _glp_vertex#data., 0, G->v_sizecxx . . $ _glp_graph#v_size.);
176 }
177 v->tempcxx . . $ _glp_vertex#temp. = NULLcxx . . $ `/usr/lib/gcc/x86_64-linux-gnu/15/include/stddef.h:419:9`!;
178 v->incxx . . $ _glp_vertex#in. = v->outcxx . . $ _glp_vertex#out. = NULLcxx . . $ `/usr/lib/gcc/x86_64-linux-gnu/15/include/stddef.h:419:9`!;
179 }
180 /* set new number of vertices */
181 G->nvcxx . . $ _glp_graph#nv. = nv_new;
182 /* return the ordinal number of the first vertex added */
183 return nv_new - nadd + 1;
184 }
185
186 /**********************************************************************/
187
188 void glp_set_vertex_namecxx . . $ glp_set_vertex_name(71bf418d6cb83dd4).(glp_graphcxx . . $ glp_graph# *G, int i, const char *name)
189 { /* assign (change) vertex name */
190 glp_vertexcxx . . $ glp_vertex# *v;
191 if (!(1 <= i && i <= G->nvcxx . . $ _glp_graph#nv.))
192 xerrorcxx . . $ `external/glpk/glpenv.h:158:9`!("glp_set_vertex_name: i = %d; vertex number out of rang"
193 "e\n", i);
194 v = G->vcxx . . $ _glp_graph#v.[i];
195 if (v->namecxx . . $ _glp_vertex#name. != NULLcxx . . $ `/usr/lib/gcc/x86_64-linux-gnu/15/include/stddef.h:419:9`!)
196 { if (v->entrycxx . . $ _glp_vertex#entry. != NULLcxx . . $ `/usr/lib/gcc/x86_64-linux-gnu/15/include/stddef.h:419:9`!)
197 { xassertcxx . . $ `external/glpk/glpenv.h:162:9`!(G->index != NULLcxx . . $ `/usr/lib/gcc/x86_64-linux-gnu/15/include/stddef.h:419:9`!);
198 avl_delete_nodecxx . . $ `external/glpk/glpavl.h:113:9`!(G->indexcxx . . $ _glp_graph#index., v->entrycxx . . $ _glp_vertex#entry.);
199 v->entrycxx . . $ _glp_vertex#entry. = NULLcxx . . $ `/usr/lib/gcc/x86_64-linux-gnu/15/include/stddef.h:419:9`!;
200 }
201 dmp_free_atomcxx . . $ `external/glpk/glpdmp.h:66:9`!(G->poolcxx . . $ _glp_graph#pool., v->namecxx . . $ _glp_vertex#name., strlencxx . . $ strlen(751346f8406fd082).(v->namecxx . . $ _glp_vertex#name.)+1);
202 v->namecxx . . $ _glp_vertex#name. = NULLcxx . . $ `/usr/lib/gcc/x86_64-linux-gnu/15/include/stddef.h:419:9`!;
203 }
204 if (!(name == NULLcxx . . $ `/usr/lib/gcc/x86_64-linux-gnu/15/include/stddef.h:419:9`! || name[0] == '\0'))
205 { int k;
206 for (k = 0; name[k] != '\0'; k++)
207 { if (k == 256)
208 xerrorcxx . . $ `external/glpk/glpenv.h:158:9`!("glp_set_vertex_name: i = %d; vertex name too lon"
209 "g\n", i);
210 if (iscntrlcxx . . $ `<external>/17904084882347303253/ctype.h:191:10`!((unsigned char)name[k]))
211 xerrorcxx . . $ `external/glpk/glpenv.h:158:9`!("glp_set_vertex_name: i = %d; vertex name contain"
212 "s invalid character(s)\n", i);
213 }
214 v->namecxx . . $ _glp_vertex#name. = dmp_get_atomcxx . . $ `external/glpk/glpdmp.h:62:9`!(G->poolcxx . . $ _glp_graph#pool., strlencxx . . $ strlen(751346f8406fd082).(name)+1);
215 strcpycxx . . $ strcpy(b7b3a83273496486).(v->namecxx . . $ _glp_vertex#name., name);
216 if (G->indexcxx . . $ _glp_graph#index. != NULLcxx . . $ `/usr/lib/gcc/x86_64-linux-gnu/15/include/stddef.h:419:9`!)
217 { xassertcxx . . $ `external/glpk/glpenv.h:162:9`!(v->entry == NULLcxx . . $ `/usr/lib/gcc/x86_64-linux-gnu/15/include/stddef.h:419:9`!);
218 v->entrycxx . . $ _glp_vertex#entry. = avl_insert_nodecxx . . $ `external/glpk/glpavl.h:89:9`!(G->indexcxx . . $ _glp_graph#index., v->namecxx . . $ _glp_vertex#name.);
219 avl_set_node_linkcxx . . $ `external/glpk/glpavl.h:97:9`!(v->entrycxx . . $ _glp_vertex#entry., v);
220 }
221 }
222 return;
223 }
224
225 /***********************************************************************
226 * NAME
227 *
228 * glp_add_arc - add new arc to graph
229 *
230 * SYNOPSIS
231 *
232 * glp_arc *glp_add_arc(glp_graph *G, int i, int j);
233 *
234 * DESCRIPTION
235 *
236 * The routine glp_add_arc adds a new arc to the specified graph.
237 *
238 * The parameters i and j specify the ordinal numbers of, resp., tail
239 * and head vertices of the arc. Note that self-loops and multiple arcs
240 * are allowed.
241 *
242 * RETURNS
243 *
244 * The routine glp_add_arc returns a pointer to the arc added. */
245
246 glp_arccxx . . $ glp_arc# *glp_add_arccxx . . $ glp_add_arc(e54dd140876db879).(glp_graphcxx . . $ glp_graph# *G, int i, int j)
247 { glp_arccxx . . $ glp_arc# *a;
248 if (!(1 <= i && i <= G->nvcxx . . $ _glp_graph#nv.))
249 xerrorcxx . . $ `external/glpk/glpenv.h:158:9`!("glp_add_arc: i = %d; tail vertex number out of range\n"
250 , i);
251 if (!(1 <= j && j <= G->nvcxx . . $ _glp_graph#nv.))
252 xerrorcxx . . $ `external/glpk/glpenv.h:158:9`!("glp_add_arc: j = %d; head vertex number out of range\n"
253 , j);
254 if (G->nacxx . . $ _glp_graph#na. == NA_MAXcxx . . $ `external/glpk/glpapi15.c:32:9`!)
255 xerrorcxx . . $ `external/glpk/glpenv.h:158:9`!("glp_add_arc: too many arcs\n");
256 a = dmp_get_atomcxx . . $ `external/glpk/glpdmp.h:62:9`!(G->poolcxx . . $ _glp_graph#pool., sizeof(glp_arccxx . . $ glp_arc#));
257 a->tailcxx . . $ _glp_arc#tail. = G->vcxx . . $ _glp_graph#v.[i];
258 a->headcxx . . $ _glp_arc#head. = G->vcxx . . $ _glp_graph#v.[j];
259 if (G->a_sizecxx . . $ _glp_graph#a_size. == 0)
260 a->datacxx . . $ _glp_arc#data. = NULLcxx . . $ `/usr/lib/gcc/x86_64-linux-gnu/15/include/stddef.h:419:9`!;
261 else
262 { a->datacxx . . $ _glp_arc#data. = dmp_get_atomcxx . . $ `external/glpk/glpdmp.h:62:9`!(G->poolcxx . . $ _glp_graph#pool., G->a_sizecxx . . $ _glp_graph#a_size.);
263 memsetcxx . . $ memset(d1de1e4fb215f1c6).(a->datacxx . . $ _glp_arc#data., 0, G->a_sizecxx . . $ _glp_graph#a_size.);
264 }
265 a->tempcxx . . $ _glp_arc#temp. = NULLcxx . . $ `/usr/lib/gcc/x86_64-linux-gnu/15/include/stddef.h:419:9`!;
266 a->t_prevcxx . . $ _glp_arc#t_prev. = NULLcxx . . $ `/usr/lib/gcc/x86_64-linux-gnu/15/include/stddef.h:419:9`!;
267 a->t_nextcxx . . $ _glp_arc#t_next. = G->vcxx . . $ _glp_graph#v.[i]->outcxx . . $ _glp_vertex#out.;
268 if (a->t_nextcxx . . $ _glp_arc#t_next. != NULLcxx . . $ `/usr/lib/gcc/x86_64-linux-gnu/15/include/stddef.h:419:9`!) a->t_nextcxx . . $ _glp_arc#t_next.->t_prevcxx . . $ _glp_arc#t_prev. = a;
269 a->h_prevcxx . . $ _glp_arc#h_prev. = NULLcxx . . $ `/usr/lib/gcc/x86_64-linux-gnu/15/include/stddef.h:419:9`!;
270 a->h_nextcxx . . $ _glp_arc#h_next. = G->vcxx . . $ _glp_graph#v.[j]->incxx . . $ _glp_vertex#in.;
271 if (a->h_nextcxx . . $ _glp_arc#h_next. != NULLcxx . . $ `/usr/lib/gcc/x86_64-linux-gnu/15/include/stddef.h:419:9`!) a->h_nextcxx . . $ _glp_arc#h_next.->h_prevcxx . . $ _glp_arc#h_prev. = a;
272 G->vcxx . . $ _glp_graph#v.[i]->outcxx . . $ _glp_vertex#out. = G->vcxx . . $ _glp_graph#v.[j]->incxx . . $ _glp_vertex#in. = a;
273 G->nacxx . . $ _glp_graph#na.++;
274 return a;
275 }
276
277 /***********************************************************************
278 * NAME
279 *
280 * glp_del_vertices - delete vertices from graph
281 *
282 * SYNOPSIS
283 *
284 * void glp_del_vertices(glp_graph *G, int ndel, const int num[]);
285 *
286 * DESCRIPTION
287 *
288 * The routine glp_del_vertices deletes vertices along with all
289 * incident arcs from the specified graph. Ordinal numbers of vertices
290 * to be deleted should be placed in locations num[1], ..., num[ndel],
291 * ndel > 0.
292 *
293 * Note that deleting vertices involves changing ordinal numbers of
294 * other vertices remaining in the graph. New ordinal numbers of the
295 * remaining vertices are assigned under the assumption that the
296 * original order of vertices is not changed. */
297
298 void glp_del_verticescxx . . $ glp_del_vertices(5082857f14926bca).(glp_graphcxx . . $ glp_graph# *G, int ndel, const int num[])
299 { glp_vertexcxx . . $ glp_vertex# *v;
300 int i, k, nv_new;
301 /* scan the list of vertices to be deleted */
302 if (!(1 <= ndel && ndel <= G->nvcxx . . $ _glp_graph#nv.))
303 xerrorcxx . . $ `external/glpk/glpenv.h:158:9`!("glp_del_vertices: ndel = %d; invalid number of vertice"
304 "s\n", ndel);
305 for (k = 1; k <= ndel; k++)
306 { /* take the number of vertex to be deleted */
307 i = num[k];
308 /* obtain pointer to i-th vertex */
309 if (!(1 <= i && i <= G->nvcxx . . $ _glp_graph#nv.))
310 xerrorcxx . . $ `external/glpk/glpenv.h:158:9`!("glp_del_vertices: num[%d] = %d; vertex number out o"
311 "f range\n", k, i);
312 v = G->vcxx . . $ _glp_graph#v.[i];
313 /* check that the vertex is not marked yet */
314 if (v->icxx . . $ _glp_vertex#i. == 0)
315 xerrorcxx . . $ `external/glpk/glpenv.h:158:9`!("glp_del_vertices: num[%d] = %d; duplicate vertex nu"
316 "mbers not allowed\n", k, i);
317 /* erase symbolic name assigned to the vertex */
318 glp_set_vertex_namecxx . . $ glp_set_vertex_name(71bf418d6cb83dd4).(G, i, NULLcxx . . $ `/usr/lib/gcc/x86_64-linux-gnu/15/include/stddef.h:419:9`!);
319 xassertcxx . . $ `external/glpk/glpenv.h:162:9`!(v->name == NULLcxx . . $ `/usr/lib/gcc/x86_64-linux-gnu/15/include/stddef.h:419:9`!);
320 xassertcxx . . $ `external/glpk/glpenv.h:162:9`!(v->entry == NULLcxx . . $ `/usr/lib/gcc/x86_64-linux-gnu/15/include/stddef.h:419:9`!);
321 /* free vertex data, if allocated */
322 if (v->datacxx . . $ _glp_vertex#data. != NULLcxx . . $ `/usr/lib/gcc/x86_64-linux-gnu/15/include/stddef.h:419:9`!)
323 dmp_free_atomcxx . . $ `external/glpk/glpdmp.h:66:9`!(G->poolcxx . . $ _glp_graph#pool., v->datacxx . . $ _glp_vertex#data., G->v_sizecxx . . $ _glp_graph#v_size.);
324 /* delete all incoming arcs */
325 while (v->incxx . . $ _glp_vertex#in. != NULLcxx . . $ `/usr/lib/gcc/x86_64-linux-gnu/15/include/stddef.h:419:9`!)
326 glp_del_arccxx . . $ glp_del_arc(ba307328f5fbb0db).(G, v->incxx . . $ _glp_vertex#in.);
327 /* delete all outgoing arcs */
328 while (v->outcxx . . $ _glp_vertex#out. != NULLcxx . . $ `/usr/lib/gcc/x86_64-linux-gnu/15/include/stddef.h:419:9`!)
329 glp_del_arccxx . . $ glp_del_arc(ba307328f5fbb0db).(G, v->outcxx . . $ _glp_vertex#out.);
330 /* mark the vertex to be deleted */
331 v->icxx . . $ _glp_vertex#i. = 0;
332 }
333 /* delete all marked vertices from the vertex list */
334 nv_new = 0;
335 for (i = 1; i <= G->nvcxx . . $ _glp_graph#nv.; i++)
336 { /* obtain pointer to i-th vertex */
337 v = G->vcxx . . $ _glp_graph#v.[i];
338 /* check if the vertex is marked */
339 if (v->icxx . . $ _glp_vertex#i. == 0)
340 { /* it is marked, delete it */
341 dmp_free_atomcxx . . $ `external/glpk/glpdmp.h:66:9`!(G->poolcxx . . $ _glp_graph#pool., v, sizeof(glp_vertexcxx . . $ glp_vertex#));
342 }
343 else
344 { /* it is not marked, keep it */
345 v->icxx . . $ _glp_vertex#i. = ++nv_new;
346 G->vcxx . . $ _glp_graph#v.[v->icxx . . $ _glp_vertex#i.] = v;
347 }
348 }
349 /* set new number of vertices in the graph */
350 G->nvcxx . . $ _glp_graph#nv. = nv_new;
351 return;
352 }
353
354 /***********************************************************************
355 * NAME
356 *
357 * glp_del_arc - delete arc from graph
358 *
359 * SYNOPSIS
360 *
361 * void glp_del_arc(glp_graph *G, glp_arc *a);
362 *
363 * DESCRIPTION
364 *
365 * The routine glp_del_arc deletes an arc from the specified graph.
366 * The arc to be deleted must exist. */
367
368 void glp_del_arccxx . . $ glp_del_arc(ba307328f5fbb0db).(glp_graphcxx . . $ glp_graph# *G, glp_arccxx . . $ glp_arc# *a)
369 { /* some sanity checks */
370 xassertcxx . . $ `external/glpk/glpenv.h:162:9`!(G->na > 0);
371 xassertcxx . . $ `external/glpk/glpenv.h:162:9`!(1 <= a->tail->i && a->tail->i <= G->nv);
372 xassertcxx . . $ `external/glpk/glpenv.h:162:9`!(a->tail == G->v[a->tail->i]);
373 xassertcxx . . $ `external/glpk/glpenv.h:162:9`!(1 <= a->head->i && a->head->i <= G->nv);
374 xassertcxx . . $ `external/glpk/glpenv.h:162:9`!(a->head == G->v[a->head->i]);
375 /* remove the arc from the list of incoming arcs */
376 if (a->h_prevcxx . . $ _glp_arc#h_prev. == NULLcxx . . $ `/usr/lib/gcc/x86_64-linux-gnu/15/include/stddef.h:419:9`!)
377 a->headcxx . . $ _glp_arc#head.->incxx . . $ _glp_vertex#in. = a->h_nextcxx . . $ _glp_arc#h_next.;
378 else
379 a->h_prevcxx . . $ _glp_arc#h_prev.->h_nextcxx . . $ _glp_arc#h_next. = a->h_nextcxx . . $ _glp_arc#h_next.;
380 if (a->h_nextcxx . . $ _glp_arc#h_next. == NULLcxx . . $ `/usr/lib/gcc/x86_64-linux-gnu/15/include/stddef.h:419:9`!)
381 ;
382 else
383 a->h_nextcxx . . $ _glp_arc#h_next.->h_prevcxx . . $ _glp_arc#h_prev. = a->h_prevcxx . . $ _glp_arc#h_prev.;
384 /* remove the arc from the list of outgoing arcs */
385 if (a->t_prevcxx . . $ _glp_arc#t_prev. == NULLcxx . . $ `/usr/lib/gcc/x86_64-linux-gnu/15/include/stddef.h:419:9`!)
386 a->tailcxx . . $ _glp_arc#tail.->outcxx . . $ _glp_vertex#out. = a->t_nextcxx . . $ _glp_arc#t_next.;
387 else
388 a->t_prevcxx . . $ _glp_arc#t_prev.->t_nextcxx . . $ _glp_arc#t_next. = a->t_nextcxx . . $ _glp_arc#t_next.;
389 if (a->t_nextcxx . . $ _glp_arc#t_next. == NULLcxx . . $ `/usr/lib/gcc/x86_64-linux-gnu/15/include/stddef.h:419:9`!)
390 ;
391 else
392 a->t_nextcxx . . $ _glp_arc#t_next.->t_prevcxx . . $ _glp_arc#t_prev. = a->t_prevcxx . . $ _glp_arc#t_prev.;
393 /* free arc data, if allocated */
394 if (a->datacxx . . $ _glp_arc#data. != NULLcxx . . $ `/usr/lib/gcc/x86_64-linux-gnu/15/include/stddef.h:419:9`!)
395 dmp_free_atomcxx . . $ `external/glpk/glpdmp.h:66:9`!(G->poolcxx . . $ _glp_graph#pool., a->datacxx . . $ _glp_arc#data., G->a_sizecxx . . $ _glp_graph#a_size.);
396 /* delete the arc from the graph */
397 dmp_free_atomcxx . . $ `external/glpk/glpdmp.h:66:9`!(G->poolcxx . . $ _glp_graph#pool., a, sizeof(glp_arccxx . . $ glp_arc#));
398 G->nacxx . . $ _glp_graph#na.--;
399 return;
400 }
401
402 /***********************************************************************
403 * NAME
404 *
405 * glp_erase_graph - erase graph content
406 *
407 * SYNOPSIS
408 *
409 * void glp_erase_graph(glp_graph *G, int v_size, int a_size);
410 *
411 * DESCRIPTION
412 *
413 * The routine glp_erase_graph erases the content of the specified
414 * graph. The effect of this operation is the same as if the graph
415 * would be deleted with the routine glp_delete_graph and then created
416 * anew with the routine glp_create_graph, with exception that the
417 * handle (pointer) to the graph remains valid. */
418
419 static void delete_graphcxx . . $ delete_graph(10592e6c475fb878).(glp_graphcxx . . $ glp_graph# *G)
420 { dmp_delete_poolcxx . . $ `external/glpk/glpdmp.h:74:9`!(G->poolcxx . . $ _glp_graph#pool.);
421 xfreecxx . . $ `external/glpk/glpenv.h:175:9`!(G->vcxx . . $ _glp_graph#v.);
422 if (G->indexcxx . . $ _glp_graph#index. != NULLcxx . . $ `/usr/lib/gcc/x86_64-linux-gnu/15/include/stddef.h:419:9`!) avl_delete_treecxx . . $ `external/glpk/glpavl.h:117:9`!(G->indexcxx . . $ _glp_graph#index.);
423 return;
424 }
425
426 void glp_erase_graphcxx . . $ glp_erase_graph(fd6d4ec766750ee3).(glp_graphcxx . . $ glp_graph# *G, int v_size, int a_size)
427 { if (!(0 <= v_size && v_size <= 256))
428 xerrorcxx . . $ `external/glpk/glpenv.h:158:9`!("glp_erase_graph: v_size = %d; invalid size of vertex d"
429 "ata\n", v_size);
430 if (!(0 <= a_size && a_size <= 256))
431 xerrorcxx . . $ `external/glpk/glpenv.h:158:9`!("glp_erase_graph: a_size = %d; invalid size of arc data"
432 "\n", a_size);
433 delete_graphcxx . . $ delete_graph(10592e6c475fb878).(G);
434 create_graphcxx . . $ create_graph(fd6d4ec766750ee3).(G, v_size, a_size);
435 return;
436 }
437
438 /***********************************************************************
439 * NAME
440 *
441 * glp_delete_graph - delete graph
442 *
443 * SYNOPSIS
444 *
445 * void glp_delete_graph(glp_graph *G);
446 *
447 * DESCRIPTION
448 *
449 * The routine glp_delete_graph deletes the specified graph and frees
450 * all the memory allocated to this program object. */
451
452 void glp_delete_graphcxx . . $ glp_delete_graph(10592e6c475fb878).(glp_graphcxx . . $ glp_graph# *G)
453 { delete_graphcxx . . $ delete_graph(10592e6c475fb878).(G);
454 xfreecxx . . $ `external/glpk/glpenv.h:175:9`!(G);
455 return;
456 }
457
458 /**********************************************************************/
459
460 void glp_create_v_indexcxx . . $ glp_create_v_index(10592e6c475fb878).(glp_graphcxx . . $ glp_graph# *G)
461 { /* create vertex name index */
462 glp_vertexcxx . . $ glp_vertex# *v;
463 int i;
464 if (G->indexcxx . . $ _glp_graph#index. == NULLcxx . . $ `/usr/lib/gcc/x86_64-linux-gnu/15/include/stddef.h:419:9`!)
465 { G->indexcxx . . $ _glp_graph#index. = avl_create_treecxx . . $ `external/glpk/glpavl.h:80:9`!(avl_strcmpcxx . . $ `external/glpk/glpavl.h:85:9`!, NULLcxx . . $ `/usr/lib/gcc/x86_64-linux-gnu/15/include/stddef.h:419:9`!);
466 for (i = 1; i <= G->nvcxx . . $ _glp_graph#nv.; i++)
467 { v = G->vcxx . . $ _glp_graph#v.[i];
468 xassertcxx . . $ `external/glpk/glpenv.h:162:9`!(v->entry == NULLcxx . . $ `/usr/lib/gcc/x86_64-linux-gnu/15/include/stddef.h:419:9`!);
469 if (v->namecxx . . $ _glp_vertex#name. != NULLcxx . . $ `/usr/lib/gcc/x86_64-linux-gnu/15/include/stddef.h:419:9`!)
470 { v->entrycxx . . $ _glp_vertex#entry. = avl_insert_nodecxx . . $ `external/glpk/glpavl.h:89:9`!(G->indexcxx . . $ _glp_graph#index., v->namecxx . . $ _glp_vertex#name.);
471 avl_set_node_linkcxx . . $ `external/glpk/glpavl.h:97:9`!(v->entrycxx . . $ _glp_vertex#entry., v);
472 }
473 }
474 }
475 return;
476 }
477
478 int glp_find_vertexcxx . . $ glp_find_vertex(df29dc7bf65d5d53).(glp_graphcxx . . $ glp_graph# *G, const char *name)
479 { /* find vertex by its name */
480 AVLNODEcxx . . $ AVLNODE# *node;
481 int i = 0;
482 if (G->indexcxx . . $ _glp_graph#index. == NULLcxx . . $ `/usr/lib/gcc/x86_64-linux-gnu/15/include/stddef.h:419:9`!)
483 xerrorcxx . . $ `external/glpk/glpenv.h:158:9`!("glp_find_vertex: vertex name index does not exist\n");
484 if (!(name == NULLcxx . . $ `/usr/lib/gcc/x86_64-linux-gnu/15/include/stddef.h:419:9`! || name[0] == '\0' || strlencxx . . $ strlen(751346f8406fd082).(name) > 255))
485 { node = avl_find_nodecxx . . $ `external/glpk/glpavl.h:101:9`!(G->indexcxx . . $ _glp_graph#index., name);
486 if (node != NULLcxx . . $ `/usr/lib/gcc/x86_64-linux-gnu/15/include/stddef.h:419:9`!)
487 i = ((glp_vertexcxx . . $ glp_vertex# *)avl_get_node_linkcxx . . $ `external/glpk/glpavl.h:109:9`!(node))->icxx . . $ _glp_vertex#i.;
488 }
489 return i;
490 }
491
492 void glp_delete_v_indexcxx . . $ glp_delete_v_index(10592e6c475fb878).(glp_graphcxx . . $ glp_graph# *G)
493 { /* delete vertex name index */
494 int i;
495 if (G->indexcxx . . $ _glp_graph#index. != NULLcxx . . $ `/usr/lib/gcc/x86_64-linux-gnu/15/include/stddef.h:419:9`!)
496 { avl_delete_treecxx . . $ `external/glpk/glpavl.h:117:9`!(G->indexcxx . . $ _glp_graph#index.), G->indexcxx . . $ _glp_graph#index. = NULLcxx . . $ `/usr/lib/gcc/x86_64-linux-gnu/15/include/stddef.h:419:9`!;
497 for (i = 1; i <= G->nvcxx . . $ _glp_graph#nv.; i++) G->vcxx . . $ _glp_graph#v.[i]->entrycxx . . $ _glp_vertex#entry. = NULLcxx . . $ `/usr/lib/gcc/x86_64-linux-gnu/15/include/stddef.h:419:9`!;
498 }
499 return;
500 }
501
502 /***********************************************************************
503 * NAME
504 *
505 * glp_read_graph - read graph from plain text file
506 *
507 * SYNOPSIS
508 *
509 * int glp_read_graph(glp_graph *G, const char *fname);
510 *
511 * DESCRIPTION
512 *
513 * The routine glp_read_graph reads a graph from a plain text file.
514 *
515 * RETURNS
516 *
517 * If the operation was successful, the routine returns zero. Otherwise
518 * it prints an error message and returns non-zero. */
519
520 int glp_read_graphcxx . . $ glp_read_graph(df29dc7bf65d5d53).(glp_graphcxx . . $ glp_graph# *G, const char *fname)
521 { glp_datacxx . . $ glp_data# *data;
522 jmp_bufcxx . . $ jmp_buf# jump;
523 int nv, na, i, j, k, ret;
524 glp_erase_graphcxx . . $ glp_erase_graph(fd6d4ec766750ee3).(G, G->v_sizecxx . . $ _glp_graph#v_size., G->a_sizecxx . . $ _glp_graph#a_size.);
525 xprintfcxx . . $ `external/glpk/glpenv.h:145:9`!("Reading graph from `%s'...\n", fname);
526 data = glp_sdf_open_filecxx . . $ glp_sdf_open_file(48b6cd6ae4c46f0f).(fname);
527 if (data == NULLcxx . . $ `/usr/lib/gcc/x86_64-linux-gnu/15/include/stddef.h:419:9`!)
528 { ret = 1;
529 goto done;
530 }
531 if (setjmpcxx . . $ `<external>/4367339001007250937/setjmp.h:49:9`!(jump))
532 { ret = 1;
533 goto done;
534 }
535 glp_sdf_set_jumpcxx . . $ glp_sdf_set_jump(b0c068eebba1df51).(data, jump);
536 nv = glp_sdf_read_intcxx . . $ glp_sdf_read_int(d55aa0a7098b3be0).(data);
537 if (nv < 0)
538 glp_sdf_errorcxx . . $ glp_sdf_error(36733fdcc0114f3d).(data, "invalid number of vertices\n");
539 na = glp_sdf_read_intcxx . . $ glp_sdf_read_int(d55aa0a7098b3be0).(data);
540 if (na < 0)
541 glp_sdf_errorcxx . . $ glp_sdf_error(36733fdcc0114f3d).(data, "invalid number of arcs\n");
542 xprintfcxx . . $ `external/glpk/glpenv.h:145:9`!("Graph has %d vert%s and %d arc%s\n",
543 nv, nv == 1 ? "ex" : "ices", na, na == 1 ? "" : "s");
544 if (nv > 0) glp_add_verticescxx . . $ glp_add_vertices(9d5fec13eee488ca).(G, nv);
545 for (k = 1; k <= na; k++)
546 { i = glp_sdf_read_intcxx . . $ glp_sdf_read_int(d55aa0a7098b3be0).(data);
547 if (!(1 <= i && i <= nv))
548 glp_sdf_errorcxx . . $ glp_sdf_error(36733fdcc0114f3d).(data, "tail vertex number out of range\n");
549 j = glp_sdf_read_intcxx . . $ glp_sdf_read_int(d55aa0a7098b3be0).(data);
550 if (!(1 <= j && j <= nv))
551 glp_sdf_errorcxx . . $ glp_sdf_error(36733fdcc0114f3d).(data, "head vertex number out of range\n");
552 glp_add_arccxx . . $ glp_add_arc(e54dd140876db879).(G, i, j);
553 }
554 xprintfcxx . . $ `external/glpk/glpenv.h:145:9`!("%d lines were read\n", glp_sdf_linecxx . . $ glp_sdf_line(d55aa0a7098b3be0).(data));
555 ret = 0;
556 done: if (data != NULLcxx . . $ `/usr/lib/gcc/x86_64-linux-gnu/15/include/stddef.h:419:9`!) glp_sdf_close_filecxx . . $ glp_sdf_close_file(eb8f982ad4273b27).(data);
557 return ret;
558 }
559
560 /***********************************************************************
561 * NAME
562 *
563 * glp_write_graph - write graph to plain text file
564 *
565 * SYNOPSIS
566 *
567 * int glp_write_graph(glp_graph *G, const char *fname).
568 *
569 * DESCRIPTION
570 *
571 * The routine glp_write_graph writes the specified graph to a plain
572 * text file.
573 *
574 * RETURNS
575 *
576 * If the operation was successful, the routine returns zero. Otherwise
577 * it prints an error message and returns non-zero. */
578
579 int glp_write_graphcxx . . $ glp_write_graph(df29dc7bf65d5d53).(glp_graphcxx . . $ glp_graph# *G, const char *fname)
580 { XFILEcxx . . $ XFILE# *fp;
581 glp_vertexcxx . . $ glp_vertex# *v;
582 glp_arccxx . . $ glp_arc# *a;
583 int i, count, ret;
584 xprintfcxx . . $ `external/glpk/glpenv.h:145:9`!("Writing graph to `%s'...\n", fname);
585 fp = xfopencxx . . $ `external/glpk/glpenv.h:193:9`!(fname, "w"), count = 0;
586 if (fp == NULLcxx . . $ `/usr/lib/gcc/x86_64-linux-gnu/15/include/stddef.h:419:9`!)
587 { xprintfcxx . . $ `external/glpk/glpenv.h:145:9`!("Unable to create `%s' - %s\n", fname, xerrmsgcxx . . $ `external/glpk/glpenv.h:190:9`!());
588 ret = 1;
589 goto done;
590 }
591 xfprintfcxx . . $ `external/glpk/glpenv.h:214:9`!(fp, "%d %d\n", G->nvcxx . . $ _glp_graph#nv., G->nacxx . . $ _glp_graph#na.), count++;
592 for (i = 1; i <= G->nvcxx . . $ _glp_graph#nv.; i++)
593 { v = G->vcxx . . $ _glp_graph#v.[i];
594 for (a = v->outcxx . . $ _glp_vertex#out.; a != NULLcxx . . $ `/usr/lib/gcc/x86_64-linux-gnu/15/include/stddef.h:419:9`!; a = a->t_nextcxx . . $ _glp_arc#t_next.)
595 xfprintfcxx . . $ `external/glpk/glpenv.h:214:9`!(fp, "%d %d\n", a->tailcxx . . $ _glp_arc#tail.->icxx . . $ _glp_vertex#i., a->headcxx . . $ _glp_arc#head.->icxx . . $ _glp_vertex#i.), count++;
596 }
597 xfflushcxx . . $ `external/glpk/glpenv.h:208:9`!(fp);
598 if (xferrorcxx . . $ `external/glpk/glpenv.h:196:9`!(fp))
599 { xprintfcxx . . $ `external/glpk/glpenv.h:145:9`!("Write error on `%s' - %s\n", fname, xerrmsgcxx . . $ `external/glpk/glpenv.h:190:9`!());
600 ret = 1;
601 goto done;
602 }
603 xprintfcxx . . $ `external/glpk/glpenv.h:145:9`!("%d lines were written\n", count);
604 ret = 0;
605 done: if (fp != NULLcxx . . $ `/usr/lib/gcc/x86_64-linux-gnu/15/include/stddef.h:419:9`!) xfclosecxx . . $ `external/glpk/glpenv.h:211:9`!(fp);
606 return ret;
607 }
608
609 /* eof */