// (C) Copyright International Business Machines Corporation 2007 // All Rights Reserved. // This code is published under the Eclipse Public License. // // Authors : // Pierre Bonami, International Business Machines Corporation // // Date : 10/06/2007 #include "BonQuadCut.hpp" namespace Bonmin { QuadCut::QuadCut(): OsiRowCut(), c_(0), Q_(), type_(Upper) {} QuadCut::QuadCut(const QuadCut & other): OsiRowCut(other), c_(other.c_), Q_(other.Q_), type_(other.type_){ } QuadCut & QuadCut::operator=(const QuadCut & rhs){ if(this != &rhs){ OsiRowCut::operator=(rhs); c_ = rhs.c_; Q_ = rhs.Q_; type_ = rhs.type_; } return *this; } OsiRowCut * QuadCut::clone() const { return new QuadCut(*this); } QuadCut::~QuadCut(){ } /// Compute cut violation double QuadCut::violated(const double * solution) const{ double rhs = c_; rhs += row().dotProduct(solution); const int * indice = Q_.getIndices(); const double * val = Q_.getElements(); const int * start = Q_.getVectorStarts(); const int * length = Q_.getVectorLengths(); int n = Q_.getMajorDim(); for(int i = 0 ; i < n ; i++){ int s=start[i]; int l=length[i]; for(int k = s ; k < s+l ; k++){ if(i == indice[k]) rhs += solution[i] * solution[indice[k]] * val[k]; else rhs += 2*solution[i] * solution[indice[k]] * val[k]; } } #if 0 for(int i = 0 ; i < n ; i++){ for(int k = 0 ; k < length[i] ; k++){ if(i == indice[k]) rhs += solution[i] * solution[indice[k]] * val[k]; else rhs += 2*solution[i] * solution[indice[k]] * val[k]; } start += length[i]; } #endif return std::max(lb() - rhs, rhs - ub()); } void QuadCut::print() const{ std::cout<<"Quadratic cut has lower bound "< 0 && elements[i] > 0.) std::cout<<"+ "; std::cout<< elements[i] <<" x["< 0 && i % 5 == 0) std::cout<print(); } } } /* Ends Bonmin namespace.*/