/* $Id$ * * Name: CouenneSparseBndVec.hpp * Author: Pietro Belotti * Purpose: Keep track of tightened bounds with a sparse vector * * (C) Pietro Belotti, 2010. * This file is licensed under the Eclipse Public License (EPL) */ #ifndef COUENNESPARSEBNDVEC_HPP #define COUENNESPARSEBNDVEC_HPP namespace Couenne { template class CouenneSparseBndVec { /// Implements a fast sparse+dense vector data structure, with a /// size of n and a number k of nonzero elements. Usually, k<= n_) || (dInd_ [sind] != index)) dInd_ [sind = n_++] = index; // this entry is new and has to be initialized return data_ [sind]; } /// Return data in DENSE format -- use with care T *data () {return data_;} /// Return indices in DENSE format -- for use with data() unsigned int *indices () {return dInd_;} /// Return current size unsigned int nElements () {return n_;} /// Resize void resize (unsigned int newsize) {size_ = newsize;} }; } #endif // #include // #include // int main () { // Couenne::CouenneSparseBndVec v (100); // v[84] = 10; // v[0] = 60; // v[99] = 63; // v[72] = 16; // v[84] = 70; // v[25] = 33; // v[21] = 15; // v[21] = 12; // v[21] = 12; // v[8] = 22; // v[4] = 66; // srand48(1243235); // for (int i=0; i<1e9; i++) // v [(int)(99.999 * drand48())] = (int)(10000 * drand48()); // for (int i=0; i< v.nElements(); i++) // printf ("v [%d] = %d\n", v.indices () [i], v.data () [i]); // }