| 1 | /* glpapi18.c (maximum clique problem) */cxx . . $ `<file>/external/glpk/glpapi18.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 | #include "glpnet.h"cxx . . $ `<file>/external/glpk/glpnet.h`/ |
| 27 | |
| 28 | static void set_edgecxx . . $ set_edge(34ee600be5240935).(int nv, unsigned char a[], int i, int j) |
| 29 | { int k; |
| 30 | xassertcxx . . $ `external/glpk/glpenv.h:162:9`!(1 <= j && j < i && i <= nv); |
| 31 | k = ((i - 1) * (i - 2)) / 2 + (j - 1); |
| 32 | a[k / CHAR_BITcxx . . $ `<external>/67164224788392828/limits.h:64:9`!] |= |
| 33 | (unsigned char)(1 << ((CHAR_BITcxx . . $ `<external>/67164224788392828/limits.h:64:9`! - 1) - k % CHAR_BITcxx . . $ `<external>/67164224788392828/limits.h:64:9`!)); |
| 34 | return; |
| 35 | } |
| 36 | |
| 37 | int glp_wclique_exactcxx . . $ glp_wclique_exact(9be8a0802dabcdd1).(glp_graphcxx . . $ glp_graph# *G, int v_wgt, double *sol, int v_set) |
| 38 | { /* find maximum weight clique with exact algorithm */ |
| 39 | glp_arccxx . . $ glp_arc# *e; |
| 40 | int i, j, k, len, x, *w, *ind, ret = 0; |
| 41 | unsigned char *a; |
| 42 | double s, t; |
| 43 | if (v_wgt >= 0 && v_wgt > G->v_sizecxx . . $ _glp_graph#v_size. - (int)sizeof(double)) |
| 44 | xerrorcxx . . $ `external/glpk/glpenv.h:158:9`!("glp_wclique_exact: v_wgt = %d; invalid parameter\n", |
| 45 | v_wgt); |
| 46 | if (v_set >= 0 && v_set > G->v_sizecxx . . $ _glp_graph#v_size. - (int)sizeof(int)) |
| 47 | xerrorcxx . . $ `external/glpk/glpenv.h:158:9`!("glp_wclique_exact: v_set = %d; invalid parameter\n", |
| 48 | v_set); |
| 49 | if (G->nvcxx . . $ _glp_graph#nv. == 0) |
| 50 | { /* empty graph has only empty clique */ |
| 51 | if (sol != NULLcxx . . $ `/usr/lib/gcc/x86_64-linux-gnu/15/include/stddef.h:419:9`!) *sol = 0.0; |
| 52 | return 0; |
| 53 | } |
| 54 | /* allocate working arrays */ |
| 55 | w = xcalloccxx . . $ `external/glpk/glpenv.h:171:9`!(1+G->nvcxx . . $ _glp_graph#nv., sizeof(int)); |
| 56 | ind = xcalloccxx . . $ `external/glpk/glpenv.h:171:9`!(1+G->nvcxx . . $ _glp_graph#nv., sizeof(int)); |
| 57 | len = G->nvcxx . . $ _glp_graph#nv.; /* # vertices */ |
| 58 | len = len * (len - 1) / 2; /* # entries in lower triangle */ |
| 59 | len = (len + (CHAR_BITcxx . . $ `<external>/67164224788392828/limits.h:64:9`! - 1)) / CHAR_BITcxx . . $ `<external>/67164224788392828/limits.h:64:9`!; /* # bytes needed */ |
| 60 | a = xcalloccxx . . $ `external/glpk/glpenv.h:171:9`!(len, sizeof(char)); |
| 61 | memsetcxx . . $ memset(d1de1e4fb215f1c6).(a, 0, len * sizeof(char)); |
| 62 | /* determine vertex weights */ |
| 63 | s = 0.0; |
| 64 | for (i = 1; i <= G->nvcxx . . $ _glp_graph#nv.; i++) |
| 65 | { if (v_wgt >= 0) |
| 66 | { memcpycxx . . $ memcpy(cc817cb175f282d).(&t, (char *)G->vcxx . . $ _glp_graph#v.[i]->datacxx . . $ _glp_vertex#data. + v_wgt, sizeof(double)); |
| 67 | if (!(0.0 <= t && t <= (double)INT_MAXcxx . . $ `<external>/67164224788392828/limits.h:120:9`! && t == floor(t))) |
| 68 | { ret = GLP_EDATAcxx . . $ `external/glpk/glpk.h:256:9`!; |
| 69 | goto done; |
| 70 | } |
| 71 | w[i] = (int)t; |
| 72 | } |
| 73 | else |
| 74 | w[i] = 1; |
| 75 | s += (double)w[i]; |
| 76 | } |
| 77 | if (s > (double)INT_MAXcxx . . $ `<external>/67164224788392828/limits.h:120:9`!) |
| 78 | { ret = GLP_EDATAcxx . . $ `external/glpk/glpk.h:256:9`!; |
| 79 | goto done; |
| 80 | } |
| 81 | /* build the adjacency matrix */ |
| 82 | for (i = 1; i <= G->nvcxx . . $ _glp_graph#nv.; i++) |
| 83 | { for (e = G->vcxx . . $ _glp_graph#v.[i]->incxx . . $ _glp_vertex#in.; e != NULLcxx . . $ `/usr/lib/gcc/x86_64-linux-gnu/15/include/stddef.h:419:9`!; e = e->h_nextcxx . . $ _glp_arc#h_next.) |
| 84 | { j = e->tailcxx . . $ _glp_arc#tail.->icxx . . $ _glp_vertex#i.; |
| 85 | /* there exists edge (j,i) in the graph */ |
| 86 | if (i > j) set_edgecxx . . $ set_edge(34ee600be5240935).(G->nvcxx . . $ _glp_graph#nv., a, i, j); |
| 87 | } |
| 88 | for (e = G->vcxx . . $ _glp_graph#v.[i]->outcxx . . $ _glp_vertex#out.; e != NULLcxx . . $ `/usr/lib/gcc/x86_64-linux-gnu/15/include/stddef.h:419:9`!; e = e->t_nextcxx . . $ _glp_arc#t_next.) |
| 89 | { j = e->headcxx . . $ _glp_arc#head.->icxx . . $ _glp_vertex#i.; |
| 90 | /* there exists edge (i,j) in the graph */ |
| 91 | if (i > j) set_edgecxx . . $ set_edge(34ee600be5240935).(G->nvcxx . . $ _glp_graph#nv., a, i, j); |
| 92 | } |
| 93 | } |
| 94 | /* find maximum weight clique in the graph */ |
| 95 | len = wcliquecxx . . $ `external/glpk/glpnet.h:49:9`!(G->nvcxx . . $ _glp_graph#nv., w, a, ind); |
| 96 | /* compute the clique weight */ |
| 97 | s = 0.0; |
| 98 | for (k = 1; k <= len; k++) |
| 99 | { i = ind[k]; |
| 100 | xassertcxx . . $ `external/glpk/glpenv.h:162:9`!(1 <= i && i <= G->nv); |
| 101 | s += (double)w[i]; |
| 102 | } |
| 103 | if (sol != NULLcxx . . $ `/usr/lib/gcc/x86_64-linux-gnu/15/include/stddef.h:419:9`!) *sol = s; |
| 104 | /* mark vertices included in the clique */ |
| 105 | if (v_set >= 0) |
| 106 | { x = 0; |
| 107 | for (i = 1; i <= G->nvcxx . . $ _glp_graph#nv.; i++) |
| 108 | memcpycxx . . $ memcpy(cc817cb175f282d).((char *)G->vcxx . . $ _glp_graph#v.[i]->datacxx . . $ _glp_vertex#data. + v_set, &x, sizeof(int)); |
| 109 | x = 1; |
| 110 | for (k = 1; k <= len; k++) |
| 111 | { i = ind[k]; |
| 112 | memcpycxx . . $ memcpy(cc817cb175f282d).((char *)G->vcxx . . $ _glp_graph#v.[i]->datacxx . . $ _glp_vertex#data. + v_set, &x, sizeof(int)); |
| 113 | } |
| 114 | } |
| 115 | done: /* free working arrays */ |
| 116 | xfreecxx . . $ `external/glpk/glpenv.h:175:9`!(w); |
| 117 | xfreecxx . . $ `external/glpk/glpenv.h:175:9`!(ind); |
| 118 | xfreecxx . . $ `external/glpk/glpenv.h:175:9`!(a); |
| 119 | return ret; |
| 120 | } |
| 121 | |
| 122 | /* eof */ |