Skip to main content
  • Home
  • Development
  • Documentation
  • Donate
  • Operational login
  • Browse the archive

swh logo
SoftwareHeritage
Software
Heritage
Archive
Features
  • Search

  • Downloads

  • Save code now

  • Add forge now

  • Help

  • e31fa09
  • /
  • src
  • /
  • GeneralizedSolver.cpp
Raw File Download

To reference or cite the objects present in the Software Heritage archive, permalinks based on SoftWare Hash IDentifiers (SWHIDs) must be used.
Select below a type of object currently browsed in order to display its associated SWHID and permalink.

  • content
  • directory
content badge
swh:1:cnt:56afca354da8b9a9a04436d070c571683628bf5e
directory badge
swh:1:dir:a182c55e93ceee8e3a35d88e8da2daa576d94fc5

This interface enables to generate software citations, provided that the root directory of browsed objects contains a citation.cff or codemeta.json file.
Select below a type of object currently browsed in order to generate citations for them.

  • content
  • directory
(requires biblatex-software package)
Generating citation ...
(requires biblatex-software package)
Generating citation ...
GeneralizedSolver.cpp
#include "GeneralizedSolver.h"

#include <iostream>

#ifdef EOLC_MOSEK
#include "external\SolverWrappers\Mosek\QuadProgMosek.h"
#endif

#ifdef EOLC_GUROBI
#include "external\SolverWrappers\Gurobi\Gurobi.h"
#endif

using namespace std;
using namespace Eigen;

GeneralizedSolver::GeneralizedSolver() :
	whichSolver(GeneralizedSolver::NoSolver)
{

}

bool GeneralizedSolver::velocitySolve(const bool& fixedPoints, const bool& collisions,
	const SparseMatrix<double>& MDK, const VectorXd& b,
	const SparseMatrix<double>& Aeq, const VectorXd& beq,
	const SparseMatrix<double>& Aineq, const VectorXd& bineq,
	VectorXd& v)
{
	if (!collisions) {
		// Simplest case, a cloth with no fixed points and no collisions
		if (!fixedPoints) {
			ConjugateGradient<SparseMatrix<double>, Lower | Upper> cg;
			cg.compute(MDK);
			v = cg.solve(-b);
			return true;
		}
		else {
			// If there are fixed points we can use KKT which is faster than solving a quadprog
			// the assumption is made that MDK and b have been built properly uppon making it here
			LeastSquaresConjugateGradient<SparseMatrix<double> > lscg;
			lscg.compute(MDK);
			v = lscg.solve(-b);
		}
	}
	else {
		if (whichSolver == GeneralizedSolver::NoSolver) {
			cout << "The simulation has encountered a collision, but a quadratic programming solver has not been specified." << endl;
			cout << "Please either set an external quadratic programming solver, or avoid collisions in your simulation." << endl;
			abort();
		}
		else if (whichSolver == GeneralizedSolver::Mosek) {
#ifdef EOLC_MOSEK

#else
			cout << "ERROR:" << endl;
			cout << "Attempting to use the mosek solver without mosek support enabled" << endl;
			abort();
#endif
		}
		else if (whichSolver == GeneralizedSolver::Gurobi) {
#ifdef EOLC_GUROBI

#else
			cout << "ERROR:" << endl;
			cout << "Attempting to use the gurobi solver without gurobi support enabled" << endl;
			abort();
#endif
		}
	}

	return false;
}

back to top

Software Heritage — Copyright (C) 2015–2026, The Software Heritage developers. License: GNU AGPLv3+.
The source code of Software Heritage itself is available on our development forge.
The source code files archived by Software Heritage are available under their own copyright and licenses.
Terms of use: Archive access, API— Content policy— Contact— JavaScript license information— Web API