42 #include "scip/scip.h"
43 #include "scip/cons_linear.h"
45 #include "blockmemshell/memory.h"
66 SCIP_CALL( SCIPallocBlockMemory(pricingprob, gcgcol) );
68 (*gcgcol)->maxvars = SCIPcalcMemGrowSize(pricingprob, nvars);
69 SCIP_CALL( SCIPallocBlockMemoryArray(pricingprob, &((*gcgcol)->vars), (*gcgcol)->maxvars) );
70 SCIP_CALL( SCIPallocBlockMemoryArray(pricingprob, &((*gcgcol)->vals), (*gcgcol)->maxvars) );
72 (*gcgcol)->pricingprob = pricingprob;
73 (*gcgcol)->probnr = probnr;
74 (*gcgcol)->isray = isray;
75 (*gcgcol)->redcost = redcost;
77 (*gcgcol)->mastercoefs = NULL;
78 (*gcgcol)->mastercuts = NULL;
79 (*gcgcol)->linkvars = NULL;
80 (*gcgcol)->nmastercoefs = 0;
81 (*gcgcol)->nmastercuts = 0;
82 (*gcgcol)->maxmastercoefs = 0;
83 (*gcgcol)->maxmastercuts = 0;
84 (*gcgcol)->nlinkvars = 0;
85 (*gcgcol)->initcoefs = FALSE;
89 for( i = 0; i < nvars; ++i )
102 SCIP_CALL( SCIPvarGetOrigvarSum(&origvar, &scalar, &constant) );
104 assert( !SCIPisZero(pricingprob, scalar) );
106 origval = (vals[i] - constant) / scalar;
109 if( SCIPvarIsIntegral(origvar) && SCIPisFeasIntegral(pricingprob, origval) )
110 origval = SCIPround(pricingprob, origval);
112 if( !SCIPisZero(pricingprob, origval) )
114 (*gcgcol)->vars[nnonz] = origvar;
115 (*gcgcol)->vals[nnonz] = origval;
120 (*gcgcol)->nvars = nnonz;
123 SCIPsortPtrReal((
void**)(*gcgcol)->vars, (
double*)(*gcgcol)->vals, SCIPvarComp, nnonz);
126 for( i = 1 ; i < (*gcgcol)->nvars; ++i )
128 assert( SCIPvarCompare((*gcgcol)->vars[i-1], (*gcgcol)->vars[i]) != 0 );
139 assert(gcgcol != NULL);
140 assert(*gcgcol != NULL);
143 assert((*gcgcol)->nvars == 0 || (*gcgcol)->vars != NULL);
144 SCIPfreeBlockMemoryArrayNull((*gcgcol)->pricingprob, &(*gcgcol)->vars, (*gcgcol)->maxvars);
145 assert((*gcgcol)->nvars == 0 || (*gcgcol)->vals != NULL);
146 SCIPfreeBlockMemoryArrayNull((*gcgcol)->pricingprob, &(*gcgcol)->vals, (*gcgcol)->maxvars);
147 SCIPfreeBlockMemoryArrayNull((*gcgcol)->pricingprob, &(*gcgcol)->mastercoefs, (*gcgcol)->maxmastercoefs);
148 SCIPfreeBlockMemoryArrayNull((*gcgcol)->pricingprob, &(*gcgcol)->linkvars, (*gcgcol)->maxlinkvars);
149 SCIPfreeBlockMemoryArrayNull((*gcgcol)->pricingprob, &(*gcgcol)->mastercuts, (*gcgcol)->maxmastercuts);
150 SCIPfreeBlockMemory((*gcgcol)->pricingprob, gcgcol);
173 solvars = SCIPgetOrigVars(pricingprob);
174 nsolvars = SCIPgetNOrigVars(pricingprob);
176 SCIP_CALL( SCIPallocBufferArray(pricingprob, &colvars, nsolvars) );
177 SCIP_CALL( SCIPallocBufferArray(pricingprob, &colvals, nsolvars) );
181 for( i = 0; i < nsolvars; ++i )
187 solval = SCIPgetSolVal(pricingprob, sol, solvar);
190 if( SCIPvarIsIntegral(solvar) && SCIPisFeasIntegral(pricingprob, solval) )
191 solval = SCIPround(pricingprob, solval);
193 if( SCIPisZero(pricingprob, solval) )
198 colvars[ncolvars] = solvar;
199 colvals[ncolvars] = solval;
203 SCIP_CALL(
GCGcreateGcgCol(pricingprob, gcgcol, prob, colvars, colvals, ncolvars, isray, redcost) );
205 SCIPfreeBufferArray(pricingprob, &colvals);
206 SCIPfreeBufferArray(pricingprob, &colvars);
220 if( redcost1 < redcost2 )
222 else if( redcost1 > redcost2 )
239 else if( age1 > age2 )
270 if( probnr1 != probnr2 )
276 if( nvars1 != nvars2 )
286 for( i = 0; i < nvars1; ++i )
300 if( SCIPvarCompare(var1, var2) != 0 || !SCIPisEQ(pricingprob, val1, val2) )
347 return gcgcol->
nvars;
355 return gcgcol->
isray;
386 if( !SCIPisNegative(gcgcol->
pricingprob, redcost) )
411 SCIP_Real* mastercoefs,
417 SCIPdebugMessage(
"Col set master coefs\n");
419 if( nmastercoefs == 0 )
425 for( i = 0; i < nmastercoefs; ++i )
427 SCIP_Real coef = mastercoefs[i];
455 SCIP_Real* mastercoefs;
457 SCIP_Real* mastercuts;
462 assert(scip != NULL);
463 assert(gcgcol != NULL);
476 for( i = 0; i < nmastercoefs; ++i )
478 if( !SCIPisZero(scip, mastercoefs[i]))
479 norm += SQR(mastercoefs[i]);
482 for( i = 0; i < nmastercuts; ++i )
484 if( !SCIPisZero(scip, mastercuts[i]))
485 norm += SQR(mastercuts[i]);
489 for( i = 0; i < nlinkvars; ++i )
491 if( !SCIPisZero(scip, solvals[linkvars[i]]) )
492 norm += solvals[linkvars[i]];
549 for( i = 0; i < nlinkvars; ++i )
586 SCIP_Real* newmastercuts,
594 newsize = SCIPcalcMemGrowSize(gcgcol->
pricingprob, i);
603 for( i = 0; i < nnewmastercuts; ++i )
627 nvars = gcgcol->
nvars;
629 found = SCIPsortedvecFindPtr((
void**) vars, SCIPvarComp, (
void*) var, nvars, &pos);
647 return (agelimit >= 0 && col->
age > agelimit);
660 SCIP_CONS** masterconss;
665 SCIP_Real* mastercoefs;
667 SCIP_Real* mastercuts;
670 SCIP_Real dualobjnorm;
673 assert(scip != NULL);
674 assert(gcgcol != NULL);
689 for( i = 0; i < nmastercoefs; ++i )
694 lhs = SCIPgetLhsLinear(scip, masterconss[i]);
695 rhs = SCIPgetRhsLinear(scip, masterconss[i]);
697 if( !SCIPisInfinity(scip, -lhs))
699 dualobjnorm += SQR(lhs);
701 if( SCIPisPositive(scip, mastercoefs[i]) )
702 para += mastercoefs[i] * lhs;
704 else if( !SCIPisInfinity(scip, rhs) )
706 dualobjnorm += SQR(rhs);
708 if(SCIPisNegative(scip, mastercoefs[i] ) )
709 para += mastercoefs[i] * rhs;
713 for( i = 0; i < nmastercuts; ++i )
718 if( !SCIProwIsInLP(cuts[i]) )
721 lhs = SCIProwGetLhs(cuts[i]);
722 rhs = SCIProwGetRhs(cuts[i]);
724 if( !SCIPisInfinity(scip, -lhs))
726 dualobjnorm += SQR(lhs);
728 if( SCIPisPositive(scip, mastercuts[i]) )
729 para += mastercuts[i] * lhs;
731 else if( !SCIPisInfinity(scip, rhs) )
733 dualobjnorm += SQR(rhs);
735 if(SCIPisNegative(scip, mastercuts[i] ) )
736 para += mastercuts[i] * rhs;
745 assert(!SCIPisInfinity(scip, ABS(para)));
747 dualobjnorm = SQRT(dualobjnorm);
748 assert(!SCIPisInfinity(scip, dualobjnorm));
749 assert(SCIPisPositive(scip, dualobjnorm));
750 assert(SCIPisPositive(scip, gcgcol->
norm));
752 para = para / (dualobjnorm * gcgcol->
norm);
766 SCIP_Real para = 0.0;
767 SCIP_Real norm1 = 0.0;
768 SCIP_Real norm2 = 0.0;
774 SCIP_Real* mastercoefs1;
776 SCIP_Real* mastercuts1;
785 SCIP_Real* mastercoefs2;
786 SCIP_Real* mastercuts2;
790 assert(scip != NULL);
791 assert(gcgcol1 != NULL);
792 assert(gcgcol2 != NULL);
813 for( i = 0; i < nmastercoefs1; ++i )
815 if( SCIPisPositive(scip, mastercoefs1[i] * mastercoefs2[i]) )
816 para += mastercoefs1[i] * mastercoefs2[i];
818 if( SCIPisPositive(scip, mastercoefs1[i]) )
819 norm1 += SQR(mastercoefs1[i]);
820 if( SCIPisPositive(scip, mastercoefs2[i]) )
821 norm2 += SQR(mastercoefs2[i]);
824 for( i = 0; i < nmastercuts1; ++i )
826 if( SCIPisPositive(scip, mastercuts1[i] * mastercuts2[i]) )
827 para += mastercuts1[i] * mastercuts2[i];
829 if( SCIPisPositive(scip, mastercuts1[i]) )
830 norm1 += SQR(mastercuts1[i]);
831 if( SCIPisPositive(scip, mastercuts2[i]) )
832 norm2 += SQR(mastercuts2[i]);
835 for( i = 0; i < nlinkvars1; ++i )
839 linkvar1 = solvars1[linkvars1[i]];
840 linkval1 = solvals1[linkvars1[i]];
842 norm1 += SQR(linkval1);
844 for( j = 0; j < nlinkvars2; ++j )
848 linkvar2 = solvars2[linkvars2[j]];
849 linkval2 = solvals2[linkvars2[j]];
851 if( linkvar1 == linkvar2 )
853 para += linkval1 * linkval2;
859 for( i = 0; i < nlinkvars2; ++i )
863 linkval2 = solvals2[linkvars2[i]];
865 norm2 += SQR(linkval2);
879 assert(SCIPisPositive(scip, norm1) && SCIPisPositive(scip, norm2));
881 para = para/(norm1*norm2);