19 #include "OSInstance.h"
30 #include "OSInstance.h"
33 #include "CoinTime.hpp"
35 #include "ClpFactorization.hpp"
36 #include "ClpNetworkMatrix.hpp"
37 #include "OsiClpSolverInterface.hpp"
46 # error "don't have header file for math"
56 # error "don't have header file for time"
66 std::cout <<
"INSIDE OSBearcatSolverXkij CONSTRUCTOR with OSOption argument" << std::endl;
70 std::cout <<
"INSIDE OSBearcatSolverXkij CONSTRUCTOR with OSOption argument" << std::endl;
219 int numVar = m_numNodes*m_numNodes -
m_numHubs ;
221 for(i = 0; i < numVar; i++){
292 for(i = 0; i < m_numNodes*(m_numNodes - 1); i++){
315 std::cout <<
"INSIDE ~OSBearcatSolverXkij DESTRUCTOR" << std::endl;
565 testVal =
qrouteCost(k - 1, l, c[ k - 1], &kountVar);
570 if(
m_vv[ k-1][ d1] + testVal <
m_vv[ k][ d] ){
599 l = m_totalDemand - d;
610 testVal =
qrouteCost(m_numHubs -1 , l, c[ m_numHubs -1], &kountVar);
615 if(
m_vv[ m_numHubs - 1][ d] + testVal < trueMin){
617 trueMin =
m_vv[ m_numHubs -1][ d] + testVal;
618 m_optD[ m_numHubs -1 ] = d;
619 m_optL[ m_numHubs -1 ] = l;
629 if( isFeasible ==
false){
631 std::cout <<
"NOT ENOUGH CAPACITY " << std::endl;
641 m_optL[ k - 1 ] = m_optD[
k ] - m_optD[ k - 1 ] ;
671 std::cout <<
"LVALUE NEGATIVE " << l << std::endl;
679 std::cout <<
"LVALUE BIGGER THAN UPPER BOUND " << l << std::endl;
728 m_u[i][l1] = *(c + k*(m_numNodes - 1) + i - 1);
745 if(
m_u[i][l] + *(c + i*(m_numNodes-1) +
k ) < rcost){
747 rcost =
m_u[i][l] + *(c + i*(m_numNodes-1) + k );
760 *(
m_varIdx + (*kountVar)++) = startPnt + bestLastNode*(m_numNodes - 1) +
k ;
761 *(
m_varIdx + (*kountVar)++) = startPnt + k*(m_numNodes - 1) + bestLastNode - 1;
775 for(l2 = lowerVal; l2 <= l; l2++){
789 if(
m_px[j][ l1 ] != i ){
792 m_g[
j][i] =
m_u[
j][ l1 ] + *(c + j*(m_numNodes-1) + i - 1) ;
799 m_g[
j][i] =
m_v[
j][ l1] + *(c + j*(m_numNodes-1) + i - 1) ;
807 if(
m_g[j][i] <
m_u[i][l2] ){
825 if(
m_px[j][ l1 ] != i ){
828 m_g[
j][i] =
m_u[
j][ l1 ] + *(c + j*(m_numNodes-1) + i ) ;
833 m_g[
j][i] =
m_v[
j][ l1] + *(c + j*(m_numNodes-1) + i ) ;
839 if(
m_g[j][i] <
m_u[i][l2] ){
857 if( (
m_g[j][i] <
m_v[i][l2] ) && (
m_px[i][l2] != j) ){
875 if(
m_u[i][l2] + *(c + i*(m_numNodes-1) + k ) < rcost){
877 rcost =
m_u[i][l2] + *(c + i*(m_numNodes-1) + k );
909 *(
m_varIdx + (*kountVar)++) = startPnt + bestLastNode*(m_numNodes - 1) +
k ;
918 currentNode = bestLastNode;
923 while(currentNode != k){
925 if(
m_px[ currentNode][ lvalue ] != successorNode){
930 successorNode = currentNode;
931 currentNode =
m_px[ currentNode][ lvalue ];
934 if(currentNode - successorNode > 0){
937 *(
m_varIdx + (*kountVar)++) = startPnt + currentNode*(m_numNodes - 1) + successorNode;
943 *(
m_varIdx + (*kountVar)++) = startPnt + currentNode*(m_numNodes - 1) + successorNode - 1 ;
952 successorNode = currentNode;
953 currentNode =
m_tx[ currentNode][ lvalue ];
955 if(currentNode - successorNode > 0){
957 *(
m_varIdx + (*kountVar)++) = startPnt + currentNode*(m_numNodes - 1) + successorNode;
961 *(
m_varIdx + (*kountVar)++) = startPnt + currentNode*(m_numNodes - 1) + successorNode - 1 ;
968 lvalue = lvalue - *(
m_demand + successorNode);
987 const double* yB,
const int numBRows,
988 int &numNewColumns,
int* &numNonzVec,
double* &costVec,
989 int** &rowIdxVec,
double** &valuesVec,
double &lowerBound)
996 int numCoulpingConstraints;
1025 double start = CoinCpuTime();
1027 cpuTime = CoinCpuTime() - start;
1028 std::cout <<
"DYNAMIC PROGRSMMING CPU TIME " << cpuTime << std::endl;
1036 std::cout <<
" whichBlock = " << k <<
" L = " <<
m_optL[
k] << std::endl;
1047 std::cout <<
"Best Reduced Cost Hub " << k <<
" = " <<
m_optValHub[
k] << std::endl;
1056 for(j = 0; j < kountVar; j++){
1073 for(i = 0; i < numCoulpingConstraints; i++){
1136 for(j = 0; j < kountVar; j++){
1203 std::cout <<
"Lower Bound = " <<
m_lowerBnd << std::endl;
1208 std::cout <<
"TOTAL DEMAND = " <<
m_totalDemand << std::endl;
1209 std::cout <<
"Test Value = " << testVal << std::endl;
1210 throw ErrorClass(
"inconsistent demand calculation" );
1229 std::cout <<
"LEAVING GET COLUMNS" << std::endl;
1532 std::cout <<
"Executing OSBearcatSolverXkij::getInitialRestrictedMaster2( )" << std::endl;
1551 std::string testFileName;
1554 std::map<int, std::map<int, std::vector<int> > >::iterator mit;
1555 std::map<int, std::vector<int> >::iterator mit2;
1556 std::vector<int>::iterator vit;
1573 int *starts =
new int[ numThetaVar + 1 + numVarArt];
1580 for(i = 0; i < numVarArt; i++){
1586 std::vector<IndexValuePair*> primalValPair;
1594 xVar =
new double[ numXVar];
1596 for(i = 0; i < numXVar; i++){
1603 int* numRowNonz = NULL;
1604 int** colIdx = NULL;
1605 double** rowValues = NULL ;
1620 osinstance = osilreader->
readOSiL(osil);
1636 for ( mit2 = mit->second.begin() ; mit2 != mit->second.end(); mit2++ ){
1640 for ( vit = mit2->second.begin() ; vit != mit2->second.end(); vit++ ){
1644 std::cout <<
"FIXING LOWER BOUND ON VARIABLE " << osinstance->
getVariableNames()[ kount + mit2->first*
m_numNodes + *vit ] << std::endl;
1667 for(j = 0; j < i; j++){
1683 std::string* varNames;
1710 std::string masterVarName;
1716 objcoeff->
indexes[ varNumber ] = varNumber ;
1731 values[ kountNonz] = 1;
1732 indexes[ kountNonz++] = i ;
1733 starts[ startsIdx++] = kountNonz;
1779 OsiSolverInterface *si = solver->
osiSolver;
1800 while(isCutAdded ==
true){
1809 idx1 = 2*m_numHubs + k*m_numNodes*(m_numNodes - 1);
1810 idx2 = idx1 + m_numNodes*(m_numNodes - 1);
1813 std::cout <<
"HUB " << k <<
" VARIABLES" << std::endl;
1820 for(i = idx1; i < idx2; i++){
1821 if( primalValPair[ i]->value > .01 ){
1822 std::cout << osinstance->
getVariableNames()[ primalValPair[ i]->idx ] << std::endl;
1823 std::cout <<
m_variableNames[ primalValPair[ i]->idx - k*(m_numNodes - 1)*m_numNodes - 2*m_numHubs ] <<
" " << primalValPair[ i]->value << std::endl;
1827 xVar[ primalValPair[ i]->idx - k*(m_numNodes - 1)*m_numNodes - 2*m_numHubs ] = primalValPair[ i]->value;
1836 getCutsX(xVar, numXVar, numNewRows, numRowNonz,
1837 colIdx,rowValues, rowLB, rowUB);
1841 if(numNewRows >= 1){
1843 std::cout <<
"WE HAVE A CUT " << std::endl;
1844 std::cout <<
"EXPRESS CUT IN X(I, J) SPACE" << std::endl;
1845 for(i = 0; i < numRowNonz[ 0]; i++){
1852 for(i = 0; i < numNewRows; i++){
1856 std::cout <<
"EXPRESS CUT IN X(K, I, J) SPACE" << std::endl;
1858 for(j = 0; j < numRowNonz[ i]; j++){
1860 colIdx[ i][
j] = colIdx[ i][
j] + k*(m_numNodes - 1)*m_numNodes + 2*m_numHubs ;
1865 std::cout <<
"CUT UPPER BOUND = " << rowUB[ i] << std::endl;
1868 si->addRow(numRowNonz[ i], colIdx[ i], rowValues[ i], rowLB[ i], rowUB[ i] ) ;
1878 for(i = idx1; i < idx2; i++){
1879 if( primalValPair[ i]->value > .01 ){
1880 xVar[ primalValPair[ i]->idx - k*(m_numNodes - 1)*m_numNodes - 2*m_numHubs ] = 0;
1888 std::cout <<
"Optimal Objective Value = " << primalValPair[
k]->value*primalValPair[ k +
m_numHubs]->value << std::endl;
1895 std::cout << std::endl << std::endl;
1896 if( isCutAdded ==
true) {
1898 std::cout <<
"A CUT WAS ADDED, CALL SOLVE AGAIN" << std::endl;
1902 std::cout <<
"Optimal Objective Value = " << solver->
osresult->
getObjValue(0, 0) << std::endl;
1920 idx1 = 2*m_numHubs + k*m_numNodes*(m_numNodes - 1);
1921 idx2 = idx1 + m_numNodes*(m_numNodes - 1);
1938 for(j1 = 0; j1 < i1; j1++){
1942 if( primalValPair[ idx1 ]->value > .1 ){
1947 if(j1 >= m_numHubs){
1949 values[ kountNonz] = 1;
1950 indexes[ kountNonz++] = j1 -
m_numHubs ;
1966 if( primalValPair[ idx1 ]->value > .1 ){
1972 if(j1 >= m_numHubs){
1974 values[ kountNonz] = 1;
1975 indexes[ kountNonz++] = j1 -
m_numHubs ;
1990 values[ kountNonz] = 1;
1991 indexes[ kountNonz++] = m_numNodes - m_numHubs +
k ;
1994 std::cout <<
" m_numThetaVar " <<
m_numThetaVar << std::endl;
2002 masterVarName +=
")";
2003 intVarSet.insert ( std::pair<int,double>(varNumber, 1.0) );
2006 std::cout <<
"Optimal Objective Value = " << primalValPair[
k]->value*primalValPair[ k +
m_numHubs]->value << std::endl;
2008 objcoeff->
indexes[ k + numVarArt ] = k + numVarArt ;
2009 objcoeff->
values[ k + numVarArt ] = primalValPair[
k]->value*primalValPair[ k +
m_numHubs]->value;
2013 std::cout <<
"m_bestIPValue = " <<
m_bestIPValue << std::endl;
2014 starts[ startsIdx++] = kountNonz;
2021 for( i = 0; i < m_numNodes -
m_numHubs ; i++){
2029 for( i = m_numNodes - m_numHubs; i <
m_numNodes ; i++){
2039 values, 0, kountNonz - 1, indexes, 0, kountNonz - 1, starts, 0, startsIdx);
2042 primalValPair.clear();
2049 std::cout <<
"NONZ = " << kountNonz << std::endl;
2066 std::cout << std::endl << std::endl << std::endl;
2067 if (osilreader != NULL)
2090 std::cout <<
"Executing getOptions(OSOption *osoption)" << std::endl;
2097 std::vector<SolverOption*> solverOptions;
2098 std::vector<SolverOption*>::iterator vit;
2099 std::vector<int>::iterator vit2;
2100 std::vector<int >demand;
2101 std::vector<int >routeCapacity;
2102 std::vector<int >routeMinPickup;
2106 if (solverOptions.size() == 0)
throw ErrorClass(
"options for routeSolver not available");
2111 std::string routeString;
2112 std::string solutionString;
2113 string::size_type pos1;
2114 string::size_type pos2;
2115 string::size_type pos3;
2118 std::map<int, std::map<int, std::vector<int> > >::iterator mit;
2119 std::map<int, std::vector<int> >::iterator mit2;
2124 for (vit = solverOptions.begin(); vit != solverOptions.end(); vit++) {
2132 if( (*vit)->name.find(
"numHubs") != std::string::npos){
2135 std::istringstream hubBuffer( (*vit)->value);
2137 std::cout <<
"numHubs = " << m_numHubs << std::endl;
2141 if((*vit)->name.find(
"numNodes") != std::string::npos){
2144 std::istringstream numNodesBuffer( (*vit)->value);
2146 std::cout <<
"numNodes = " << m_numNodes << std::endl;
2149 if((*vit)->name.find(
"totalDemand") != std::string::npos){
2152 std::istringstream totalDemandBuffer( (*vit)->value);
2154 std::cout <<
"m_totalDemand = " << m_totalDemand << std::endl;
2157 if((*vit)->name.find(
"routeMinPickup") != std::string::npos){
2160 std::istringstream routeMinPickupBuffer( (*vit)->value);
2161 routeMinPickupBuffer >> tmpVal;
2162 routeMinPickup.push_back( tmpVal);
2166 if( (*vit)->name.find(
"demand") != std::string::npos ){
2169 std::istringstream demandBuffer( (*vit)->value);
2170 demandBuffer >> tmpVal;
2171 if(tmpVal <= 0 && demand.size() >
m_numHubs)
throw ErrorClass(
"must have strictly positive demand");
2173 demand.push_back( tmpVal);
2177 if((*vit)->name.find(
"routeCapacity") != std::string::npos ){
2178 std::istringstream routeCapacityBuffer( (*vit)->value);
2179 routeCapacityBuffer >> tmpVal;
2180 routeCapacity.push_back( tmpVal);
2185 if((*vit)->name.find(
"osilFile") != std::string::npos ){
2191 if( (*vit)->name.find(
"restrictedMasterSolution") != std::string::npos ){
2198 pos1 = (*vit)->category.find(
":");
2199 if(pos1 == std::string::npos )
throw ErrorClass(
"OSoL category attribute not properly defined");
2202 solutionString = (*vit)->category.substr( 0, pos1);
2203 routeString = (*vit)->category.substr( pos1 + 1);
2205 pos2 = solutionString.find(
"n");
2206 if(pos2 == std::string::npos )
throw ErrorClass(
"OSoL category attribute not properly defined");
2208 std::istringstream solutionBuffer( solutionString.substr( pos2 + 1) );
2209 solutionBuffer >> solutionNumber;
2213 pos3 = routeString.find(
"e");
2214 if(pos3 == std::string::npos )
throw ErrorClass(
"OSoL category attribute not properly defined");
2215 std::istringstream routeBuffer( routeString.substr( pos3 + 1) );
2216 routeBuffer >> routeNumber;
2218 std::istringstream nodeBuffer( (*vit)->value);
2219 nodeBuffer >> tmpVal;
2227 mit2 = mit->second.find( routeNumber);
2229 if(mit2 != mit->second.end() ){
2233 mit2->second.push_back( tmpVal);
2239 std::vector<int> tmpVec;
2240 tmpVec.push_back( tmpVal) ;
2241 mit->second.insert( std::pair<
int,std::vector<int> >(routeNumber, tmpVec) );
2248 std::vector<int> tmpVec;
2249 tmpVec.push_back( tmpVal) ;
2251 std::map<int, std::vector<int> > tmpMap;
2252 tmpMap.insert( std::pair<
int,std::vector<int> >(routeNumber, tmpVec) );
2253 m_initSolMap.insert( std::pair<
int, std::map<
int, std::vector<int> > >(solutionNumber, tmpMap) ) ;
2258 if( (*vit)->name.find(
"maxMasterColumns") != std::string::npos){
2261 std::istringstream maxMasterColumns( (*vit)->value);
2263 std::cout <<
"m_maxMasterColumn = " << m_maxMasterColumns << std::endl;
2266 if( (*vit)->name.find(
"maxThetaNonz") != std::string::npos){
2268 std::istringstream maxThetaNonz( (*vit)->value);
2270 std::cout <<
"m_maxThetaNonz = " << m_maxThetaNonz << std::endl;
2273 if( (*vit)->name.find(
"use1OPTstart") != std::string::npos){
2275 if ( (*vit)->value.find(
"true") != std::string::npos )
m_use1OPTstart =
true;
2279 if( (*vit)->name.find(
"maxBmatrixCon") != std::string::npos ){
2281 std::istringstream maxBmatrixCon( (*vit)->value);
2283 std::cout <<
"m_maxBmatrixCon = " << m_maxBmatrixCon << std::endl;
2286 if( (*vit)->name.find(
"maxBmatrixNonz") != std::string::npos ){
2288 std::istringstream maxBmatrixNonz( (*vit)->value);
2290 std::cout <<
"m_maxBmatrixNonz = " << m_maxBmatrixNonz << std::endl;
2314 for (vit2 = routeCapacity.begin(); vit2 != routeCapacity.end(); vit2++) {
2319 routeCapacity.clear();
2326 for (vit2 = routeMinPickup.begin(); vit2 != routeMinPickup.end(); vit2++) {
2331 routeMinPickup.clear();
2340 for (vit2 = demand.begin(); vit2 != demand.end(); vit2++) {
2362 int &numNewRows,
int* &numNonz,
int** &colIdx,
2363 double** &
values,
double* &rowLB,
double* &rowUB) {
2378 tmpRhs =
new double[ numSepRows ];
2380 for(i = 0; i < numSepRows; i++){
2389 ErrorClass(
"number of master varibles in OSBearcatSolverXkij::getCuts inconsistent");
2398 for(i = 0; i < numTheta; i++){
2416 tmpRhs[ rowKount] -= theta[ i];
2427 for(i = indexAdjust; i < numSepRows - 1; i++){
2434 int tmpKount = indexAdjust;
2435 for(
int i1 = m_numHubs; i1 <
m_numNodes; i1++){
2467 std::cout <<
" m_Bmatrix[ j] " << m_Bmatrix[
j] << std::endl ;
2512 for(j = m_pntBmatrix[ m_numBmatrixCon - 1] ;
2558 std::vector<int> dualIdx;
2559 std::vector<int>::iterator vit1;
2560 std::vector<int>::iterator vit2;
2565 for(k = 0; k < indexAdjust; k++){
2577 std::cout <<
"DOING SEPARATION FOR NODE " << k + m_numHubs << std::endl;
2586 for (vit1 = dualIdx.begin(); vit1 != dualIdx.end(); vit1++) {
2590 for (vit2 = dualIdx.begin(); vit2 != dualIdx.end(); vit2++) {
2597 std::cout <<
"CUT VARIABLE = " <<
m_variableNames[ index ] <<std::endl;
2605 std::cout <<
"CUT VARIABLE = " <<
m_variableNames[ index ] <<std::endl;
2623 for(i = indexAdjust; i < numSepRows - 1; i++){
2716 for(i = indexAdjust; i < numSepRows - 1; i++){
2744 int &numNewRows,
int* &numNonz,
int** &colIdx,
2745 double** &
values,
double* &rowLB,
double* &rowUB) {
2760 tmpRhs =
new double[ numSepRows ];
2762 for(i = 0; i < numSepRows; i++){
2770 for(i = 0; i < numX; i++){
2780 tmpRhs[ rowKount] -= x[ i];
2787 for(i = indexAdjust; i < numSepRows - 1; i++){
2795 int tmpKount = indexAdjust;
2796 for(
int i1 = m_numHubs; i1 <
m_numNodes; i1++){
2811 m_newRowColumnValue[ 0][ 1] = 1;
2845 std::vector<int> dualIdx;
2846 std::vector<int>::iterator vit1;
2847 std::vector<int>::iterator vit2;
2852 for(k = 0; k < indexAdjust; k++){
2853 std::cout << std::endl << std::endl;
2862 std::cout <<
"DOING SEPARATION FOR NODE " << k + m_numHubs << std::endl;
2873 for (vit1 = dualIdx.begin(); vit1 != dualIdx.end(); vit1++) {
2877 for (vit2 = dualIdx.begin(); vit2 != dualIdx.end(); vit2++) {
2884 std::cout <<
"CUT VARIABLE = " <<
m_variableNames[ index] <<std::endl;
2893 std::cout <<
"CUT VARIABLE = " <<
m_variableNames[ index] <<std::endl;
2909 for(i = indexAdjust; i < numSepRows - 1; i++){
2940 for(i = indexAdjust; i < numSepRows - 1; i++){
2982 for(j = 0; j < i; j++){
3044 m_rc[
k][ startPnt + m_Bmatrix[
j] ] -= yB[ i];
3069 for(j = 0; j < i; j++){
3114 for(i = 0; i <
j; i++){
3116 m_Amatrix[ numNonz++] = i*(m_numNodes - 1) + j - 1 ;
3122 m_Amatrix[ numNonz++] = i*(m_numNodes - 1) + j ;
3146 std::cout << std::endl;
3147 std::cout <<
" PAU HANA TIME! " << std::endl;
3150 std::vector<int>::iterator vit;
3170 for(vit = m_zOptIndexes.begin() ; vit != m_zOptIndexes.end(); vit++){
3173 std::cout <<
"x variables for column " << i << std::endl;
3187 std::cout <<
"cost = " << cost << std::endl << std::endl;
3189 std::cout << std::endl << std::endl;
3190 std::cout <<
"LOWER BOUND VALUE = " <<
m_bestLPValue << std::endl;
3191 std::cout <<
"FINAL BEST IP SOLUTION VALUE = " <<
m_bestIPValue << std::endl;
3192 std::cout <<
"NUMBER OF COLUMNS IN FINAL MASTER = " <<
m_numThetaVar << std::endl;
3195 std::cout <<
"NUMBER OF GENERATED COLUMNS = " << numColsGen << std::endl;
3196 std::cout <<
"NUMBER OF GENERATED CUTS = " <<
m_numBmatrixCon << std::endl;
3197 std::cout <<
"NUMBER OF NODES = " << numNodes << std::endl;
3198 std::cout <<
" PAU!!!" << std::endl;
3200 std::cout << std::endl << std::endl;
3205 std::cout << std::endl << std::endl;
3233 double *
values =
new double[ 2*numYvar + 2*numVvar];
3234 int *indexes =
new int[ 2*numYvar + 2*numVvar];
3235 int *starts =
new int[ numYvar + numVvar + 1];
3244 std::string separationVarName;
3245 std::string separationConName;
3279 separationConName +=
")";
3294 std::cout <<
"NUMBER OF VARIABLES SET = " << numYvar + numVvar << std::endl;
3296 for(i = 0; i < numVvar; i++){
3302 values[ kountNonz ] = -1.0;
3303 indexes[ kountNonz ] = i;
3306 values[ kountNonz ] = 1.0;
3307 indexes[ kountNonz ] = rowKounter - 1;
3312 starts[ startsIdx++ ] = kountNonz;
3324 for(i1 = 0; i1 < m_numNodes -
m_numHubs; i1++){
3329 for(j1 = i1 + 1; j1 < m_numNodes -
m_numHubs; j1++){
3336 separationVarName +=
")";
3344 values[ kountNonz ] = 1.0;
3345 indexes[ kountNonz ] = i1;
3348 values[ kountNonz ] = -1.0;
3349 indexes[ kountNonz ] = kountCon ;
3352 starts[ startsIdx++ ] = kountNonz;
3359 separationVarName +=
")";
3362 values[ kountNonz ] = 1.0;
3363 indexes[ kountNonz ] = j1;
3369 values[ kountNonz ] = -1.0;
3370 indexes[ kountNonz ] = kountCon ;
3373 starts[ startsIdx++ ] = kountNonz;
3383 std::cout <<
"NUMBER OF VARIABLES ADDED = " << kount << std::endl;
3390 for(i = 0; i < numVvar; i++){
3393 objcoeff->
values[ i] = 1.0;
3405 values, 0, kountNonz - 1, indexes, 0, kountNonz - 1, starts, 0, startsIdx);
3418 CoinPackedMatrix* matrix;
3419 bool columnMajor =
true;
3421 matrix =
new CoinPackedMatrix(
3431 ClpNetworkMatrix network( *matrix);
3467 double from1Distance;
3468 double from0Distance;
3475 xvalues =
new double[ numVar];
3476 for(i = 0; i < numVar; i++){
3504 for( j = 0; j < i; j++){
3507 from1Distance = 1 - xvalues[ i*(
m_numNodes - 1) + j ];
3508 from0Distance = xvalues[ i*(
m_numNodes - 1) + j ];
3509 fraction = std::max(from1Distance, from0Distance);
3511 if(fraction < minFraction){
3513 minFraction = fraction;
3523 from1Distance = 1 - xvalues[ i*(m_numNodes - 1) + j - 1 ];
3524 from0Distance = xvalues[ i*(m_numNodes - 1) + j - 1 ];
3525 fraction = std::max(from1Distance, from0Distance);
3527 if(fraction < minFraction) {
3529 minFraction = fraction;
3530 varIdx = i*(m_numNodes - 1) + j - 1;
3544 for( j = 0; j < i; j++){
3547 from1Distance = 1 - xvalues[ i*(m_numNodes - 1) + j ];
3548 from0Distance = xvalues[ i*(m_numNodes - 1) + j ];
3549 fraction = std::max(from1Distance, from0Distance);
3551 if(fraction < minFraction) {
3553 minFraction = fraction;
3554 varIdx = i*(m_numNodes - 1) + j ;
3563 from1Distance = 1 - xvalues[ i*(m_numNodes - 1) + j - 1 ];
3564 from0Distance = xvalues[ i*(m_numNodes - 1) + j - 1 ];
3565 fraction = std::max(from1Distance, from0Distance);
3567 if(fraction < minFraction) {
3569 minFraction = fraction;
3570 varIdx = i*(m_numNodes - 1) + j - 1;
3578 std::cout <<
" HERE IS GAIL 1" << std::endl;
3583 std::cout <<
" HERE IS GAIL 2" << std::endl;
3603 const int numThetaVar) {
3610 double from1Distance;
3611 double from0Distance;
3618 xvalues =
new double[ numVar];
3619 for(i = 0; i < numVar; i++){
3626 for(i = 0; i < numThetaVar; i++){
3648 for( j = 0; j < i; j++){
3651 from1Distance = 1 - xvalues[ i*(
m_numNodes - 1) + j ];
3652 from0Distance = xvalues[ i*(
m_numNodes - 1) + j ];
3653 fraction = std::max(from1Distance, from0Distance);
3655 if(fraction < minFraction){
3657 minFraction = fraction;
3667 from1Distance = 1 - xvalues[ i*(m_numNodes - 1) + j - 1 ];
3668 from0Distance = xvalues[ i*(m_numNodes - 1) + j - 1 ];
3669 fraction = std::max(from1Distance, from0Distance);
3671 if(fraction < minFraction) {
3673 minFraction = fraction;
3674 varIdx = i*(m_numNodes - 1) + j - 1;
3684 std::cout <<
"MIN FRACTION = " << minFraction << std::endl;
3692 for( j = 0; j < i; j++){
3695 from1Distance = 1 - xvalues[ i*(m_numNodes - 1) + j ];
3696 from0Distance = xvalues[ i*(m_numNodes - 1) + j ];
3697 fraction = std::max(from1Distance, from0Distance);
3699 if(fraction < minFraction) {
3701 minFraction = fraction;
3702 varIdx = i*(m_numNodes - 1) + j ;
3711 from1Distance = 1 - xvalues[ i*(m_numNodes - 1) + j - 1 ];
3712 from0Distance = xvalues[ i*(m_numNodes - 1) + j - 1 ];
3713 fraction = std::max(from1Distance, from0Distance);
3715 if(fraction < minFraction) {
3717 minFraction = fraction;
3718 varIdx = i*(m_numNodes - 1) + j - 1;
3748 const std::map<int, int> &varConMap,
int &varIdx,
int &numNonz,
3749 int* &indexes,
double* &
values) {
3766 std::cout <<
"Branching on Variable: " <<
m_variableNames[ varIdx] << std::endl;
3771 if( varConMap.find( varIdx) == varConMap.end() ){
3829 const int numThetaVar,
const std::map<int, int> &varConMap,
3830 int &varIdx,
int &numNonz,
int* &indexes,
double* &
values) {
3846 std::cout <<
"Branching on Variable: " <<
m_variableNames[ varIdx] << std::endl;
3851 if( varConMap.find( varIdx) == varConMap.end() ){
3947 std::map<int, int>::iterator mit;
3949 int numVars = inVars.size();
3957 std::vector<double> valuesVec;
3960 std::vector<int> indexesVec;
3961 int *indexes = NULL ;
3963 int *starts =
new int[ numVars + 1 + numVarArt];
3977 for(mit = inVars.begin(); mit != inVars.end(); mit++){
3983 thetaPntTmp =
new int[ numVars + 1];
3984 thetaIndexTmp =
new int[ numNonz];
3988 for(mit = inVars.begin(); mit != inVars.end(); mit++){
4000 thetaPntTmp[ kount] = 0;
4002 for(mit = inVars.begin(); mit != inVars.end(); mit++){
4016 thetaPntTmp[ kount] = numNonz;
4022 inVars[ mit->first] = numVarArt + kount - 1 ;
4038 for(i = 0; i < numVarArt; i++){
4048 for(mit = inVars.begin(); mit != inVars.end(); mit++){
4051 intVarSet.insert ( std::pair<int,double>(mit->second, 1.0) );
4060 for(j = thetaPntTmp[ mit->second - numVarArt]; j < thetaPntTmp[ mit->second - numVarArt + 1 ]; j++){
4080 si->writeLp(
"gailTest" );
4088 starts[ startsIdx++] = numNonz;
4090 for(i = 0; i < numVarArt; i++){
4092 starts[ startsIdx++] = numNonz;
4093 valuesVec.push_back( 1.0);
4094 indexesVec.push_back( i);
4104 for(mit = inVars.begin(); mit != inVars.end(); mit++){
4107 valuesVec.push_back( 1.0);
4123 for(i = 0; i < numAmatrixRows; i++){
4142 valuesVec.push_back( rowCount);
4143 indexesVec.push_back( i);
4172 valuesVec.push_back( rowCount);
4188 starts[ startsIdx++] = numNonz;
4194 values =
new double[ numNonz];
4195 indexes =
new int[ numNonz];
4197 if(numNonz != valuesVec.size() )
throw ErrorClass(
"dimension problem in reset");
4198 if(numNonz != indexesVec.size() )
throw ErrorClass(
"dimension problem in reset");
4200 for(i = 0; i < numNonz; i++){
4202 values[ i] = valuesVec[i];
4203 indexes[ i] = indexesVec[i];
4242 for(i = 0; i < numVarArt; i++){
4244 objcoeff->
indexes[ varNumber ] = varNumber ;
4258 for(mit = inVars.begin(); mit != inVars.end(); mit++){
4260 objcoeff->
indexes[ varNumber ] = varNumber ;
4262 objcoeff->
values[ varNumber ] = si->getObjCoefficients()[ mit->first] ;
4264 m_thetaCost[ varNumber] = si->getObjCoefficients()[ mit->first];
4285 for(i = m_numNodes; i < m_numBmatrixCon +
m_numNodes; i++){
4288 si->getRowLower()[ i], si->getRowUpper()[ i], 0);
4300 values, 0, numNonz - 1, indexes, 0, numNonz - 1, starts, 0, startsIdx);
4306 delete[] tmpConvexity;
4307 tmpConvexity = NULL;
4308 delete[] thetaPntTmp;
4310 delete[] thetaIndexTmp;
4311 thetaIndexTmp = NULL;
4319 ostringstream outStr;
4320 outStr << theString;
4322 return outStr.str();
double * getConstraintLowerBounds()
Get constraint lower bounds.
double * getVariableLowerBounds()
Get variable lower bounds.
double * getConstraintUpperBounds()
Get constraint upper bounds.
int * m_separationIndexMap
m_separationIndexMap maps the variable index into the appropriate row in the separation problem for t...
OSInstance * m_osinstanceSeparation
int m_maxMasterRows
m_maxMasterColumns is the maximumn number of rows we allow in the master, in this application it is e...
bool addVariable(int index, std::string name, double lowerBound, double upperBound, char type)
add a variable.
bool bConstraintsModified
bConstraintsModified is true if the constraints data has been modified.
double getObjValue(int solIdx, int objIdx)
std::string getSolutionStatusType(int solIdx)
Get the [i]th optimization solution status type, where i equals the given solution index...
bool setLinearConstraintCoefficients(int numberOfValues, bool isColumnMajor, double *values, int valuesBegin, int valuesEnd, int *indexes, int indexesBegin, int indexesEnd, int *starts, int startsBegin, int startsEnd)
set linear constraint coefficients
int getVariableNumber()
Get number of variables.
std::string printModel()
Print the infix representation of the problem.
double ** m_newColumnRowValue
void getOptions(OSOption *osoption)
void calcReducedCost(const double *yA, const double *yB)
calculate the reduced costs c – input of the objective function costs yA – dual values on node assign...
std::string errormsg
errormsg is the error that is causing the exception to be thrown
std::string m_initOSiLFile
OsiSolverInterface * osiSolver
osiSolver is the osi solver object – in this case clp, glpk, cbc, cplex, symphony or dylp ...
int getLinearConstraintCoefficientNumber()
Get number of specified (usually nonzero) linear constraint coefficient values.
int * m_routeCapacity
the route capacity – bus seating limit this can vary with the route/hub
int * m_upperBoundL
largest possible L-value on a route – this will be the minimum of m_routeCapacity and total demand ...
std::vector< SolverOption * > getSolverOptions(std::string solver_name)
Get the options associated with a given solver.
std::vector< IndexValuePair * > getOptimalPrimalVariableValues(int solIdx)
Get one solution of optimal primal variable values.
ObjCoef ** coef
coef is pointer to an array of ObjCoef object pointers
OSInstance * m_osinstanceMaster
std::map< int, std::map< int, std::vector< int > > > m_initSolMap
the index on the outer map is on the solution number, the index on the inner map indexes the route nu...
OSResult * osresult
osresult holds the solution or result of the model in-memory as an OSResult object ...
OSInstance * getSeparationInstance()
int m_numBmatrixCon
m_numBmatrixCon is the number of constraints in B - 1, we have the -1 because: m_pntBmatrix[ k] point...
OSInstance * readOSiL(const std::string &osil)
parse the OSiL model instance.
std::string * getVariableNames()
Get variable names.
void getInitialSolution()
generate an intitial feasible solution in theta space for the initial master
virtual void buildSolverInstance()
The implementation of the corresponding virtual function.
int * indexes
indexes holds an integer array of rowIdx (or colIdx) elements in coefMatrix (AMatrix).
int m_minDemand
m_minDemand is the value of the minimum demand node – it is not the minimum demand that must be carri...
double ** getDenseObjectiveCoefficients()
getDenseObjectiveCoefficients.
double ** m_cost
the distance/cost vectors
virtual void getColumns(const double *yA, const int numARows, const double *yB, const int numBRows, int &numNewColumns, int *&numNonz, double *&cost, int **&rowIdx, double **&values, double &lowerBound)
RETURN VALUES: int numNewColumns – number of new columns generated int* numNonz – number of nonzeros ...
void getCutsX(const double *xVar, const int numXVar, int &numNewRows, int *&numNonz, int **&colIdx, double **&values, double *&rowLB, double *&rowUB)
RETURN VALUES: int numNewRows – number of new rows generated int* numNonz – number of nonzeros in eac...
virtual void resetMaster(std::map< int, int > &inVars, OsiSolverInterface *si)
INPUT:
bool setConstraintNumber(int number)
set the number of constraints.
Used to read an OSiL string.
int * m_lowerBoundL
smallest possible L-value on a route for now this will equal
int * m_demand
m_demand is the vector of node demands
virtual void pauHana(std::vector< int > &m_zOptIndexes, int numNodes, int numColsGen)
double lb
lb corresponds to the optional attribute that holds the variable lower bound.
~OSBearcatSolverXkij()
Default Destructor.
double qrouteCost(const int &k, const int &l, const double *c, int *kountVar)
kipp – document
Variable ** var
Here we define a pointer to an array of var pointers.
std::set< std::pair< int, double > > intVarSet
intVarSet holds and std::pair where the first element is the index of an integer variable and the sec...
virtual void initializeDataStructures()
allocate memory and initialize arrays
SparseMatrix * getLinearConstraintCoefficientsInRowMajor()
Get linear constraint coefficients in row major.
double value
value is the value of the objective function coefficient corresponding to the variable with index idx...
bool setObjectiveNumber(int number)
set the number of objectives.
OSOption * osoption
osoption holds the solver options in-memory as an OSOption object
bool addConstraint(int index, std::string name, double lowerBound, double upperBound, double constant)
add a constraint.
bool addObjective(int index, std::string name, std::string maxOrMin, double constant, double weight, SparseVector *objectiveCoefficients)
add an objective.
a sparse vector data structure
Variables * variables
variables is a pointer to a Variables object
double ** m_newRowColumnValue
SparseMatrix * getLinearConstraintCoefficientsInColumnMajor()
Get linear constraint coefficients in column major.
double * values
values holds a double array of value elements in coefMatrix (AMatrix), which contains nonzero element...
OSInstance * osinstance
osinstance holds the problem instance in-memory as an OSInstance object
void createVariableNames()
InstanceData * instanceData
A pointer to an InstanceData object.
int * convexityRowIndex
conconvexityRowIndex holds the index of the convexity row that the theta columns are in...
int getConstraintNumber()
Get number of constraints.
Objective ** obj
coef is pointer to an array of ObjCoef object pointers
std::string sSolverName
sSolverName is the name of the Coin solver used, e.g.
std::string makeStringFromInt2(std::string theString, int theInt)
bool setInstanceDescription(std::string description)
set the instance description.
OSBearcatSolverXkij()
Default Constructor.
Objectives * objectives
objectives is a pointer to a Objectives object
Implements a solve method for the Coin solvers.
std::string getFileAsString(const char *fname)
read a file and return contents as a string.
ClpSimplex * m_separationClpModel
int m_numNodes
m_numNodes is the number of nodes (both pickup and hub) in the model
int * starts
starts holds an integer array of start elements in coefMatrix (AMatrix), which points to the start of...
double * values
values holds a double array of nonzero values.
bool bVariablesModified
bVariablesModified is true if the variables data has been modified.
double * getVariableUpperBounds()
Get variable upper bounds.
int m_maxThetaNonz
m_maxMasterNonz is the maximumn number of nonzero elements we allow in the transformation matrix betw...
int getBranchingVar(const double *theta, const int numThetaVar)
RETURN VALUES: return the integer index of a fractional x_{ij} variable.
int * m_routeMinPickup
the minimum number of students that we pickup on a route this can vary with the route/hub ...
int * indexes
indexes holds an integer array of indexes whose corresponding values are nonzero. ...
virtual void getBranchingCut(const double *thetaVar, const int numThetaVar, const std::map< int, int > &varConMap, int &varIdx, int &numNonz, int *&indexes, double *&values)
RETURN VALUES: varIdx – the variable number x_{ij} for branching numNonz – number of theta indexes in...
bool m_use1OPTstart
if m_use1OPTstart is true we use the option file to fix the nodes to hubs found by SK's 1OPT heuristi...
std::string * m_variableNames
void getCutsTheta(const double *thetaVar, const int numThetaVar, int &numNewRows, int *&numNonz, int **&colIdx, double **&values, double *&rowLB, double *&rowUB)
RETURN VALUES: int numNewRows – number of new rows generated int* numNonz – number of nonzeros in eac...
int m_maxBmatrixNonz
m_maxBmatrixNonz is the maximum number of nonzero elements in the B matrix constraints ...
bool setVariableNumber(int number)
set the number of variables.
The in-memory representation of an OSiL instance..
virtual OSInstance * getInitialRestrictedMaster()
OSInstance* OSBearcatSolverXkij::getInitialRestrictedMaster( ){.
class used to make it easy to read and write files.
virtual void solve()
The implementation of the corresponding virtual function.
int m_upperBoundLMax
largest possible L-value over all routes
double zeroTol
we terminate column generation when the reduced costs are not smaller than zeroTol ...
double ** m_rc
the reduced cost vector for each k, we asssume order is (l, i, j)
OSDecompParam m_osDecompParam
share the parameters with the decomposition solver
used for throwing exceptions.
int m_numHubs
m_numHubs is the number of hubs/routes
int m_maxMasterColumns
m_maxMasterColumns is the maximumn number of columns we allow in the master
int m_maxBmatrixCon
m_maxBmatrixCon is the maximum number of B matrix constraints it is the number of tour breaking const...
void fint fint fint real fint real * x
double artVarCoeff
artVarCoeff is the coefficient of the artificial variable in the objective function ...