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

  • 505fc29
  • /
  • src
  • /
  • ArclengthStrategyGurobiSeparate.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:cfcd628b4acaa83f26756e73242a0d3ee7d786c5
directory badge
swh:1:dir:6b077e51a4e0137699fb0df51458390d621719a6

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 ...
ArclengthStrategyGurobiSeparate.cpp
#include "ArclengthStrategyGurobiSeparate.h"

#include <nsessentials/util/TimedBlock.h>
#ifdef WITH_GUROBI
#include <gurobi_c++.h>
#endif

void ArclengthStrategyGurobiSeparate::CalculateParametricLengths(ParametrizationData& optData)
{
#ifdef WITH_GUROBI
	nse::util::TimedBlock b("Finding parametric sizes of patches using separate Gurobi ..");

	bool verbose = false;

#pragma omp parallel for
	for (int i = 0; i < optData.arcConstraints.size(); ++i)
		optData.arcConstraints[i].broken = true;	

	try
	{
		GRBEnv env = GRBEnv();

		for (int iPatch = 0; iPatch < optData.patches.size(); ++iPatch)
		{
			auto& patch = optData.patches[iPatch];
			if (patch.PatchSides().size() != 4)
				continue;

			GRBModel model = GRBModel(env);

			model.set(GRB_IntParam_OutputFlag, verbose ? 1 : 0);

			GRBQuadExpr objective = 0.0;

			std::map<size_t, GRBVar> variables;
			for (auto& side : patch.PatchSides())
			{
				for (auto arcIdx : side)
				{
					auto var = model.addVar(1.0, 5000.0, 0, GRB_INTEGER);
					objective = objective + optData.geometricArcFitWeight[arcIdx] * (var - optData.parametricHalfarcTargetLengths[arcIdx]) * (var - optData.parametricHalfarcTargetLengths[arcIdx]);
					variables[arcIdx] = var;
				}
			}

			for (int k = 0; k < 2; ++k)
			{
				GRBLinExpr expr;
				auto& c = optData.faceConstraints[2 * iPatch + k];
				for (int i = 0; i < 2; ++i)
				{
					double sign = (i == 0 ? +1 : -1);
					for (auto arc : c.arcs[i])
						expr = expr + sign * variables.at(arc);
				}
				if (!(c.canGrow[0] && c.canGrow[1]))
				{

					char sense;
					if (!c.canGrow[0] && !c.canGrow[1])
						sense = GRB_EQUAL;
					else if (c.canGrow[0])
						sense = GRB_LESS_EQUAL;
					else
						sense = GRB_GREATER_EQUAL;
					model.addConstr(expr, sense, 0.0);
				}
			}
						
			model.setObjective(objective, GRB_MINIMIZE);

			model.optimize();

			for(auto& entry : variables)
			{
				if (verbose)
					std::cout << "Length: " << entry.second.get(GRB_DoubleAttr_X) << " (optimal length: " << optData.parametricHalfarcTargetLengths[entry.first] << ")" << std::endl;
				optData.parametricHalfarcLengths[entry.first] = entry.second.get(GRB_DoubleAttr_X);
			}
			
			if (verbose)
				std::cout << "Obj: " << model.get(GRB_DoubleAttr_ObjVal) << std::endl;
		}
	}
	catch (GRBException e) {
		std::cout << "Error code = " << e.getErrorCode() << std::endl;
		std::cout << e.getMessage() << std::endl;
	}
	catch (...) {
		std::cout << "Exception during optimization" << std::endl;
	}
#endif
}

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