bool Solver_LP_abstract::readLpFromFile(const std::string& filename,
                                        VectorX &c, VectorX &lb, VectorX &ub,
                                        MatrixXX &A, VectorX &Alb, VectorX &Aub)
{
  std::ifstream in(filename.c_str(), std::ios::in | std::ios::binary);
  typename MatrixXX::Index n=0, m=0;
  in.read((char*) (&n),sizeof(typename MatrixXX::Index));
  in.read((char*) (&m),sizeof(typename MatrixXX::Index));
  c.resize(n);
  lb.resize(n);
  ub.resize(n);
  A.resize(m,n);
  Alb.resize(m);
  Aub.resize(m);
  in.read( (char *) c.data() , n*sizeof(typename MatrixXX::Scalar) );
  in.read( (char *) lb.data() , n*sizeof(typename MatrixXX::Scalar) );
  in.read( (char *) ub.data() , n*sizeof(typename MatrixXX::Scalar) );
  in.read( (char *) A.data() , m*n*sizeof(typename MatrixXX::Scalar) );
  in.read( (char *) Alb.data() , m*sizeof(typename MatrixXX::Scalar) );
  in.read( (char *) Aub.data() , m*sizeof(typename MatrixXX::Scalar) );
  in.close();
  return true;
}
Esempio n. 2
0
void Simulation::computeForces(const VectorX& x, VectorX& force)
{
    VectorX gradient;

    gradient.resize(m_mesh->m_system_dimension);
    gradient.setZero();

    // springs
    for (std::vector<Constraint*>::iterator it = m_constraints.begin(); it != m_constraints.end(); ++it)
    {
        (*it)->EvaluateGradient(x, gradient);
    }

    // external forces
    gradient -= m_external_force;

    force = -gradient;
}