Example #1
0
void SimpleVector::componentMult( OoqpVector& vec )
{
  assert( n == vec.length() );
  SimpleVector & sv = dynamic_cast<SimpleVector &>(vec);
  double * y = sv.v;
  int i;
  for( i = 0; i < n; i++ ) v[i] *= y[i];
}
Example #2
0
void SimpleVector::axdzpy( double alpha, OoqpVector& xvec,
			       OoqpVector& zvec )
{
  SimpleVector & sxvec = dynamic_cast<SimpleVector &>(xvec);
  double * x = sxvec.v;
  SimpleVector & szvec = dynamic_cast<SimpleVector &>(zvec);
  double * z = szvec.v;
  
  assert( n == xvec.length() &&
	  n == zvec.length() );

  int i;
  for( i = 0; i < n; i++ ) {
    //if(x[i] > 0 && z[i] > 0) 
      v[i] += alpha * x[i] / z[i];
  }
}
Example #3
0
void SimpleVector::axpy( double alpha, OoqpVector& vec )
{
  assert( n == vec.length() );
  SimpleVector & sv = dynamic_cast<SimpleVector &>(vec);

  int one = 1;
  daxpy_( &n, &alpha, sv.v, &one, v, &one );
}
Example #4
0
void SimpleVector::componentDiv ( OoqpVector& vec )
{
  assert( n == vec.length() );
  double * pv = v, *lv = v + n;

  SimpleVector & sv = dynamic_cast<SimpleVector &>(vec);
  double * y = sv.v;

  for( ; pv < lv; pv++, y++ ) *pv /= *y;
}
Example #5
0
void SimpleVector::selectNonZeros( OoqpVector& select )
{
  SimpleVector & sselect = dynamic_cast<SimpleVector &>(select);
  double * map = sselect.v;

  assert( n == select.length() );
  int i;
  for( i = 0; i < n; i++ ) {
    if( 0.0 == map[i] ) v[i] = 0.0;
  }
}
Example #6
0
void SimpleVector::addSomeConstants( double c, OoqpVector& select )
{
  SimpleVector & sselect = dynamic_cast<SimpleVector &>(select);
  double * map = sselect.v;

  int i;
  assert( n == select.length() );
  for( i = 0; i < n; i++ ) {
    if( map[i] ) v[i] += c;
  }
}
Example #7
0
void SimpleVector::divideSome( OoqpVector& div, OoqpVector& select )
{
  if( n == 0 ) return;

  SimpleVector & sselect = dynamic_cast<SimpleVector &>(select);
  double * map = sselect.v;

  SimpleVector & sdiv = dynamic_cast<SimpleVector &>(div);
  double * q   = sdiv.v;
  assert( n == div.length() && n == select.length() );

  double * lmap = map + n;
  double * w = v;
  while( map < lmap ) {
    if( 0 != *map ) {
      *w  /= *q;
    }
    map++;
    w++;
    q++;
  }
}
Example #8
0
void DenseStorage::fromGetDiagonal( int idiag, OoqpVector& vec )
{ 
  int k;
  int extent = vec.length();
  
  assert( idiag + extent <= n );
  assert( idiag + extent <= m );

  SimpleVector &  sv = (SimpleVector &) vec;

  for ( k = idiag; k < idiag + extent; k++ ) {
    sv[k] = M[k][k];
  }
}
Example #9
0
void PetscVector::copyFrom( OoqpVector& v_in )
{
    assert( n == v_in.length() );

    if( v_in.isKindOf( kPetscVector ) ) {
        PetscVector & pet = (PetscVector &) v_in;
        int ierr = VecCopy( pet.pv, pv );
        assert( ierr  == 0);
    } else if ( v_in.isKindOf( kSimpleVector ) ) {
        SimpleVector & sv = (SimpleVector &) v_in;
        this->copyFromArray( sv.elements() );
    } else {
        assert( 0 && "Can't copy from unknown OoqpVector type" );
    }
}
Example #10
0
int SimpleVector::somePositive( OoqpVector& select )
{
  SimpleVector & sselect = dynamic_cast<SimpleVector &>(select);
  double * map = sselect.v;

  assert( n == select.length() );

  int i;
  for( i = 0; i < n; i++ ) {
    if( 0.0 != map[i] && v[i] <= 0 ) {
      cout << "Element " << i << " is nonpositive: " << v[i] << endl;
      return 0;
    }
  }
  return 1;
}
Example #11
0
int SimpleVector::matchesNonZeroPattern( OoqpVector& select )
{
  SimpleVector & sselect = dynamic_cast<SimpleVector &>(select);
  double * map = sselect.v;

  double * lmap = map + n;
  assert( n == select.length() );

  double *w = v;
  while( map < lmap ) {
    if( *map == 0.0 && *w != 0.0  ) return 0;
    map++;
    w++;
  }

  return 1;
}
Example #12
0
void DenseStorage::setToDiagonal( OoqpVector& vec )
{ 
  int i,k;

  int extent = vec.length();

  assert( extent <= n );
  assert( extent <= m );

  SimpleVector &  sv = (SimpleVector &) vec;
  for( i = 0; i < m; i++ ) {
    for( k = 0; k < n; k++ ) {
      M[i][k] = 0.0;
    }
  }

  for ( k = 0; k < extent; k++ ) {
    M[k][k] = sv[k];
  }
}
Example #13
0
double SimpleVector::stepbound(OoqpVector & pvec, double maxStep )
{
  assert( n == pvec.length() );

  SimpleVector & spvec = dynamic_cast<SimpleVector &>(pvec);
  double * p = spvec.v;
  double * w = v;
  double bound = maxStep;

  int i;
  for( i = 0; i < n; i++ ) {
    double temp = p[i];
    if( w[i] >= 0 && temp < 0 ) {
      temp = -w[i]/temp;
      if( temp < bound ) {
	bound = temp;
      }
    }
  }
  return bound;
}
Example #14
0
double 
SimpleVector::shiftedDotProductWith( double alpha, OoqpVector& mystep,
					 OoqpVector& yvec,
					 double beta,  OoqpVector& ystep )
{
  assert( n == mystep.length() &&
	  n == yvec  .length() && 
	  n == ystep .length() );

  SimpleVector & syvec = dynamic_cast<SimpleVector &>(yvec);
  double * y = syvec.v;

  SimpleVector & smystep = dynamic_cast<SimpleVector &>(mystep);
  double * p = smystep.v;

  SimpleVector & systep = dynamic_cast<SimpleVector &>(ystep);
  double * q = systep.v;

  double dot1 = 0.0;
  double dot2 = 0.0;

  const int size = 8196;
  int kmax       = n / size;
  int i          = 0;

  int k, imax;
  for( k = 0; k < kmax; k++ ) {
    imax = (k + 1) * 8196;
    for( ; i < imax; i++ ) {
      dot1 += (v[i] + alpha * p[i]) * (y[i] + beta * q[i] );
    }
    dot2 += dot1;
    dot1  = 0;
  }
  for( ; i < n; i++ ) {
    dot1 += (v[i] + alpha * p[i]) * (y[i] + beta * q[i] );
  }
  
  return dot2 + dot1;
}
Example #15
0
void SimpleVector::writefSomeToStream( ostream& out,
					   const char format[],
					   OoqpVector& select ) const
{
  SimpleVector & sselect = dynamic_cast<SimpleVector &>(select);
  double * s = 0;
  if( select.length() > 0 ) {
    s = sselect.v;
  } 
  int i;

  for( i = 0; i < n; i++ ) {
    if( !s || s[i] != 0.0 ) {
      int j = 0;
      char c;
      while( (c = format[j]) != 0 ) {
	if( c != '%' ) {
	  out << c;
	} else {
	  // Brain-dead variable substitution, but good enough for this
	  // simple case
	  if( 0 == strncmp( "{value}", &format[j + 1], 7 ) ) {
	    out << v[i];
	    j += 7;
	  } else if ( 0 == strncmp( "{index}", &format[j + 1], 7 ) ) {
	    out << i;
	    j += 7;
	  } else {
	    out << c;
	  }
	}
	j++;
      }
      out << endl;
    }
  }
}
Example #16
0
void 
QpGenData::randomlyChooseBoundedVariables( OoqpVector& x,
					   OoqpVector& dualx,
					   OoqpVector& xlow_,
					   OoqpVector& ixlow_,
					   OoqpVector& xupp_,
					   OoqpVector& ixupp_,
					   double * ix,
					   double percentLowerOnly,
					   double percentUpperOnly,
					   double percentBound )
{
  int i;
  double drand( double * );
  // Initialize the upper and lower bounds on x
  int n = x.length();

  
  double * sxlow  = new double[n];
  double * sixlow = new double[n];
  double * sxupp  = new double[n];
  double * sixupp = new double[n];
  double * sx     = new double[n];
  double * sdualx = new double[n];
  
  for( i = 0; i < n; i++ ) {
    double r = drand(ix);
    //cout << " r: " << r << "   ";
	
    if( r < percentLowerOnly ) {
      //cout << "i= " << i << " Lower bound " << endl;
      sixlow[i]  = 1.0;
      sxlow[i]    = (drand(ix) - 0.5) * 3.0;
      sixupp[i]  = 0.0;
      sxupp[i]    = 0.0;
    } else if ( r < percentLowerOnly + percentUpperOnly ) { 
      //cout << "i= " << i << " Upper bound " << endl;
      sixlow[i]  = 0.0;
      sxlow[i]    = 0.0;
      sixupp[i]  = 1.0;
      sxupp[i]    = (drand(ix) - 0.5) * 3.0;
    } else if ( r < percentLowerOnly + percentUpperOnly
		+ percentBound ) {
      //cout << "i= " << i << " Two-sided bound " << endl;
      sixlow[i]  = 1.0;
      sxlow[i]    = (drand(ix) - 0.5) * 3.0;
      sixupp[i]  = 1.0;
      sxupp[i]    = sxlow[i] +  drand(ix) * 10.0;
    } else {
      // it is free
      //cout << "i= " << i << " Free " << endl;
      sixlow[i]  = 0.0;
      sxlow[i]    = 0.0;
      sixupp[i]  = 0.0;
      sxupp[i]    = 0.0;
    }
  }
  xlow_. copyFromArray( sxlow );
  ixlow_.copyFromArray( sixlow );
  xupp_. copyFromArray( sxupp );
  ixupp_.copyFromArray( sixupp );

  for ( i = 0; i < n; i++ ) {
    if( sixlow[i] == 0.0 && sixupp[i] == 0.0 ) {
      // x[i] not bounded
      sx[i] = 20.0 * drand(ix) - 10.0;
      sdualx[i] = 0.0;
    } else if ( sixlow[i] != 0.0 && sixupp[i] != 0.0 ) {
      // x[i] is bounded above and below
      double r = drand( ix );
      if( r < 0.33 ) {
	// x[i] is on its lower bound
	sx[i]     =  sxlow[i];
	sdualx[i] =  10.0 * drand( ix );
      } else if ( r > .66 ) {
	// x[i] is on its upper bound
	sx[i]     =  sxupp[i];
	sdualx[i] = -10.0 * drand( ix );
      } else {
	// x[i] is somewhere in between
	double theta = .99 * drand( ix ) + .005;
	sx[i] = (1 - theta) * sxlow[i] + theta * sxupp[i];
	sdualx[i] = 0.0;
      }
    } else if ( sixlow[i] != 0.0 ) {
      // x[i] is only bounded below
      if( drand( ix ) < .33 ) {
	// x[i] is on its lower bound
	sx[i]     =  sxlow[i];
	sdualx[i] =  10.0 * drand( ix );
      } else {
	// x[i] is somewhere above its lower bound
	sx[i]     = sxlow[i] + 0.005 + 10.0 * drand(ix);
	sdualx[i] = 0.0;
      }
    } else { // x[i] only has an upper bound
      if( drand(ix) > .66 ) {
	// x[i] is on its upper bound
	sx[i]     =  sxupp[i];
	sdualx[i] = -10.0 * drand( ix );
      } else {
	// x[i] is somewhere below its upper bound
	sx[i]     =  sxupp[i] - 0.005 - 10.0 * drand(ix);
	sdualx[i] = 0.0;
      }
    } // end else x[i] only has an upper bound
  } // end for ( i = 0; i < n; i++ )
  x.copyFromArray( sx );
  dualx.copyFromArray( sdualx );

  delete [] sxlow;
  delete [] sxupp;
  delete [] sixlow;
  delete [] sixupp;
  delete [] sx;
  delete [] sdualx;
}
Example #17
0
void SimpleVector::copyFrom( OoqpVector& vec )
{
  assert( vec.length() == n );

  vec.copyIntoArray( this->v );
}