Scippy

GCG

Branch-and-Price & Column Generation for Everyone

automorphism_bliss.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 "bliss/graph.hh"
31#include "scip/scip.h"
32
34{
36 bliss::Graph* graph;
37 bliss::Stats bstats;
39};
40
41SCIP_RETCODE struct_graph::init(
42 SCIP* scip,
43 int nvertices
44 )
45{
46 graphdata = new struct_graph_data();
47 graphdata->graph = new bliss::Graph(nvertices);
48 assert(graphdata->graph->get_nof_vertices() == (unsigned int)nvertices);
49 //graph = new bliss::Graph();
50 graphdata->scip_ = scip;
51 graphdata->terminate = false;
52 return SCIP_OKAY;
53}
54
55SCIP_RETCODE struct_graph::destroy(
56 )
57{
58 delete graphdata->graph;
59 delete graphdata;
60 return SCIP_OKAY;
61}
62
63void struct_graph::setColor(
64 int vertex,
65 int color
66 )
67{
68 assert(vertex < graphdata->graph->get_nof_vertices());
69 graphdata->graph->change_color((unsigned int)vertex, (unsigned int)color);
70 //graph->add_vertex((unsigned int)color);
71}
72
73void struct_graph::addEdge(
74 int v1,
75 int v2
76 )
77{
78 graphdata->graph->add_edge((unsigned int)v1, (unsigned int)v2);
79}
80
81unsigned int struct_graph::getNVertices(
82 )
83{
84 return graphdata->graph->get_nof_vertices();
85}
86
87SCIP_RETCODE struct_graph::findAutomorphisms(
88 void* userdata,
89 void (*fhook)(void*, unsigned int, const unsigned int*),
90 unsigned int searchnodelimit,
91 unsigned int generatorlimit
92 )
93{
94#ifdef BLISS_PATCH_PRESENT
95 if( searchnodelimit > 0u || generatorlimit > 0u)
96 graphdata->graph->set_search_limits(searchnodelimit, generatorlimit);
97#endif
98
99#if BLISS_VERSION_MAJOR >= 1 || BLISS_VERSION_MINOR >= 76
100 auto report = [&](unsigned int n, const unsigned int* aut) {
101 (*fhook)((void*)userdata, n, aut);
102 };
103
104 auto term = [&]() {
105 return graphdata->terminate
106 || (generatorlimit > 0 && graphdata->bstats.get_nof_generators() >= (long unsigned int) generatorlimit)
107 || (searchnodelimit > 0 && graphdata->bstats.get_nof_nodes() >= (long unsigned int) searchnodelimit);
108 };
109
110 graphdata->graph->find_automorphisms(graphdata->bstats, report, term);
111#else
112 graphdata->graph->find_automorphisms(graphdata->bstats, fhook, userdata);
113#endif
114 return SCIP_OKAY;
115}
116
117void struct_graph::terminateSearch()
118{
119 graphdata->terminate = true;
120}
121
122extern "C"
123void GCGgetBlissName(char* buffer, int len)
124{
125#ifdef BLISS_PATCH_PRESENT
126 SCIPsnprintf(buffer, len, "bliss %sp", bliss::version);
127#else
128 SCIPsnprintf(buffer, len, "bliss %s", bliss::version);
129#endif
130}
static void fhook(void *user_param, unsigned int N, const unsigned int *aut)
void GCGgetBlissName(char *buffer, int len)
int SCIPsnprintf(char *t, int len, const char *s,...)
helper functions for automorphism detection
SCIP_OKAY
enum SCIP_Retcode SCIP_RETCODE