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

https://github.com/sueda/eol-cloth
16 March 2020, 03:50:51 UTC
  • Code
  • Branches (2)
  • Releases (0)
  • Visits
Revision a6d03813fc8cd8b58edc6b3cef6b2f732f4d9d36 authored by Nick Weidner on 07 September 2018, 18:25:33 UTC, committed by Nick Weidner on 07 September 2018, 18:25:33 UTC
Point fix
1 parent 09335f4
  • Files
  • Changes
    • Branches
    • Releases
    • HEAD
    • refs/heads/master
    • refs/heads/v0.2
    • a6d03813fc8cd8b58edc6b3cef6b2f732f4d9d36
    No releases to show
  • 1b43d4c
  • /
  • src
  • /
  • GeneralizedSolver.cpp
Raw File Download
Take a new snapshot of a software origin

If the archived software origin currently browsed is not synchronized with its upstream version (for instance when new commits have been issued), you can explicitly request Software Heritage to take a new snapshot of it.

Use the form below to proceed. Once a request has been submitted and accepted, it will be processed as soon as possible. You can then check its processing state by visiting this dedicated page.
swh spinner

Processing "take a new snapshot" request ...

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.

  • revision
  • directory
  • content
  • snapshot
origin badgerevision badge
swh:1:rev:a6d03813fc8cd8b58edc6b3cef6b2f732f4d9d36
origin badgedirectory badge
swh:1:dir:1b07a9d61d0f633b8fdcff6b3e3ac51cc715151c
origin badgecontent badge
swh:1:cnt:5f1fbf35bf4a213c3141ab86c74f0c3c4157a5a8
origin badgesnapshot badge
swh:1:snp:283fc0df3963669dc87db8b6fd8259953e6e6732

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.

  • revision
  • directory
  • content
  • snapshot
Generate software citation in BibTex format (requires biblatex-software package)
Generating citation ...
Generate software citation in BibTex format (requires biblatex-software package)
Generating citation ...
Generate software citation in BibTex format (requires biblatex-software package)
Generating citation ...
Generate software citation in BibTex format (requires biblatex-software package)
Generating citation ...
Tip revision: a6d03813fc8cd8b58edc6b3cef6b2f732f4d9d36 authored by Nick Weidner on 07 September 2018, 18:25:33 UTC
Point fix
Tip revision: a6d0381
GeneralizedSolver.cpp
#include "GeneralizedSolver.h"

#include "matlabOutputs.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)
{

}

void generateMatlab(const SparseMatrix<double>& MDK, const VectorXd& b,
	const SparseMatrix<double>& Aeq, const VectorXd& beq,
	const SparseMatrix<double>& Aineq, const VectorXd& bineq,
	VectorXd& v)
{
	mat_s2s_file(MDK, "MDK", "solver.m", true);
	vec_to_file(b, "b", "solver.m", false);
	mat_s2s_file(Aeq, "Aeq", "solver.m", false);
	vec_to_file(beq, "beq", "solver.m", false);
	mat_s2s_file(Aineq, "Aineq", "solver.m", false);
	vec_to_file(bineq, "bineq", "solver.m", false);
	vec_to_file(v, "v_input", "solver.m", false);
}

#ifdef EOLC_MOSEK
bool mosekSolve(const SparseMatrix<double>& MDK, const VectorXd& b,
	const SparseMatrix<double>& Aeq, const VectorXd& beq,
	const SparseMatrix<double>& Aineq, const VectorXd& bineq,
	VectorXd& v)
{
	QuadProgMosek *program = new QuadProgMosek();
	double inf = numeric_limits<double>::infinity();

	VectorXd xl;
	VectorXd xu;
	xl.setConstant(b.size(), -inf);
	xu.setConstant(b.size(), inf);

	program->setNumberOfVariables(b.size());
	program->setNumberOfEqualities(beq.size());
	program->setNumberOfInequalities(bineq.size());

	program->setObjectiveMatrix(MDK);
	program->setObjectiveVector(b);

	program->setInequalityMatrix(Aineq);
	program->setInequalityVector(bineq);

	program->setEqualityMatrix(Aeq);
	program->setEqualityVector(beq);

	bool success = program->solve();

	v = program->getPrimalSolution();

	return success;
}
#endif

#ifdef EOLC_GUROBI
bool gurobiSolve(SparseMatrix<double>& MDK, const VectorXd& b,
	SparseMatrix<double>& Aeq, const VectorXd& beq,
	SparseMatrix<double>& Aineq, const VectorXd& bineq,
	VectorXd& v)
{
	GurobiSparse qp(b.size(), beq.size(), bineq.size());
	qp.displayOutput(false);

	SparseMatrix<double> Sb(b.sparseView());
	SparseVector<double> Sbeq(beq.sparseView());
	SparseVector<double> Sbineq(bineq.sparseView());

	MDK.makeCompressed();
	Sb.makeCompressed();
	Aeq.makeCompressed();
	Aineq.makeCompressed();

	VectorXd XL, XU;
	double inf = numeric_limits<double>::infinity();
	XL.setConstant(b.size(), -inf);
	XU.setConstant(b.size(), inf);

	bool success = qp.solve(MDK, Sb,
		Aeq, Sbeq,
		Aineq, Sbineq,
		XL, XU);

	v = qp.result();

	return success;
}
#endif

bool GeneralizedSolver::velocitySolve(const bool& fixedPoints, const bool& collisions,
	SparseMatrix<double>& MDK, const VectorXd& b,
	SparseMatrix<double>& Aeq, const VectorXd& beq,
	SparseMatrix<double>& Aineq, const VectorXd& bineq,
	VectorXd& v)
{
	//if (true) {
	//	generateMatlab(MDK, b,
	//		Aeq, beq,
	//		Aineq, bineq,
	//		v);
	//}

	if (!collisions && false) {
		// 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);
			//cout << v << endl;
			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);
			return true;
		}
	}
	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
			bool success = mosekSolve(MDK, b,
				Aeq, beq,
				Aineq, bineq,
				v);
			return success;
#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
			bool success = gurobiSolve(MDK, b,
				Aeq, beq,
				Aineq, bineq,
				v);
			return success;
#else
			cout << "ERROR:" << endl;
			cout << "Attempting to use the gurobi solver without gurobi support enabled" << endl;
			abort();
#endif
		}
	}

	return false;
}
The diff you're trying to view is too large. Only the first 1000 changed files have been loaded.
Showing with 0 additions and 0 deletions (0 / 0 diffs computed)
swh spinner

Computing file changes ...

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