<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
<meta name="Generator" content="Microsoft Exchange Server">
<!-- converted from text --><style><!-- .EmailQuote { margin-left: 1pt; padding-left: 4pt; border-left: #800000 2px solid; } --></style>
</head>
<body>
<meta content="text/html; charset=UTF-8">
<style type="text/css" style="">
<!--
p
        {margin-top:0;
        margin-bottom:0}
-->
</style>
<div dir="ltr">
<div id="x_divtagdefaultwrapper" dir="ltr" style="font-size:12pt; color:#000000; font-family:Calibri,Helvetica,sans-serif">
<p>Hi Marko,</p>
<p><br>
</p>
<p>Marc says off-topic, but I won't erase my answer now <span>😊</span></p>
<p><br>
</p>
<p>I admit I haven't looked at your minimal working example. In the C world, your easiest option is to introduce distinct structs for each type in the headers<br>
</p>
<p><br>
</p>
<p>cons_one.h: struct one_data {...}</p>
<p>cons_two.h: struct two_data {...}</p>
<p>...<br>
</p>
<p><br>
</p>
<p>and to create a constraint data using <br>
</p>
<p><br>
</p>
<p><b>struct one_data *mydata;</b><b><br>
</b></p>
<p><b>mydata = malloc(sizeof(struct one_data));</b></p>
<p><b><br>
</b></p>
<p><b> // constraint creation</b></p>
<p><b><br>
</b></p>
<p><b>SCIPsetConsData(scip, cons_of_type_one, (SCIP_CONSDATA*)mydata);</b></p>
<p><b><br>
</b></p>
<p>Whenever the constraint wants to use its above data in the implementation in one.cpp, cast it back to its original type:<b></b></p>
<p><b><br>
</b></p>
<p><b></b><span><b>struct one_data *mydata = (struct one_data *)SCIPconsGetData(cons);</b></span></p>
<p><br>
</p>
<p>Note that for all constraint handlers of SCIP, their data implementation is entirely private to the c file, they *NEVER* expose their internal data structure of struct SCIP_ConsData to the world outside. This is why you pass a list of weights, list of binary
 variables, and a capacity to the Knapsack constraint handler at constraint creation time, but not an object of SCIP_KNAPSACKDATA type, which does not even exist. 
<br>
</p>
<p><br>
</p>
<p>Now it's time for C++ guys to tell you a different approach.</p>
<p><br>
</p>
<p>Cheers,</p>
<p>Gregor<br>
</p>
<p><br>
</p>
<p><br>
</p>
<p><br>
</p>
<p><br>
</p>
<p><br>
</p>
</div>
<hr tabindex="-1" style="display:inline-block; width:98%">
<div id="x_divRplyFwdMsg" dir="ltr"><font face="Calibri, sans-serif" color="#000000" style="font-size:11pt"><b>Von:</b> Scip <scip-bounces@zib.de> im Auftrag von Horváth Markó <marko.horvath@sztaki.hu><br>
<b>Gesendet:</b> Donnerstag, 22. Oktober 2020 10:37:55<br>
<b>An:</b> scip@zib.de<br>
<b>Betreff:</b> [SCIP] Multiple SCIP_ConsData cause heap corruption</font>
<div> </div>
</div>
</div>
<font size="2"><span style="font-size:10pt;">
<div class="PlainText">Dear All,<br>
<br>
I am working on a branch-and-price project using SCIP, but I got stuck <br>
on something. Actually, I reduced my problem to a "simple" C++ issue, <br>
but due to the design of SCIP maybe you have already run into this <br>
problem and know the solution.<br>
<br>
So, my problem is that I have three different user-defined constraints <br>
and thus three different user-defined constraint data, that is, three <br>
different structures in three different .cpp files with the same name: <br>
SCIP_ConsData. (Due to the design of SCIP, I must use this name for all <br>
structures). Everything was fine when I used only the first two <br>
constraints (it was also a luck, I guess), however, the third one ruined <br>
everything. The problem is that in runtime these structures are mixed up <br>
which causes a heap corruption.<br>
<br>
More precisely, I have three SCIP_ConsData structures in different .cpp <br>
files (say, one.cpp, two.cpp, three.cpp) and when I want to create a new <br>
instance of the corresponding SCIP_ConsData in file two.cpp, the <br>
structure in file one.cpp is going to be created. Later, it will cause a <br>
heap corruption.<br>
<br>
What should I do to fix this issue?<br>
<br>
I attach a very minimal working example for this phenomenon. I use <br>
Visual Studio 2019 under Windows 10 with C++17 Standard.<br>
<br>
Best Regards,<br>
Marko<br>
</div>
</span></font>
</body>
</html>