GCG 4.1.1 (dev)

Generic Column Generation

Loading...
Searching...
No Matches
automorphism_nauty.cpp
Go to the documentation of this file.
1/* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
2/* */
3/* This file is part of the program and library */
4/* GCG --- Generic Column Generation */
5/* a Dantzig-Wolfe decomposition based extension */
6/* of the branch-cut-and-price framework */
7/* SCIP --- Solving Constraint Integer Programs */
8/* */
9/* Copyright (C) 2010-2026 Operations Research, RWTH Aachen University */
10/* Zuse Institute Berlin (ZIB) */
11/* */
12/* Licensed under the Apache License, Version 2.0 (the "License"); */
13/* you may not use this file except in compliance with the License. */
14/* You may obtain a copy of the License at */
15/* */
16/* http://www.apache.org/licenses/LICENSE-2.0 */
17/* */
18/* Unless required by applicable law or agreed to in writing, software */
19/* distributed under the License is distributed on an "AS IS" BASIS, */
20/* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. */
21/* See the License for the specific language governing permissions and */
22/* limitations under the License. */
23/* */
24/* You should have received a copy of the Apache-2.0 license */
25/* along with GCG; see the file LICENSE. If not visit gcg.or.rwth-aachen.de.*/
26/* */
27/* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
28
30#include "nauty/nausparse.h"
31#include "scip/scip.h"
32#include <vector>
33
35{
37 void (*staticfhook)(void*, unsigned int, const unsigned int*);
38 statsblk* stats;
39 unsigned int searchnodelimit;
40 unsigned int generatorlimit;
42};
43
44static TLS_ATTR NautyData nautydata;
45static TLS_ATTR DEFAULTOPTIONS_SPARSEGRAPH(options);
46
48{
49 SCIP* scip_;
50 statsblk stats;
51 sparsegraph graph;
52 int* ptn;
53 int* orbits;
54 std::vector<std::vector<int>> edges;
55 size_t nedges;
56};
57
58static
60 int count, /**< ordinal of this generator (starts with 1) */
61 int* perm, /**< the generator */
62 int* orbits, /**< orbits generated by the group found so far */
63 int numorbits, /**< number of orbits */
64 int stabvertex, /**< stabilizing vertex */
65 int n /**< number of vertices */
66 )
67{
69 || (nautydata.generatorlimit > 0 && (unsigned int)count >= nautydata.generatorlimit)
71 return;
72 else
73 (*nautydata.staticfhook)(nautydata.staticuserdata, n, (unsigned int*)perm);
74}
75
76SCIP_RETCODE struct_graph::init(
77 SCIP* scip,
78 int nvertices
79 )
80{
81 graphdata = new struct_graph_data();
82 graphdata->scip_ = scip;
83 options.userautomproc = &nautyhook;
84 options.defaultptn = FALSE;
85 SG_INIT(graphdata->graph);
86 DYNALLOC1(size_t, graphdata->graph.v, graphdata->graph.vlen, nvertices, "malloc");
87 DYNALLOC1(int, graphdata->graph.d, graphdata->graph.dlen, nvertices, "malloc");
88 graphdata->graph.e = NULL;
89 graphdata->graph.w = NULL;
90 graphdata->graph.nv = nvertices;
91 SCIP_CALL( SCIPallocBlockMemoryArray(scip, &graphdata->ptn, nvertices) );
92 graphdata->edges.resize(nvertices);
93 graphdata->nedges = 0;
94 return SCIP_OKAY;
95}
96
97SCIP_RETCODE struct_graph::destroy(
98 )
99{
100 SCIPfreeBlockMemoryArray(graphdata->scip_, &graphdata->ptn, graphdata->graph.nv);
101 SG_FREE(graphdata->graph);
102 delete graphdata;
103 return SCIP_OKAY;
104}
105
106void struct_graph::setColor(
107 int vertex,
108 int color
109 )
110{
111 assert(vertex < graphdata->graph.nv);
112 graphdata->ptn[vertex] = color;
113}
114
115void struct_graph::addEdge(
116 int v1,
117 int v2
118 )
119{
120 assert(v1 < (int) graphdata->edges.size() && v2 < (int) graphdata->edges.size());
121 graphdata->edges[v1].push_back(v2);
122 graphdata->edges[v2].push_back(v1);
123 graphdata->nedges+=2;
124}
125
126unsigned int struct_graph::getNVertices(
127 )
128{
129 return graphdata->graph.nv;
130}
131
132SCIP_RETCODE struct_graph::findAutomorphisms(
133 void* userdata,
134 void (*fhook)(void*, unsigned int, const unsigned int*),
135 unsigned int searchnodelimit,
136 unsigned int generatorlimit
137 )
138{
139 int i;
140 int* lab = NULL;
141 int* orbits = NULL;
142 size_t edgeindex = 0;
143
144 // edges
145 DYNALLOC1(int, graphdata->graph.e, graphdata->graph.elen, graphdata->nedges, "malloc");
146 graphdata->graph.nde = graphdata->nedges;
147 assert((int) graphdata->edges.size() == graphdata->graph.nv);
148 for( i = 0; i < graphdata->graph.nv; ++i)
149 {
150 graphdata->graph.d[i] = (int)graphdata->edges[i].size();
151 graphdata->graph.v[i] = edgeindex;
152 for( auto v : graphdata->edges[i] )
153 {
154 assert(edgeindex < graphdata->graph.nde);
155 graphdata->graph.e[edgeindex++] = v;
156 }
157 }
158
159 // set coloring
160 SCIP_CALL( SCIPallocBufferArray(graphdata->scip_, &lab, graphdata->graph.nv) );
161 for( i = 0; i < graphdata->graph.nv; ++i )
162 lab[i] = i;
163 SCIPsortIntInt(graphdata->ptn, lab, graphdata->graph.nv);
164 for( i = 0; i < graphdata->graph.nv; ++i )
165 {
166 if( i + 1 == graphdata->graph.nv || graphdata->ptn[i] != graphdata->ptn[i+1] )
167 graphdata->ptn[i] = 0;
168 else
169 graphdata->ptn[i] = 1;
170 }
171
172 SCIP_CALL( SCIPallocBufferArray(graphdata->scip_, &orbits, graphdata->graph.nv) );
173
175 nautydata.staticuserdata = userdata;
176 nautydata.stats = &graphdata->stats;
177 nautydata.terminate = false;
178 sparsenauty(&graphdata->graph, lab, graphdata->ptn, orbits, &options, &graphdata->stats, NULL);
179
180 SCIPfreeBufferArray(graphdata->scip_, &orbits);
181 SCIPfreeBufferArray(graphdata->scip_, &lab);
182
183 return SCIP_OKAY;
184}
185
186void struct_graph::terminateSearch()
187{
188 nautydata.terminate = true;
189}
190
191extern "C"
192void GCGgetNautyName(char* buffer, int len)
193{
194 SCIPsnprintf(buffer, len, "Nauty %d.%d.%d", NAUTYVERSIONID/10000, (NAUTYVERSIONID%10000)/1000, (NAUTYVERSIONID%1000)/10);
195}
static void fhook(void *user_param, unsigned int N, const unsigned int *aut)
static TLS_ATTR DEFAULTOPTIONS_SPARSEGRAPH(options)
static TLS_ATTR NautyData nautydata
void GCGgetNautyName(char *buffer, int len)
static void nautyhook(int count, int *perm, int *orbits, int numorbits, int stabvertex, int n)
#define FALSE
#define SCIPfreeBlockMemoryArray(scip, ptr, num)
#define SCIPallocBufferArray(scip, ptr, num)
#define SCIPallocBlockMemoryArray(scip, ptr, num)
void SCIPsortIntInt(int *intarray1, int *intarray2, int len)
int SCIPsnprintf(char *t, int len, const char *s,...)
static assert(heur !=NULL)
SCIP_CALL(SCIPgetExternBranchCands(origprob, &lpcands, &lpcandssol, NULL, &nlpcands, NULL, NULL, NULL, NULL))
int i
SCIPfreeBufferArray(scip, &cycles)
#define NULL
helper functions for automorphism detection
void(*) staticfhook(void *, unsigned int, const unsigned int *)
unsigned int generatorlimit
unsigned int searchnodelimit
std::vector< std::vector< int > > edges
enum SCIP_Retcode SCIP_RETCODE
struct Scip SCIP