SCIP Doxygen Documentation
Loading...
Searching...
No Matches
heur_fuzzyround.c
Go to the documentation of this file.
1/* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
2/* */
3/* This file is part of the program and library */
4/* SCIP --- Solving Constraint Integer Programs */
5/* */
6/* Copyright (c) 2002-2026 Zuse Institute Berlin (ZIB) */
7/* */
8/* Licensed under the Apache License, Version 2.0 (the "License"); */
9/* you may not use this file except in compliance with the License. */
10/* You may obtain a copy of the License at */
11/* */
12/* http://www.apache.org/licenses/LICENSE-2.0 */
13/* */
14/* Unless required by applicable law or agreed to in writing, software */
15/* distributed under the License is distributed on an "AS IS" BASIS, */
16/* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. */
17/* See the License for the specific language governing permissions and */
18/* limitations under the License. */
19/* */
20/* You should have received a copy of the Apache-2.0 license */
21/* along with SCIP; see the file LICENSE. If not visit scipopt.org. */
22/* */
23/* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
24
25/**@file heur_fuzzyround.c
26 * @brief primal heuristic that constructs a feasible solution from the lp-relaxation. Round only on the state-variables (binvars)
27 * and then reconstruct the rest of the variables accordingly.
28 * @author Leon Eifler
29 */
30/*---+----1----+----2----+----3----+----4----+----5----+----6----+----7----+----8----+----9----+----0----+----1----+----2*/
31
32#include "heur_fuzzyround.h"
33
34#include "probdata_cyc.h"
35#include "scip/cons_and.h"
36
37#define HEUR_NAME "fuzzyround"
38#define HEUR_DESC "primal heuristic that constructs a feasible solution from the lp-relaxation"
39#define HEUR_DISPCHAR '&'
40#define HEUR_PRIORITY 1000
41#define HEUR_FREQ 1
42#define HEUR_FREQOFS 0
43#define HEUR_MAXDEPTH -1
44#define HEUR_TIMING SCIP_HEURTIMING_AFTERNODE
45#define HEUR_USESSUBSCIP FALSE /**< does the heuristic use a secondary SCIP instance? */
46
47/*
48 * Local methods
49 */
50
51/** execution method of primal heuristic */
52static
53SCIP_DECL_HEUREXEC(heurExecFuzzyround)
54{ /*lint --e{715}*/
55 SCIP_VAR*** binvars;
57 SCIP_Real** clustering;
58 SCIP_Real maxlpval;
59 SCIP_Bool feasible = FALSE;
60 int* binsincluster;
61 int nbins;
62 int ncluster;
63 int i;
64 int k;
65 int maxcluster;
66
67 assert(heur != NULL);
68 assert(scip != NULL);
69 assert(result != NULL);
70
72
74
75 /* only call heuristic, if an optimal LP solution is at hand */
77 return SCIP_OKAY;
78
79 /* only call separator, if there are fractional variables */
80 if( SCIPgetNLPBranchCands(scip) == 0 )
81 return SCIP_OKAY;
82
83 nbins = SCIPcycGetNBins(scip);
84 ncluster = SCIPcycGetNCluster(scip);
85 assert(nbins > 0);
86 assert(ncluster > 0 && ncluster <= nbins);
87
88 binvars = SCIPcycGetBinvars(scip);
89 assert(binvars != NULL);
90
91 /* allocate memory */
92 SCIP_CALL( SCIPallocClearBufferArray(scip, &clustering , nbins) );
93 SCIP_CALL( SCIPallocClearBufferArray(scip, &binsincluster, ncluster) );
94
95 for( i = 0; i < nbins; ++i )
96 {
97 SCIP_CALL( SCIPallocClearBufferArray(scip, &clustering[i], ncluster) ); /*lint !e866*/
98 }
99
100 /* for each bin, set the assignment with the highest lp-value to 1, the rest to 0 */
101 for( i = 0; i < nbins; ++i )
102 {
103 assert(NULL != binvars[i]);
104
105 maxlpval = 0;
106 maxcluster = -1;
107
108 for (k = 0; k < ncluster; ++k)
109 {
110 assert(NULL != binvars[i][k]);
111 if( SCIPisGT(scip, SCIPvarGetLPSol(binvars[i][k]), maxlpval) )
112 {
113 maxlpval = SCIPvarGetLPSol(binvars[i][k]);
114 maxcluster = k;
115 binsincluster[k]++;
116 }
117 else if( SCIPisEQ(scip, SCIPvarGetLPSol(binvars[i][k]), maxlpval) && maxcluster != -1
118 && binsincluster[maxcluster] > binsincluster[k] )
119 {
120 binsincluster[maxcluster]--;
121 binsincluster[k]++;
122 maxcluster = k;
123 }
124 }
125
126 assert(maxcluster >= 0);
127
128 clustering[i][maxcluster] = 1.0;
129 }
130
131 assert(isPartition(scip, clustering, nbins, ncluster));
132
133 SCIP_CALL( SCIPcreateSol(scip, &sol, heur) );
134 SCIP_CALL( assignVars(scip, sol, clustering, nbins, ncluster) );
135 SCIP_CALL( SCIPtrySolFree(scip, &sol, FALSE, TRUE, TRUE, TRUE, TRUE, &feasible) );
136
137 if( feasible )
139 else
141
142 /* free allocated memory */
143 for( i = 0; i < nbins; ++i )
144 {
145 SCIPfreeBufferArray(scip, &clustering[i]);
146 }
147 SCIPfreeBufferArray(scip, &clustering);
148 SCIPfreeBufferArray(scip, &binsincluster);
149
150 return SCIP_OKAY;
151}
152
153/*
154 * primal heuristic specific interface methods
155 */
156
157/** creates the oneopt primal heuristic and includes it in SCIP */
159 SCIP* scip /**< SCIP data structure */
160 )
161{
162 SCIP_HEUR* heur;
163
164 /* include primal heuristic */
167 HEUR_MAXDEPTH, HEUR_TIMING, HEUR_USESSUBSCIP, heurExecFuzzyround, NULL) );
168
169 assert(heur != NULL);
170
171 return SCIP_OKAY;
172}
Constraint handler for AND constraints, .
#define NULL
Definition def.h:257
#define SCIP_Bool
Definition def.h:100
#define SCIP_STRINGEQ(name, reference, retcode)
Definition def.h:454
#define SCIP_Real
Definition def.h:165
#define TRUE
Definition def.h:102
#define FALSE
Definition def.h:103
#define SCIP_CALL(x)
Definition def.h:364
int SCIPgetNLPBranchCands(SCIP *scip)
SCIP_RETCODE SCIPincludeHeurBasic(SCIP *scip, SCIP_HEUR **heur, const char *name, const char *desc, char dispchar, int priority, int freq, int freqofs, int maxdepth, SCIP_HEURTIMING timingmask, SCIP_Bool usessubscip, SCIP_DECL_HEUREXEC((*heurexec)), SCIP_HEURDATA *heurdata)
Definition scip_heur.c:122
const char * SCIPheurGetName(SCIP_HEUR *heur)
Definition heur.c:1467
SCIP_LPSOLSTAT SCIPgetLPSolstat(SCIP *scip)
Definition scip_lp.c:174
#define SCIPallocClearBufferArray(scip, ptr, num)
Definition scip_mem.h:126
#define SCIPfreeBufferArray(scip, ptr)
Definition scip_mem.h:136
SCIP_RETCODE SCIPtrySolFree(SCIP *scip, SCIP_SOL **sol, SCIP_Bool printreason, SCIP_Bool completely, SCIP_Bool checkbounds, SCIP_Bool checkintegrality, SCIP_Bool checklprows, SCIP_Bool *stored)
Definition scip_sol.c:4114
SCIP_Bool SCIPisGT(SCIP *scip, SCIP_Real val1, SCIP_Real val2)
SCIP_Bool SCIPisEQ(SCIP *scip, SCIP_Real val1, SCIP_Real val2)
SCIP_Real SCIPvarGetLPSol(SCIP_VAR *var)
Definition var.c:24696
#define HEUR_TIMING
return SCIP_OKAY
#define HEUR_FREQOFS
#define HEUR_DESC
#define HEUR_DISPCHAR
#define HEUR_MAXDEPTH
#define HEUR_PRIORITY
#define HEUR_NAME
#define HEUR_FREQ
#define HEUR_USESSUBSCIP
SCIPcreateSol(scip, &heurdata->sol, heur))
SCIP_RETCODE SCIPincludeHeurFuzzyround(SCIP *scip)
primal heuristic that constructs a feasible solution from the lp-relaxation. Round only on the state-...
static SCIP_SOL * sol
assert(minobj< SCIPgetCutoffbound(scip))
SCIP_RETCODE assignVars(SCIP *scip, SCIP_SOL *sol, SCIP_Real **clustering, int nbins, int ncluster)
int SCIPcycGetNBins(SCIP *scip)
int SCIPcycGetNCluster(SCIP *scip)
SCIP_VAR *** SCIPcycGetBinvars(SCIP *scip)
SCIP_Bool isPartition(SCIP *scip, SCIP_Real **solclustering, int nbins, int ncluster)
problem data for cycle clustering problem
struct SCIP_Heur SCIP_HEUR
Definition type_heur.h:76
#define SCIP_DECL_HEUREXEC(x)
Definition type_heur.h:163
@ SCIP_LPSOLSTAT_OPTIMAL
Definition type_lp.h:44
@ SCIP_DIDNOTRUN
Definition type_result.h:42
@ SCIP_DIDNOTFIND
Definition type_result.h:44
@ SCIP_FOUNDSOL
Definition type_result.h:56
@ SCIP_INVALIDCALL
enum SCIP_Retcode SCIP_RETCODE
struct Scip SCIP
Definition type_scip.h:39
struct SCIP_Sol SCIP_SOL
Definition type_sol.h:57
struct SCIP_Var SCIP_VAR
Definition type_var.h:166