19 #include "OSInstance.h"
30 #include "OSInstance.h"
34 #include "CoinTime.hpp"
36 #include "ClpFactorization.hpp"
37 #include "ClpNetworkMatrix.hpp"
38 #include "OsiClpSolverInterface.hpp"
51 # error "don't have header file for math"
61 # error "don't have header file for time"
65 using std::ostringstream;
69 std::cout <<
"INSIDE OSBearcatSolverXij CONSTRUCTOR with OSOption argument" << std::endl;
73 std::cout <<
"INSIDE OSBearcatSolverXij CONSTRUCTOR with OSOption argument" << std::endl;
125 if(
m_cost == NULL)
throw ErrorClass(
"Option file did not contain cost data");
244 int numVar = m_numNodes*m_numNodes -
m_numNodes ;
246 for(i = 0; i < numVar; i++){
285 for (k = 0; k < 100; k++) {
333 for(i = 0; i < m_numNodes*(m_numNodes - 1); i++){
362 std::cout <<
"INSIDE ~OSBearcatSolverXij DESTRUCTOR" << std::endl;
556 std::vector<CoinSolver*>::iterator vit;
622 for(d1 = 0; d1 <= d; d1++){
635 testVal =
qrouteCost( m_hubPoint[ k - 1], l, c[ m_hubPoint[ k - 1] ], &kountVar);
640 if(
m_vv[ m_hubPoint[ k-1] ][ d1] + testVal <
m_vv[ m_hubPoint[ k] ][ d] ){
642 m_vv[ m_hubPoint[
k] ][ d] =
m_vv[ m_hubPoint[ k-1] ][
d1] + testVal;
671 l = m_totalDemand - d;
682 testVal =
qrouteCost(m_hubPoint[m_numHubs -1] , l, c[ m_hubPoint[ m_numHubs -1] ], &kountVar);
687 if(
m_vv[ m_hubPoint[ m_numHubs - 1] ][ d] + testVal < trueMin){
689 trueMin =
m_vv[ m_hubPoint[ m_numHubs -1] ][ d] + testVal;
690 m_optD[ m_hubPoint[ m_numHubs -1] ] = d;
691 m_optL[ m_hubPoint[ m_numHubs -1] ] = l;
701 if( isFeasible ==
false){
703 std::cout <<
"NOT ENOUGH CAPACITY " << std::endl;
704 for(k = 0; k <
m_numHubs; k++) std::cout <<
" k perm = " << m_hubPoint[ k ]<< std::endl;
739 std::cout <<
"LVALUE NEGATIVE OR ZERO " << l << std::endl;
747 std::cout <<
"LVALUE BIGGER THAN UPPER BOUND " << l << std::endl;
799 m_u[i][l1] = *(c + k*(m_numNodes - 1) + i - 1);
819 if(
m_u[i][l] + *(c + i*(m_numNodes-1) +
k ) < rcost){
821 rcost =
m_u[i][l] + *(c + i*(m_numNodes-1) + k );
834 *(
m_varIdx + (*kountVar)++) = startPnt + bestLastNode*(m_numNodes - 1) +
k ;
835 *(
m_varIdx + (*kountVar)++) = startPnt + k*(m_numNodes - 1) + bestLastNode - 1;
864 if(
m_px[j][ l1 ] != i ){
867 m_g[
j][i] =
m_u[
j][ l1 ] + *(c + j*(m_numNodes-1) + i - 1) ;
874 m_g[
j][i] =
m_v[
j][ l1] + *(c + j*(m_numNodes-1) + i - 1) ;
882 if(
m_g[j][i] <
m_u[i][l2] ){
900 if(
m_px[j][ l1 ] != i ){
903 m_g[
j][i] =
m_u[
j][ l1 ] + *(c + j*(m_numNodes-1) + i ) ;
908 m_g[
j][i] =
m_v[
j][ l1] + *(c + j*(m_numNodes-1) + i ) ;
914 if(
m_g[j][i] <
m_u[i][l2] ){
932 if( (
m_g[j][i] <
m_v[i][l2] ) && (
m_px[i][l2] != j) ){
950 if(
m_u[i][l2] + *(c + i*(m_numNodes-1) + k ) < rcost){
952 rcost =
m_u[i][l2] + *(c + i*(m_numNodes-1) + k );
985 *(
m_varIdx + (*kountVar)++) = startPnt + bestLastNode*(m_numNodes - 1) +
k ;
994 currentNode = bestLastNode;
1001 while(currentNode != k){
1004 if(
m_px[ currentNode][ lvalue ] != successorNode){
1009 successorNode = currentNode;
1010 currentNode =
m_px[ currentNode][ lvalue ];
1013 if(currentNode - successorNode > 0){
1018 *(
m_varIdx + (*kountVar)++) = startPnt + currentNode*(m_numNodes - 1) + successorNode;
1026 *(
m_varIdx + (*kountVar)++) = startPnt + currentNode*(m_numNodes - 1) + successorNode - 1 ;
1035 successorNode = currentNode;
1036 currentNode =
m_tx[ currentNode][ lvalue ];
1038 if(currentNode - successorNode > 0){
1042 *(
m_varIdx + (*kountVar)++) = startPnt + currentNode*(m_numNodes - 1) + successorNode;
1047 *(
m_varIdx + (*kountVar)++) = startPnt + currentNode*(m_numNodes - 1) + successorNode - 1 ;
1056 lvalue = lvalue - *(
m_demand + successorNode);
1075 const double* yB,
const int numBRows,
1076 int &numNewColumns,
int* &numNonzVec,
double* &costVec,
1077 int** &rowIdxVec,
double** &valuesVec,
double &lowerBound)
1084 int numCoulpingConstraints;
1113 double start = CoinCpuTime();
1115 cpuTime = CoinCpuTime() - start;
1116 std::cout <<
"DYNAMIC PROGRAMMING CPU TIME " << cpuTime << std::endl;
1124 std::cout <<
" whichBlock = " << k <<
" L = " <<
m_optL[
k] << std::endl;
1135 std::cout <<
"Best Reduced Cost Hub " << k <<
" = " <<
m_optValHub[
k] << std::endl;
1144 for(j = 0; j < kountVar; j++){
1162 for(i = 0; i < numCoulpingConstraints; i++){
1236 for(j = 0; j < kountVar; j++){
1306 std::cout <<
"Lower Bound = " <<
m_lowerBnd << std::endl;
1311 std::cout <<
"TOTAL DEMAND = " <<
m_totalDemand << std::endl;
1312 std::cout <<
"Test Value = " << testVal << std::endl;
1313 throw ErrorClass(
"inconsistent demand calculation" );
1332 std::cout <<
"LEAVING GET COLUMNS" << std::endl;
1636 std::cout <<
"Executing OSBearcatSolverXij::getInitialRestrictedMaster( )" << std::endl;
1646 double* xVar = NULL;
1647 xVar =
new double[ numXVar];
1651 std::string testFileName;
1654 std::map<int, std::map<int, std::vector<int> > >::iterator mit;
1655 std::map<int, std::vector<int> >::iterator mit2;
1656 std::vector<int>::iterator vit;
1669 int *starts =
new int[ numThetaVar + 1 + numVarArt];
1681 for(i = 0; i < numVarArt; i++){
1708 std::string masterVarName;
1713 objcoeff->
indexes[ varNumber ] = varNumber ;
1724 values[ kountNonz] = 1;
1725 indexes[ kountNonz++] = i ;
1726 starts[ startsIdx++] = kountNonz;
1740 mit2 = mit->second.find( k);
1741 if(mit2 == mit->second.end() )
throw ErrorClass(
"Problem finding hub k in the solution map");
1744 mit2->second, xVar);
1747 for ( vit = mit2->second.begin() ; vit != mit2->second.end(); vit++ ) {
1750 values[ kountNonz] = 1;
1751 indexes[ kountNonz++] = *vit -
m_numHubs ;
1757 for(i = 0; i < numXVar; i++){
1768 values[ kountNonz] = 1;
1769 indexes[ kountNonz++] = m_numNodes - m_numHubs +
k ;
1780 masterVarName +=
")";
1781 intVarSet.insert ( std::pair<int,double>(varNumber, 1.0) );
1784 std::cout <<
"Optimal Objective Value = " << demandSum*tspObjValue << std::endl;
1787 objcoeff->
indexes[ k + numVarArt ] = k + numVarArt ;
1788 objcoeff->
values[ k + numVarArt ] = demandSum*tspObjValue;
1792 std::cout <<
"m_bestIPValue = " <<
m_bestIPValue << std::endl;
1793 starts[ startsIdx++] = kountNonz;
1796 std::cout <<
" m_numThetaVar " <<
m_numThetaVar << std::endl;
1800 for( i = 0; i < m_numNodes -
m_numHubs ; i++){
1808 for( i = m_numNodes - m_numHubs; i <
m_numNodes ; i++){
1818 values, 0, kountNonz - 1, indexes, 0, kountNonz - 1, starts, 0, startsIdx);
1822 std::cout <<
"NONZ = " << kountNonz << std::endl;
1836 std::cout << std::endl << std::endl << std::endl;
1838 if(objcoeff != NULL)
delete objcoeff;
1839 if(xVar != NULL)
delete xVar;
1852 std::cout <<
"Executing getOptions(OSOption *osoption)" << std::endl;
1859 std::vector<SolverOption*> solverOptions;
1860 std::vector<SolverOption*>::iterator vit;
1861 std::vector<int>::iterator vit2;
1862 std::vector<int >demand;
1863 std::vector<std::string >nodeName;
1864 std::vector<int >routeCapacity;
1865 std::vector<int >routeMinPickup;
1866 std::vector<double >arcCost;
1867 std::vector<double >::iterator vit3;
1868 std::vector<std::string>::iterator vit4;
1873 if (solverOptions.size() == 0)
throw ErrorClass(
"options for routeSolver not available");
1880 std::string routeString;
1881 std::string solutionString;
1882 std::string::size_type pos1;
1883 std::string::size_type pos2;
1884 std::string::size_type pos3;
1887 std::map<int, std::map<int, std::vector<int> > >::iterator mit;
1888 std::map<int, std::vector<int> >::iterator mit2;
1893 for (vit = solverOptions.begin(); vit != solverOptions.end(); vit++) {
1901 if( (*vit)->name.find(
"numHubs") != std::string::npos){
1904 std::istringstream hubBuffer( (*vit)->value);
1906 std::cout <<
"numHubs = " << m_numHubs << std::endl;
1910 if((*vit)->name.find(
"numNodes") != std::string::npos){
1913 std::istringstream numNodesBuffer( (*vit)->value);
1915 std::cout <<
"numNodes = " << m_numNodes << std::endl;
1918 if((*vit)->name.find(
"totalDemand") != std::string::npos){
1921 std::istringstream totalDemandBuffer( (*vit)->value);
1923 std::cout <<
"m_totalDemand = " << m_totalDemand << std::endl;
1926 if((*vit)->name.find(
"routeMinPickup") != std::string::npos){
1929 std::istringstream routeMinPickupBuffer( (*vit)->value);
1930 routeMinPickupBuffer >> tmpVal;
1931 routeMinPickup.push_back( tmpVal);
1935 if( (*vit)->name.find(
"demand") != std::string::npos ){
1938 std::istringstream demandBuffer( (*vit)->value);
1939 demandBuffer >> tmpVal;
1940 if(tmpVal <= 0 && demand.size() > (
unsigned int)
m_numHubs)
throw ErrorClass(
"must have strictly positive demand");
1942 demand.push_back( tmpVal);
1943 nodeName.push_back( (*vit)->description);
1947 if((*vit)->name.find(
"routeCapacity") != std::string::npos ){
1948 std::istringstream routeCapacityBuffer( (*vit)->value);
1949 routeCapacityBuffer >> tmpVal;
1950 routeCapacity.push_back( tmpVal);
1951 std::cout <<
"m_routeCapacity = " << tmpVal << std::endl;
1955 if((*vit)->name.find(
"osilFile") != std::string::npos ){
1961 if( (*vit)->name.find(
"restrictedMasterSolution") != std::string::npos ){
1968 pos1 = (*vit)->category.find(
":");
1969 if(pos1 == std::string::npos )
throw ErrorClass(
"OSoL category attribute not properly defined");
1972 solutionString = (*vit)->category.substr( 0, pos1);
1973 routeString = (*vit)->category.substr( pos1 + 1);
1975 pos2 = solutionString.find(
"n");
1976 if(pos2 == std::string::npos )
throw ErrorClass(
"OSoL category attribute not properly defined");
1978 std::istringstream solutionBuffer( solutionString.substr( pos2 + 1) );
1979 solutionBuffer >> solutionNumber;
1983 pos3 = routeString.find(
"e");
1984 if(pos3 == std::string::npos )
throw ErrorClass(
"OSoL category attribute not properly defined");
1985 std::istringstream routeBuffer( routeString.substr( pos3 + 1) );
1986 routeBuffer >> routeNumber;
1988 std::istringstream nodeBuffer( (*vit)->value);
1989 nodeBuffer >> tmpVal;
1997 mit2 = mit->second.find( routeNumber);
1999 if(mit2 != mit->second.end() ){
2003 mit2->second.push_back( tmpVal);
2009 std::vector<int> tmpVec;
2010 tmpVec.push_back( tmpVal) ;
2011 mit->second.insert( std::pair<
int,std::vector<int> >(routeNumber, tmpVec) );
2018 std::vector<int> tmpVec;
2019 tmpVec.push_back( tmpVal) ;
2021 std::map<int, std::vector<int> > tmpMap;
2022 tmpMap.insert( std::pair<
int,std::vector<int> >(routeNumber, tmpVec) );
2023 m_initSolMap.insert( std::pair<
int, std::map<
int, std::vector<int> > >(solutionNumber, tmpMap) ) ;
2028 if( (*vit)->name.find(
"maxMasterColumns") != std::string::npos){
2031 std::istringstream maxMasterColumns( (*vit)->value);
2033 std::cout <<
"m_maxMasterColumn = " << m_maxMasterColumns << std::endl;
2036 if( (*vit)->name.find(
"maxThetaNonz") != std::string::npos){
2038 std::istringstream maxThetaNonz( (*vit)->value);
2040 std::cout <<
"m_maxThetaNonz = " << m_maxThetaNonz << std::endl;
2043 if( (*vit)->name.find(
"use1OPTstart") != std::string::npos){
2045 if ( (*vit)->value.find(
"true") != std::string::npos )
m_use1OPTstart =
true;
2049 if( (*vit)->name.find(
"maxBmatrixCon") != std::string::npos ){
2051 std::istringstream maxBmatrixCon( (*vit)->value);
2053 std::cout <<
"m_maxBmatrixCon = " << m_maxBmatrixCon << std::endl;
2056 if( (*vit)->name.find(
"maxBmatrixNonz") != std::string::npos ){
2058 std::istringstream maxBmatrixNonz( (*vit)->value);
2060 std::cout <<
"m_maxBmatrixNonz = " << m_maxBmatrixNonz << std::endl;
2065 if( (*vit)->name.find(
"cost") != std::string::npos ){
2068 std::istringstream costBuffer( (*vit)->value);
2069 costBuffer >> tmpCost;
2070 arcCost.push_back( tmpCost);
2093 if( (
unsigned int)
m_numHubs != routeCapacity.size( ) )
throw ErrorClass(
"inconsistent number of HUBS");
2094 for (vit2 = routeCapacity.begin(); vit2 != routeCapacity.end(); vit2++) {
2098 std::cout <<
"ROUTE CAP = " << *vit2 << std::endl;
2101 routeCapacity.clear();
2107 if( (
unsigned int)
m_numHubs != routeMinPickup.size( ) )
throw ErrorClass(
"inconsistent number of HUBS");
2112 for (vit2 = routeMinPickup.begin(); vit2 != routeMinPickup.end(); vit2++) {
2117 routeMinPickup.clear();
2123 if( (
unsigned int)
m_numNodes != demand.size( ) )
2124 throw ErrorClass(
"inconsistent number of demand nodes");
2125 for (vit2 = demand.begin(); vit2 != demand.end(); vit2++) {
2136 for (vit4 = nodeName.begin(); vit4 != nodeName.end(); vit4++) {
2149 throw ErrorClass(
"input cost vector not consistent with number of nodes");
2150 if(arcCost.size() >= 1){
2154 for (vit3 = arcCost.begin(); vit3 != arcCost.end(); vit3++) {
2177 int &numNewRows,
int* &numNonz,
int** &colIdx,
2178 double** &
values,
double* &rowLB,
double* &rowUB) {
2193 tmpRhs =
new double[ numSepRows ];
2195 for(i = 0; i < numSepRows; i++){
2204 ErrorClass(
"number of master varibles in OSBearcatSolverXij::getCuts inconsistent");
2213 for(i = 0; i < numTheta; i++){
2231 tmpRhs[ rowKount] -= theta[ i];
2242 for(i = indexAdjust; i < numSepRows - 1; i++){
2249 int tmpKount = indexAdjust;
2250 for(
int i1 = m_numHubs; i1 <
m_numNodes; i1++){
2285 std::cout <<
" m_BmatrixIdx[ j] " <<
m_BmatrixIdx[
j] << std::endl ;
2330 for(j = m_pntBmatrix[ m_numBmatrixCon - 1] ;
2376 std::vector<int> dualIdx;
2377 std::vector<int>::iterator vit1;
2378 std::vector<int>::iterator vit2;
2383 for(k = 0; k < indexAdjust; k++){
2395 std::cout <<
"DOING SEPARATION FOR NODE " << k + m_numHubs << std::endl;
2404 for (vit1 = dualIdx.begin(); vit1 != dualIdx.end(); vit1++) {
2408 for (vit2 = dualIdx.begin(); vit2 != dualIdx.end(); vit2++) {
2415 std::cout <<
"CUT VARIABLE = " <<
m_variableNames[ index ] <<std::endl;
2424 std::cout <<
"CUT VARIABLE = " <<
m_variableNames[ index ] <<std::endl;
2443 for(i = indexAdjust; i < numSepRows - 1; i++){
2536 for(i = indexAdjust; i < numSepRows - 1; i++){
2559 int &numNewRows,
int* &numNonz,
int** &colIdx,
2560 double** &
values,
double* &rowLB,
double* &rowUB) {
2592 double* scatterValues;
2594 scatterValues =
new double[ numXijVar ];
2595 for(i = 0; i < numXijVar; i++ )scatterValues[ i] = 0;
2599 double *wcoeff = NULL;
2600 wcoeff =
new double[ numNonHubs];
2603 std::cout << std::endl << std::endl;
2604 std::cout <<
"INSIDE getCutsMultiCommod " << std::endl;
2605 std::cout << std::endl << std::endl;
2607 std::map<int, std::vector<std::pair<int,double> > > xVarMap;
2608 std::map<int, std::vector<std::pair<int,double> > >::iterator mit;
2609 std::vector<std::pair<int,double> >::iterator vit;
2611 std::map<std::pair<int, int>,
int>xVarIndexMap;
2612 std::pair<int,int> indexPair;
2613 ostringstream cutString;
2652 for(i = 0; i < numTheta; i++){
2660 mit = xVarMap.find( m_convexityRowIndex[ i]) ;
2662 if(mit != xVarMap.end() ){
2664 mit->second.push_back( std::pair<int, double>(
m_thetaIndex[ j], theta[ i]) );
2677 mit = xVarMap.find( k) ;
2681 numVar = solver->
osiSolver->getNumCols();
2682 for(i = 0; i < numVar; i++ ) solver->
osiSolver->setObjCoeff( i, 0);
2684 for(i = 0; i < numNonHubs; i++) wcoeff[ i ] = 0;
2686 if(mit != xVarMap.end() ){
2688 std::cout <<
"CONVEXITY ROW " <<
" = " << mit->first << std::endl;
2690 for(vit = mit->second.begin(); vit < mit->second.end(); vit++){
2694 ivalue = vit->first /(m_numNodes - 1);
2696 jvalue = vit->first - ivalue*(m_numNodes - 1);
2698 if( jvalue >= ivalue ){
2702 jnodenum = jvalue + 1;
2716 wcoeff[ jnodenum -
m_numHubs ] += vit->second;
2718 if( inodenum == k ){
2726 if( jnodenum > inodenum) ckijIndex = inodenum*(numNonHubs - 1) + jnodenum - 1 ;
2727 else ckijIndex = inodenum*(numNonHubs - 1) + jnodenum ;
2730 ckijIndex += numNonHubs ;
2735 ckijIndex += numNonHubs;
2737 tmpCoeff = solver->
osiSolver->getObjCoefficients()[ ckijIndex] ;
2740 tmpCoeff = tmpCoeff - vit->second;
2741 if( ckijIndex > numVar - 1)
throw ErrorClass(
"problem with ckijIndex calculation");
2743 solver->
osiSolver->setObjCoeff( ckijIndex, tmpCoeff );
2751 for(i = 0; i < numNonHubs; i++){
2754 solver->
osiSolver->setObjCoeff( i, wcoeff[ i ] );
2761 if(solver->
osiSolver->getObjValue() > .1){
2763 std::cout <<
"Separation Obj Value = " <<
2776 wVal = solver->
osiSolver->getColSolution()[ i];
2777 objVal += wVal*solver->
osiSolver->getObjCoefficients()[ i];
2784 indexPair.first =
k;
2785 indexPair.second = j2;
2787 uVal = solver->
osiSolver->getColSolution()[ kount];
2788 objVal += uVal*solver->
osiSolver->getObjCoefficients()[ kount];
2793 if (j2 == (i + m_numHubs) ){
2798 cutString << (wVal - uVal);
2809 std::cout <<
" Getting ready to call ErrorClass: kount = " << kount << std::endl;
2810 throw ErrorClass(
"index mapping problem in generating multicommodity cut");
2823 cutString << - uVal;
2836 std::cout <<
" Getting ready to call ErrorClass: kount = " << kount << std::endl;
2837 throw ErrorClass(
"index mapping problem in generating multicommodity cut");
2855 for(j2 = m_numHubs; j2 < j1; j2++){
2857 indexPair.first = j1;
2858 indexPair.second = j2;
2860 uVal = solver->
osiSolver->getColSolution()[ kount];
2861 objVal += uVal*solver->
osiSolver->getObjCoefficients()[ kount];
2865 if (j2 == (i + m_numHubs) ){
2871 cutString << (wVal - uVal) ;
2882 std::cout <<
" Getting ready to call ErrorClass: kount = " << kount << std::endl;
2883 throw ErrorClass(
"index mapping problem in generating multicommodity cut");
2896 cutString << - uVal;
2908 std::cout <<
" Getting ready to call ErrorClass: kount = " << kount << std::endl;
2909 throw ErrorClass(
"index mapping problem in generating multicommodity cut");
2922 indexPair.first = j1;
2923 indexPair.second = j2;
2925 uVal = solver->
osiSolver->getColSolution()[ kount];
2926 objVal += uVal*solver->
osiSolver->getObjCoefficients()[ kount];
2930 if (j2 == (i + m_numHubs) ){
2935 cutString << (wVal - uVal);
2946 std::cout <<
" Getting ready to call ErrorClass: kount = " << kount << std::endl;
2947 throw ErrorClass(
"index mapping problem in generating multicommodity cut");
2959 cutString << - uVal;
2969 std::cout <<
" Getting ready to call ErrorClass: kount = " << kount << std::endl;
2970 throw ErrorClass(
"index mapping problem in generating multicommodity cut");
2980 cutString << std::endl;
3009 ErrorClass(
"Inconsistent Number of theta variables in multicommondity cut separation problem" );
3049 scatterValues[ m_BmatrixIdx[
j] ] = 0;
3070 std::cout << std::endl << std::endl;
3074 for(i = 0; i < numVar; i++ ) solver->
osiSolver->setObjCoeff( i, 0 );
3082 delete[] scatterValues;
3083 scatterValues = NULL;
3091 for(i = 0; i < numNewRows; i++){
3111 if(scatterValues != NULL) {
3112 delete[] scatterValues;
3113 scatterValues = NULL;
3125 int &numNewRows,
int* &numNonz,
int** &colIdx,
3126 double** &
values,
double* &rowLB,
double* &rowUB) {
3141 tmpRhs =
new double[ numSepRows ];
3143 for(i = 0; i < numSepRows; i++){
3151 for(i = 0; i < numX; i++){
3161 tmpRhs[ rowKount] -= x[ i];
3168 for(i = indexAdjust; i < numSepRows - 1; i++){
3176 int tmpKount = indexAdjust;
3177 for(
int i1 = m_numHubs; i1 <
m_numNodes; i1++){
3192 m_newRowColumnValue[ 0][ 1] = 1;
3226 std::vector<int> dualIdx;
3227 std::vector<int>::iterator vit1;
3228 std::vector<int>::iterator vit2;
3233 for(k = 0; k < indexAdjust; k++){
3234 std::cout << std::endl << std::endl;
3243 std::cout <<
"DOING SEPARATION FOR NODE " << k + m_numHubs << std::endl;
3254 for (vit1 = dualIdx.begin(); vit1 != dualIdx.end(); vit1++) {
3258 for (vit2 = dualIdx.begin(); vit2 != dualIdx.end(); vit2++) {
3265 std::cout <<
"CUT VARIABLE = " <<
m_variableNames[ index] <<std::endl;
3274 std::cout <<
"CUT VARIABLE = " <<
m_variableNames[ index] <<std::endl;
3290 for(i = indexAdjust; i < numSepRows - 1; i++){
3321 for(i = indexAdjust; i < numSepRows - 1; i++){
3363 for(j = 0; j < i; j++){
3450 for(j = 0; j < i; j++){
3499 for(i = 0; i <
j; i++){
3501 m_Amatrix[ numNonz++] = i*(m_numNodes - 1) + j - 1 ;
3507 m_Amatrix[ numNonz++] = i*(m_numNodes - 1) + j ;
3530 std::vector<double> &m_zRootLPx_vals,
3531 int numNodes,
int numColsGen, std::string message){
3533 std::cout << std::endl;
3534 std::cout <<
" PAU HANA TIME! " << std::endl;
3538 std::vector<int>::iterator vit;
3563 for(vit = m_zOptIndexes.begin() ; vit != m_zOptIndexes.end(); vit++){
3566 std::cout <<
"x variables for column " << i <<
" CONVEXITY ROW = "<<
m_convexityRowIndex[ i] << std::endl;
3582 if( jvalue >= ivalue ){
3586 routeDemand +=
m_demand[ jvalue + 1];
3597 std::cout <<
"route demand = " << routeDemand << std::endl << std::endl;
3598 std::cout <<
"distance for this route " <<
m_thetaCost[ i ] / routeDemand << std::endl;
3605 std::cout << std::endl << std::endl;
3606 std::cout << message << std::endl;
3607 std::cout <<
"LINEAR PROGRAMMING RELAXATION VALUE = " <<
m_rootLPValue << std::endl;
3608 std::cout <<
"NONLINEAR RELAXATION VALUE = " <<
calcNonlinearRelax( m_zRootLPx_vals) << std::endl;
3609 std::cout <<
"LOWER BOUND VALUE = " <<
m_bestLPValue << std::endl;
3610 std::cout <<
"FINAL BEST IP SOLUTION VALUE = " <<
m_bestIPValue << std::endl;
3611 std::cout <<
"NUMBER OF COLUMNS IN FINAL MASTER = " <<
m_numThetaVar << std::endl;
3614 std::cout <<
"NUMBER OF GENERATED COLUMNS = " << numColsGen << std::endl;
3615 std::cout <<
"NUMBER OF GENERATED CUTS = " <<
m_numBmatrixCon << std::endl;
3616 std::cout <<
"NUMBER OF NODES = " << numNodes << std::endl;
3617 std::cout <<
" PAU!!!" << std::endl;
3619 std::cout << std::endl << std::endl;
3621 std::cout << std::endl << std::endl;
3633 std::vector<double>::iterator dvit;
3634 std::vector<double>::iterator dvit2;
3640 double *hubDemand = NULL;
3641 double *hubCost = NULL;
3645 double objVal = 0.0;
3646 double objValAux = 0.0;
3648 std::map<int, std::vector<double> > extPointDemands;
3649 std::map<int, std::vector<double> > extPointCosts;
3650 std::map<int, std::vector<double> > extPointValues;
3652 std::map<int, std::vector<double> >::iterator mit;
3664 for (dvit = m_zRootLPx_vals.begin(); dvit < m_zRootLPx_vals.end(); dvit++ ){
3683 jvalue = m_thetaIndex[
j] - ivalue*(
m_numNodes - 1);
3685 if( jvalue >= ivalue ){
3689 hubDemand[
m_hubPoint[ m_convexityRowIndex[ index] ] ] +=
m_demand[ jvalue + 1]*( *dvit);
3690 tmpDemand +=
m_demand[ jvalue + 1];
3698 hubDemand[
m_hubPoint[ m_convexityRowIndex[ index] ] ] +=
m_demand[ jvalue ]*( *dvit);
3726 mapSize = extPointDemands[ m_hubPoint[ i] ].size();
3730 for (j = 0; j < mapSize; j++){
3732 tmpDemand += extPointDemands[ m_hubPoint[ i] ][
j]*extPointValues[ m_hubPoint[ i] ][
j];
3733 tmpCost += extPointCosts[ m_hubPoint[ i] ][
j]*extPointValues[ m_hubPoint[ i] ][
j];
3738 extPointCosts[ m_hubPoint[ i] ][
j]*extPointDemands[ m_hubPoint[ i] ][
j]*extPointValues[ m_hubPoint[ i] ][
j];
3748 std::cout <<
"AUXILIARY VALUE COST = " << objValAux << std::endl;
3794 double *
values =
new double[ 2*numYvar + 2*numVvar];
3795 int *indexes =
new int[ 2*numYvar + 2*numVvar];
3796 int *starts =
new int[ numYvar + numVvar + 1];
3805 std::string separationVarName;
3806 std::string separationConName;
3840 separationConName +=
")";
3855 std::cout <<
"NUMBER OF VARIABLES SET = " << numYvar + numVvar << std::endl;
3857 for(i = 0; i < numVvar; i++){
3863 values[ kountNonz ] = -1.0;
3864 indexes[ kountNonz ] = i;
3867 values[ kountNonz ] = 1.0;
3868 indexes[ kountNonz ] = rowKounter - 1;
3873 starts[ startsIdx++ ] = kountNonz;
3885 for(i1 = 0; i1 < m_numNodes -
m_numHubs; i1++){
3890 for(j1 = i1 + 1; j1 < m_numNodes -
m_numHubs; j1++){
3897 separationVarName +=
")";
3905 values[ kountNonz ] = 1.0;
3906 indexes[ kountNonz ] = i1;
3909 values[ kountNonz ] = -1.0;
3910 indexes[ kountNonz ] = kountCon ;
3913 starts[ startsIdx++ ] = kountNonz;
3920 separationVarName +=
")";
3923 values[ kountNonz ] = 1.0;
3924 indexes[ kountNonz ] = j1;
3930 values[ kountNonz ] = -1.0;
3931 indexes[ kountNonz ] = kountCon ;
3934 starts[ startsIdx++ ] = kountNonz;
3944 std::cout <<
"NUMBER OF VARIABLES ADDED = " << kount << std::endl;
3951 for(i = 0; i < numVvar; i++){
3954 objcoeff->
values[ i] = 1.0;
3966 values, 0, kountNonz - 1, indexes, 0, kountNonz - 1, starts, 0, startsIdx);
3979 CoinPackedMatrix* matrix;
3980 bool columnMajor =
true;
3982 matrix =
new CoinPackedMatrix(
3992 ClpNetworkMatrix network( *matrix);
4028 double from1Distance;
4029 double from0Distance;
4036 xvalues =
new double[ numVar];
4037 for(i = 0; i < numVar; i++){
4065 for( j = 0; j < i; j++){
4068 from1Distance = 1 - xvalues[ i*(
m_numNodes - 1) + j ];
4069 from0Distance = xvalues[ i*(
m_numNodes - 1) + j ];
4070 fraction = std::max(from1Distance, from0Distance);
4072 if(fraction < minFraction){
4074 minFraction = fraction;
4084 from1Distance = 1 - xvalues[ i*(m_numNodes - 1) + j - 1 ];
4085 from0Distance = xvalues[ i*(m_numNodes - 1) + j - 1 ];
4086 fraction = std::max(from1Distance, from0Distance);
4088 if(fraction < minFraction) {
4090 minFraction = fraction;
4091 varIdx = i*(m_numNodes - 1) + j - 1;
4105 for( j = 0; j < i; j++){
4108 from1Distance = 1 - xvalues[ i*(m_numNodes - 1) + j ];
4109 from0Distance = xvalues[ i*(m_numNodes - 1) + j ];
4110 fraction = std::max(from1Distance, from0Distance);
4112 if(fraction < minFraction) {
4114 minFraction = fraction;
4115 varIdx = i*(m_numNodes - 1) + j ;
4124 from1Distance = 1 - xvalues[ i*(m_numNodes - 1) + j - 1 ];
4125 from0Distance = xvalues[ i*(m_numNodes - 1) + j - 1 ];
4126 fraction = std::max(from1Distance, from0Distance);
4128 if(fraction < minFraction) {
4130 minFraction = fraction;
4131 varIdx = i*(m_numNodes - 1) + j - 1;
4162 const int numThetaVar) {
4169 double from1Distance;
4170 double from0Distance;
4177 xvalues =
new double[ numVar];
4178 for(i = 0; i < numVar; i++){
4185 for(i = 0; i < numThetaVar; i++){
4207 for( j = 0; j < i; j++){
4210 from1Distance = 1 - xvalues[ i*(
m_numNodes - 1) + j ];
4211 from0Distance = xvalues[ i*(
m_numNodes - 1) + j ];
4212 fraction = std::max(from1Distance, from0Distance);
4214 if(fraction < minFraction){
4216 minFraction = fraction;
4226 from1Distance = 1 - xvalues[ i*(m_numNodes - 1) + j - 1 ];
4227 from0Distance = xvalues[ i*(m_numNodes - 1) + j - 1 ];
4228 fraction = std::max(from1Distance, from0Distance);
4230 if(fraction < minFraction) {
4232 minFraction = fraction;
4233 varIdx = i*(m_numNodes - 1) + j - 1;
4243 std::cout <<
"MIN FRACTION = " << minFraction << std::endl;
4251 for( j = 0; j < i; j++){
4254 from1Distance = 1 - xvalues[ i*(m_numNodes - 1) + j ];
4255 from0Distance = xvalues[ i*(m_numNodes - 1) + j ];
4256 fraction = std::max(from1Distance, from0Distance);
4258 if(fraction < minFraction) {
4260 minFraction = fraction;
4261 varIdx = i*(m_numNodes - 1) + j ;
4270 from1Distance = 1 - xvalues[ i*(m_numNodes - 1) + j - 1 ];
4271 from0Distance = xvalues[ i*(m_numNodes - 1) + j - 1 ];
4272 fraction = std::max(from1Distance, from0Distance);
4274 if(fraction < minFraction) {
4276 minFraction = fraction;
4277 varIdx = i*(m_numNodes - 1) + j - 1;
4307 const std::map<int, int> &varConMap,
int &varIdx,
int &numNonz,
4308 int* &indexes,
double* &
values) {
4324 std::cout <<
"VARIABLE INDEX = " << varIdx << std::endl;
4325 std::cout <<
"Branching on Variable: " <<
m_variableNames[ varIdx] << std::endl;
4330 if( varConMap.find( varIdx) == varConMap.end() ){
4389 const int numThetaVar,
const std::map<int, int> &varConMap,
4390 int &varIdx,
int &numNonz,
int* &indexes,
double* &
values) {
4406 std::cout <<
"Branching on Variable: " <<
m_variableNames[ varIdx] << std::endl;
4411 if( varConMap.find( varIdx) == varConMap.end() ){
4477 double *routeDemand;
4480 std::map<int, std::vector<int> > routeMap;
4481 std::vector<int>::iterator vit;
4492 routeDemand[
k] = 0;
4493 for(vit = routeMap[k].begin(); vit!=routeMap[
k].end(); ++vit){
4507 delete[] routeDemand;
4517 if(routeDemand == NULL){
4519 delete[] routeDemand;
4539 std::map<int, int>::iterator mit;
4541 int numVars = inVars.size();
4549 std::vector<double> valuesVec;
4552 std::vector<int> indexesVec;
4553 int *indexes = NULL ;
4555 int *starts =
new int[ numVars + 1 + numVarArt];
4569 for(mit = inVars.begin(); mit != inVars.end(); mit++){
4575 thetaPntTmp =
new int[ numVars + 1];
4576 thetaIndexTmp =
new int[ numNonz];
4580 for(mit = inVars.begin(); mit != inVars.end(); mit++){
4592 thetaPntTmp[ kount] = 0;
4594 for(mit = inVars.begin(); mit != inVars.end(); mit++){
4608 thetaPntTmp[ kount] = numNonz;
4614 inVars[ mit->first] = numVarArt + kount - 1 ;
4630 for(i = 0; i < numVarArt; i++){
4640 for(mit = inVars.begin(); mit != inVars.end(); mit++){
4643 intVarSet.insert ( std::pair<int,double>(mit->second, 1.0) );
4652 for(j = thetaPntTmp[ mit->second - numVarArt]; j < thetaPntTmp[ mit->second - numVarArt + 1 ]; j++){
4672 si->writeLp(
"gailTest" );
4680 starts[ startsIdx++] = numNonz;
4682 for(i = 0; i < numVarArt; i++){
4684 starts[ startsIdx++] = numNonz;
4685 valuesVec.push_back( 1.0);
4686 indexesVec.push_back( i);
4696 for(mit = inVars.begin(); mit != inVars.end(); mit++){
4699 valuesVec.push_back( 1.0);
4715 for(i = 0; i < numAmatrixRows; i++){
4734 valuesVec.push_back( rowCount);
4735 indexesVec.push_back( i);
4764 valuesVec.push_back( rowCount);
4780 starts[ startsIdx++] = numNonz;
4786 values =
new double[ numNonz];
4787 indexes =
new int[ numNonz];
4789 if( (
unsigned int)numNonz != valuesVec.size() )
throw ErrorClass(
"dimension problem in reset");
4790 if( (
unsigned int)numNonz != indexesVec.size() )
throw ErrorClass(
"dimension problem in reset");
4792 for(i = 0; i < numNonz; i++){
4794 values[ i] = valuesVec[i];
4795 indexes[ i] = indexesVec[i];
4834 for(i = 0; i < numVarArt; i++){
4836 objcoeff->
indexes[ varNumber ] = varNumber ;
4850 for(mit = inVars.begin(); mit != inVars.end(); mit++){
4852 objcoeff->
indexes[ varNumber ] = varNumber ;
4854 objcoeff->
values[ varNumber ] = si->getObjCoefficients()[ mit->first] ;
4856 m_thetaCost[ varNumber] = si->getObjCoefficients()[ mit->first];
4877 for(i = m_numNodes; i < m_numBmatrixCon +
m_numNodes; i++){
4880 si->getRowLower()[ i], si->getRowUpper()[ i], 0);
4892 values, 0, numNonz - 1, indexes, 0, numNonz - 1, starts, 0, startsIdx);
4898 delete[] tmpConvexity;
4899 tmpConvexity = NULL;
4900 delete[] thetaPntTmp;
4902 delete[] thetaIndexTmp;
4903 thetaIndexTmp = NULL;
4911 CoinSolver* solver, std::vector<int> zk,
double* xVar){
4916 numVar = numNodes*numNodes - numNodes;
4920 std::vector<int>::iterator vit;
4921 std::map<std::pair<int, int>,
int > cutMap;
4922 std::map<std::pair<int, int>,
int >::iterator mit;
4923 std::vector<IndexValuePair*> primalValPair;
4929 for(i = 0; i < numVar; i++) xVar[ i] = 0;
4932 int* numRowNonz = NULL;
4933 int** colIdx = NULL;
4934 double** rowValues = NULL ;
4940 OsiSolverInterface *si = solver->
osiSolver;
4944 si->setRowUpper(hubIndex, 1.0);
4945 si->setRowUpper(hubIndex + numNodes, 1.0);
4946 si->setRowLower(hubIndex, 1.0);
4947 si->setRowLower(hubIndex + numNodes, 1.0);
4956 for(i = 0; i < kount ; i++){
4959 si->setRowUpper(zk[ i], 1.0);
4960 si->setRowUpper(zk[ i] + numNodes, 1.0);
4961 si->setRowLower(zk[ i], 1.0);
4962 si->setRowLower(zk[ i] + numNodes, 1.0);
4969 si->setColUpper(idx1*(numNodes -1) + idx2, 1.0);
4974 si->setColUpper(idx1*(numNodes -1) + idx2 - 1, 1.0);
4985 si->setColUpper(idx1*(numNodes -1) + idx2, 1.0);
4991 si->setColUpper(idx1*(numNodes -1) + idx2 - 1, 1.0);
4996 for(j = i + 1; j < kount; j++){
5004 si->setColUpper(idx1*(numNodes -1) + idx2, 1.0);
5010 si->setColUpper(idx1*(numNodes -1) + idx2 - 1, 1.0);
5020 si->setColUpper(idx1*(numNodes -1) + idx2, 1.0);
5025 si->setColUpper(idx1*(numNodes -1) + idx2 - 1, 1.0);
5043 while(isCutAdded ==
true){
5047 for(i = 0; i < numVar; i++) xVar[ primalValPair[ i]->idx ] = primalValPair[ i]->value;
5050 getCutsX(xVar, numVar, numNewRows, numRowNonz,
5051 colIdx,rowValues, rowLB, rowUB);
5053 if(numNewRows >= 1){
5055 std::cout <<
"WE HAVE A CUT " << std::endl;
5056 std::cout <<
"EXPRESS CUT IN X(I, J) SPACE" << std::endl;
5059 for(i = 0; i < numNewRows; i++){
5061 std::cout <<
"CUT UPPER BOUND = " << rowUB[ i] << std::endl;
5062 si->addRow(numRowNonz[ i], colIdx[ i], rowValues[ i], rowLB[ i], rowUB[ i] ) ;
5065 std::cout <<
"A CUT WAS ADDED, CALL SOLVE AGAIN" << std::endl;
5070 std::cout <<
"Optimal Objective Value = " << solver->
osresult->
getObjValue(0, 0) << std::endl;
5085 std::cout <<
"Objective Function Value = " << objValue << std::endl;
5088 for(i = 0; i < numVar; i++) si->setColUpper(i, 0);
5089 for(i = 0; i < 2*numNodes; i++) si->setRowUpper(i, 0);
5090 for(i = 0; i < 2*numNodes; i++) si->setRowLower(i, 0);
5097 std::cout << std::endl << std::endl << std::endl;
5115 numVar = numNodes*numNodes - numNodes;
5119 std::vector<int>::iterator vit;
5122 std::map<std::pair<int, int>,
int > cutMap;
5123 std::map<std::pair<int, int>,
int >::iterator mit;
5128 rhsVec =
new double[ 2*numNodes];
5130 for(i = 0; i < 2*numNodes; i++){
5141 std::pair <int,int> pairIJ;
5142 std::pair <int,int> pairJI;
5144 for(i = 0; i < numNodes - 1; i++){
5147 for(j = i + 1; j < numNodes; j++){
5150 pairIJ = std::make_pair(i, j);
5151 pairJI = std::make_pair(j, i);
5153 cutMap[pairIJ ] = 2*numNodes + numCuts;
5154 cutMap[pairJI ] = 2*numNodes + numCuts;
5169 for(i = 0; i < numVar; i++){
5180 for(i = 0; i < numVar; i++){
5183 objcoeff->
values[ i] = cost[ i];
5187 osinstance->
addObjective(-1,
"minimizeDistance",
"min", 0.0, 1.0, objcoeff);
5194 for(i = 0; i < numNodes; i++){
5200 for(i = numNodes; i < 2*numNodes; i++){
5208 for(i = 0; i < numCuts; i++){
5216 numNonz = numVar*numVar - numVar + 2*numCuts;
5219 double *
values =
new double[ numNonz];
5220 int *rowIndexes =
new int[ numNonz];
5221 int *starts =
new int[ numVar + 1];
5226 starts[ kount++] = 0;
5227 for(i = 0; i < numNodes; i++){
5229 for(j = 0; j < i; j++){
5232 rowIndexes[ numNonz] =
j;
5233 values[ numNonz++] = 1.0;
5235 rowIndexes[ numNonz] = numNodes + i;
5236 values[ numNonz++] = 1.0;
5239 pairIJ = std::make_pair(i, j);
5240 mit = cutMap.find( pairIJ);
5241 if(mit != cutMap.end() ){
5243 rowIndexes[ numNonz] = mit->second;
5244 values[ numNonz++] = 1.0;
5248 starts[ kount++] = numNonz;
5253 for(j = i+1; j < numNodes; j++){
5256 rowIndexes[ numNonz] =
j;
5257 values[ numNonz++] = 1.0;
5259 rowIndexes[ numNonz] = numNodes + i;
5260 values[ numNonz++] = 1.0;
5263 pairIJ = std::make_pair(i, j);
5264 mit = cutMap.find( pairIJ);
5265 if(mit != cutMap.end() ){
5267 rowIndexes[ numNonz] = mit->second;
5268 values[ numNonz++] = 1.0;
5272 starts[ kount++] = numNonz;
5280 rowIndexes, 0, numNonz - 1, starts, 0, numVar);
5301 std::cout << std::endl << std::endl << std::endl;
5320 double *routeCost = NULL;
5321 int *routeDemand = NULL;
5322 double *xVar = NULL;
5324 double routeCostInf;
5327 double feasMult = 10000;
5331 xVar =
new double[ numXVar];
5335 std::map<int, std::vector<int> > routeMap;
5336 std::vector<int> tmpVec;
5337 std::vector<int>::iterator vit;
5338 std::vector<int>::iterator vit2;
5345 bool foundLocalImprovement;
5354 routeDemand[
k] = 0;
5355 for(vit = routeMap[k].begin(); vit!=routeMap[
k].end(); ++vit){
5357 std::cout <<
"node i = " << *vit <<
" demand " <<
m_demand[ *vit] << std::endl;
5364 routeMap[k], xVar)*routeDemand[
k];
5367 std::cout <<
"rout = " << k <<
" cost " << routeCost[
k] << std::endl;
5368 totalCost += routeCost[
k];
5370 std::cout <<
"rout demand " << routeDemand[
k] <<
" route capacity = " <<
m_routeCapacity[
k] << std::endl;
5371 routeCost[
k] = routeCostInf;
5372 totalCost += routeCost[
k];
5380 foundMoBetta =
true;
5384 double tmpCostkPrime;
5386 double optCostkPrime;
5389 std::vector<int>::iterator vitIdx;
5391 while(foundMoBetta ==
true){
5392 foundMoBetta =
false;
5396 foundLocalImprovement =
false;
5398 for(kprime = 0; kprime <
m_numHubs; kprime++){
5400 if(kprime != k && routeCost[ kprime] < routeCostInf){
5404 optCostk = routeCostInf;
5405 optCostkPrime = routeCostInf;
5407 for(vit = routeMap[k].begin(); vit!=routeMap[
k].end(); ++vit){
5409 foundLocalImprovement =
false;
5414 tmpCostk = routeCostInf;
5415 tmpCostkPrime = routeCostInf;
5420 routeMap[ kprime].push_back( *vit);
5423 routeMap[kprime], xVar)*(routeDemand[ kprime] +
m_demand[ *vit] );
5426 routeMap[ kprime].pop_back( );
5430 if(routeCost[k] == routeCostInf ){
5438 for(vit2 = routeMap[k].begin(); vit2 != routeMap[
k].end(); vit2++){
5440 if(vit != vit2) tmpVec.push_back( *vit2);
5445 tmpVec, xVar)*(routeDemand[
k] -
m_demand[ *vit] );
5451 tmpVal = std::max(*vit, routeDemand[ k] -
m_demand[ *vit])*feasMult
5452 + ( routeCost[kprime] - tmpCostkPrime);
5454 if( tmpVal > improvement) {
5455 foundLocalImprovement =
true;
5456 improvement = tmpVal;
5459 optCostk = tmpCostk;
5460 optCostkPrime = tmpCostkPrime;
5470 for(vit2 = routeMap[k].begin(); vit2 != routeMap[
k].end(); vit2++){
5472 if(vit != vit2) tmpVec.push_back( *vit2);
5477 tmpVec, xVar)*(routeDemand[
k] -
m_demand[ *vit] );
5481 if( ( (routeCost[k] + routeCost[kprime]) -
5482 ( tmpCostkPrime + tmpCostk ) ) > improvement ) {
5484 improvement = (routeCost[
k] + routeCost[kprime]) -
5485 ( tmpCostkPrime + tmpCostk );
5487 foundLocalImprovement =
true;
5490 optCostk = tmpCostk;
5491 optCostkPrime = tmpCostkPrime;
5499 if(foundLocalImprovement ==
true)
break;
5505 if( foundLocalImprovement ==
true) {
5508 std::cout <<
"index = " << tmpIdx << std::endl;
5510 routeMap[ kprime].push_back( tmpIdx);
5512 routeDemand[ kprime] +=
m_demand[ tmpIdx];
5514 routeCost[ kprime] = optCostkPrime;
5521 std::cout <<
"tmpIdx = " << tmpIdx << std::endl;
5522 std::cout <<
"vitIdx = " << *vitIdx << std::endl;
5523 routeMap[
k].erase( vitIdx);
5527 routeCost[
k] = optCostk;
5534 foundMoBetta =
true;
5549 std::cout << std::endl << std::endl;
5551 std::cout <<
"ROUTE " << k <<
" Total Demand = " << routeDemand[
k] << std::endl;
5552 std::cout <<
"ROUTE " << k <<
" Total Cost = " << routeCost[
k] << std::endl;
5553 std::cout <<
"ROUTE " << k <<
" Nodes " << std::endl;
5558 totalCost += routeCost[
k];
5561 std::cout <<
"Total Cost = " << totalCost << std::endl;
5569 delete[] routeDemand;
5576 if( totalCost >= routeCostInf )
return false;
5582 std::cout << std::endl << std::endl << std::endl;
5584 if(routeCost != NULL){
5589 if(routeDemand != NULL){
5590 delete[] routeDemand;
5620 numVar = numNonHubs;
5622 numVar += numNonHubs;
5624 numVar += numNonHubs*numNonHubs - numNonHubs;
5631 numCon = numNonHubs + (numNonHubs*numNonHubs - numNonHubs) + 1;
5638 osinstance->setInstanceSource(
"generated from OSBearcatSoleverXij");
5639 osinstance->setInstanceDescription(
"Instance for finding a multicommodity cut");
5640 osinstance->setVariableNumber( numVar);
5672 for(j = m_numHubs; j < i; j++){
5702 osinstance->setObjectiveNumber( 1);
5708 for(i = 0; i < numVar; i++){
5711 objcoeff->
values[ i] = 0;
5715 osinstance->addObjective(-1,
"cutViolation",
"max", 0.0, 1.0, objcoeff);
5719 osinstance->setConstraintNumber( numCon );
5734 for(j = m_numHubs; j < i; j++){
5757 upperBound = numVar - numNonHubs ;
5759 osinstance->addConstraint(numCon++,
"boundConstraint", -
OSDBL_MAX, upperBound, 0);
5762 numCon = numNonHubs + (numNonHubs*numNonHubs - numNonHubs) + 1;
5763 numNonz = 2*numNonHubs;
5764 numNonz += 3*(numNonHubs*numNonHubs - numNonHubs);
5765 numNonz += (numNonHubs*numNonHubs - numNonHubs) + numNonHubs;
5768 double *
values =
new double[ numNonz];
5769 int *columnIndexes =
new int[ numNonz];
5771 int *starts =
new int[ numCon + 1];
5776 starts[ kount++] = 0;
5783 uijKount = numNonHubs;
5789 columnIndexes[ numNonz] = j -
m_numHubs ;
5790 values[ numNonz++] = 1.0;
5793 columnIndexes[ numNonz] = uijKount ;
5794 values[ numNonz++] = -1.0;
5796 starts[ kount++] = numNonz;
5804 for(j = m_numHubs; j < i; j++){
5808 columnIndexes[ numNonz] = i -
m_numHubs ;
5809 values[ numNonz++] = -1.0;
5812 columnIndexes[ numNonz] = j -
m_numHubs ;
5813 values[ numNonz++] = 1.0;
5816 columnIndexes[ numNonz] = uijKount ;
5817 values[ numNonz++] = -1.0;
5820 starts[ kount++] = numNonz;
5830 columnIndexes[ numNonz] = i -
m_numHubs ;
5831 values[ numNonz++] = -1.0;
5834 columnIndexes[ numNonz] = j -
m_numHubs ;
5835 values[ numNonz++] = 1.0;
5838 columnIndexes[ numNonz] = uijKount ;
5839 values[ numNonz++] = -1.0;
5842 starts[ kount++] = numNonz;
5851 for(i = numNonHubs; i < numVar; i++ ){
5854 columnIndexes[ numNonz] = i ;
5855 values[ numNonz++] = 1.0;
5859 starts[ kount++] = numNonz;
5860 osinstance->setLinearConstraintCoefficients(numNonz,
false, values, 0, numNonz - 1,
5861 columnIndexes, 0, numNonz - 1, starts, 0, numVar);
5879 if( objcoeff != NULL ){
5900 numVar = m_numHubs*numNonHubs;
5908 std::pair<int,int> indexPair1;
5909 std::pair<int,int> indexPair2;
5911 std::map<int, std::vector<int> > routeMap;
5945 indexPair1.first =
k;
5946 indexPair2.second =
k;
5950 indexPair1.second = i;
5951 indexPair2.first = i;
5952 objcoeff->
indexes[ kount] = kount;
5956 throw ErrorClass(
"Index problem in generalized assignment problem to find feasible solution");
5966 osinstance->
addObjective(-1,
"feasibililtyObj",
"min", 0.0, 1.0, objcoeff);
5998 double *
values =
new double[ numNonz];
5999 int *rowIndexes =
new int[ numNonz];
6000 int *starts =
new int[ numVar + 1];
6005 starts[ kount++] = 0;
6017 rowIndexes[ numNonz] =
k ;
6020 rowIndexes[ numNonz] = i ;
6021 values[ numNonz++] = 1.0;
6023 starts[ kount++] = numNonz;
6030 rowIndexes, 0, numNonz - 1, starts, 0, numVar);
6046 std::string solStatus;
6047 std::vector<IndexValuePair*> primalValPair;
6053 if( solStatus.find(
"ptimal") != std::string::npos ){
6056 std::cout <<
"OPTIMAL SOLUTION VALUE " << optSolValue << std::endl;
6058 throw ErrorClass(
"There is no feasible solution to this problem!");
6062 vecSize = primalValPair.size();
6068 indexPair1.first =
k;
6069 std::cout << std::endl << std::endl;
6072 indexPair1.second = i;
6076 <<
" value = " << primalValPair[ kount ]->value << std::endl;
6078 routeMap[
k].push_back( i);
6094 if( objcoeff != NULL ){
6110 std::pair<int,int> indexPair;
6115 for(j = 0; j < i; j++){
6117 indexPair.first = i;
6118 indexPair.second =
j;
6125 indexPair.first = i;
6126 indexPair.second =
j;
6149 for(k1 = 0; k1 < m_numHubs - 1; k1++){
6154 if( tmpCap[ k2 ] < tmpCap[ k1 ] ){
6157 tmpVal = tmpCap[ k1 ];
6158 tmpCap[ k1 ] = tmpCap[ k2 ];
6159 tmpCap[ k2 ] = tmpVal;
6170 for(k1 = 0; k1 <
m_numHubs; k1++) std::cout <<
"m_hubPoint = " <<
m_hubPoint[ k1] << std::endl;
6171 for(k1 = 0; k1 <
m_numHubs; k1++) std::cout <<
"tmp Cap = " << tmpCap[ k1] << std::endl;
double * getConstraintLowerBounds()
Get constraint lower bounds.
double * getVariableLowerBounds()
Get variable lower bounds.
double * getConstraintUpperBounds()
Get constraint upper bounds.
CoinSolver * getTSP(int numNodes, double *cost)
call this method to get a TSP instance
OSBearcatSolverXij()
Default Constructor.
virtual void initializeDataStructures()
allocate memory and initialize arrays
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.
double ** m_rc
the reduced cost vector for each k, we asssume order is (l, i, j)
bool bConstraintsModified
bConstraintsModified is true if the constraints data has been modified.
double getObjValue(int solIdx, int objIdx)
int * m_demand
m_demand is the vector of node demands
std::string getSolutionStatusType(int solIdx)
Get the [i]th optimization solution status type, where i equals the given solution index...
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...
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.
std::string m_initOSiLFile
int m_maxThetaNonz
m_maxMasterNonz is the maximumn number of nonzero elements we allow in the transformation matrix betw...
std::string errormsg
errormsg is the error that is causing the exception to be thrown
int m_minDemand
m_minDemand is the value of the minimum demand node – it is not the minimum demand that must be carri...
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.
virtual void pauHana(std::vector< int > &m_zOptIndexes, std::vector< double > &m_zRootLPx_vals, int numNodes, int numColsGen, std::string message)
std::vector< SolverOption * > getSolverOptions(std::string solver_name)
Get the options associated with a given solver.
virtual OSInstance * getInitialRestrictedMaster()
OSInstance* OSBearcatSolverXij::getInitialRestrictedMaster( ){.
std::vector< IndexValuePair * > getOptimalPrimalVariableValues(int solIdx)
Get one solution of optimal primal variable values.
int * m_routeCapacity
the route capacity – bus seating limit this can vary with the route/hub
void getVariableIndexMap()
this method will populate: std::map<std::pair<int, int>,int>m_xVarIndexMap this gives us ...
OSInstance * m_osinstanceMaster
void getFeasibleSolution()
call this method to get generate an instance of the generalized assignment problem and find a feasibl...
int * m_convexityRowIndex
m_convexityRowIndex holds the index of the convexity row that the theta columns are in...
CoinSolver * getMultiCommodInstance(int hubIndex)
call this method to get an instance that is used to generate a multicommodity cut ...
void getCutsMultiCommod(const double *thetaVar, const int numThetaVar, int &numNewRows, int *&numNonz, int **&colIdx, double **&values, double *&rowLB, double *&rowUB)
This is the routine that generates the multi-item cuts.
int * m_hubPoint
m_hubPoint[ k] points to the the k'th hub that we use in getOptL
OSResult * osresult
osresult holds the solution or result of the model in-memory as an OSResult object ...
double getOptimalObjValue(int objIdx, int solIdx)
Get one solution's optimal objective value.
int * m_upperBoundL
largest possible L-value on a route – this will be the minimum of m_routeCapacity and total demand ...
ClpSimplex * m_separationClpModel
int m_numBmatrixCon
m_numBmatrixCon is the number of constraints in B - 1, we have the -1 because: m_pntBmatrix[ k] point...
virtual void buildSolverInstance()
The implementation of the corresponding virtual function.
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...
int * indexes
indexes holds an integer array of rowIdx (or colIdx) elements in coefMatrix (AMatrix).
double ** getDenseObjectiveCoefficients()
getDenseObjectiveCoefficients.
int * m_routeMinPickup
the minimum number of students that we pickup on a route this can vary with the route/hub ...
int * m_separationIndexMap
m_separationIndexMap maps the variable index into the appropriate row in the separation problem for t...
OSInstance * getSeparationInstance()
double calcNonlinearRelax(std::vector< double > &m_zRootLPx_vals)
calculate the nonlinear relaxation value for an LP solution
bool setConstraintNumber(int number)
set the number of constraints.
bool bDeleteArrays
bDeleteArrays is true if we delete the arrays in garbage collection set to true by default ...
std::map< std::pair< int, int >, int > m_xVarIndexMap
m_xVarIndexMap takes a variable indexed by (i,j) and returns the index of the variable in one dimensi...
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...
std::string makeStringFromInt(std::string theString, int theInt)
double ** m_newRowColumnValue
SparseMatrix * getLinearConstraintCoefficientsInRowMajor()
Get linear constraint coefficients in row major.
virtual void resetMaster(std::map< int, int > &inVars, OsiSolverInterface *si)
INPUT:
bool setObjectiveNumber(int number)
set the number of objectives.
OSOption * osoption
osoption holds the solver options in-memory as an OSOption object
int * m_BmatrixRowIndex
m_BmatrixRowIndex holds the index of the convexity row that the constraint corresponds to...
int getBranchingVar(const double *theta, const int numThetaVar)
RETURN VALUES: return the integer index of a fractional x_{ij} variable.
void getOptions(OSOption *osoption)
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
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...
double * m_cost
the distance/cost vectors
OSInstance * osinstance
osinstance holds the problem instance in-memory as an OSInstance object
bool OneOPT()
try and find a feasible solution, return false if solution not feasible
std::vector< CoinSolver * > m_multCommodCutSolvers
m_multCommodCutSolvers is a vector of solvers, one solver for each hub, used to find multicommodity f...
void createVariableNames()
void permuteHubs()
this method will calculate a permuation of the hubs so that they are in ascending order...
int m_multiCommodCutLimit
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...
int getConstraintNumber()
Get number of constraints.
std::string sSolverName
sSolverName is the name of the Coin solver used, e.g.
bool setInstanceSource(std::string source)
set the instance source.
bool setInstanceDescription(std::string description)
set the instance description.
~OSBearcatSolverXij()
Default Destructor.
int m_upperBoundLMax
largest possible L-value over all routes
double getRouteDistance(int numNodes, int hubIndex, CoinSolver *solver, std::vector< int > zk, double *xVar)
call this method to get a minimum TSP tour for a given assignment of nodes to routes INPUT: int numNo...
double qrouteCost(const int &k, const int &l, const double *c, int *kountVar)
kipp – document
Implements a solve method for the Coin solvers.
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.
OSInstance * m_osinstanceSeparation
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 ...
double * getVariableUpperBounds()
Get variable upper bounds.
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...
int * indexes
indexes holds an integer array of indexes whose corresponding values are nonzero. ...
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::map< int, std::string > m_tmpVarMap
std::string * m_variableNames
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..
void getInitialSolution()
generate an intitial feasible solution in theta space for the initial master
virtual void solve()
The implementation of the corresponding virtual function.
double zeroTol
we terminate column generation when the reduced costs are not smaller than zeroTol ...
std::string * m_nodeName
m_nodeName is the vector of node names
OSDecompParam m_osDecompParam
share the parameters with the decomposition solver
double ** m_newColumnRowValue
used for throwing exceptions.
bool m_costSetInOption
m_costSetInOption is true if the costs are set using the OSOption file
int m_numHubs
m_numHubs is the number of hubs/routes
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_maxMasterColumns
m_maxMasterColumns is the maximumn number of columns we allow in the master
int * m_lowerBoundL
smallest possible L-value on a route for now this will equal
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 ...