Beispiel #1
0
int FacilityLocation::createVarZ()
{
	int nVars = 0;
	double coeff = 0.0;
	double lb = 0.;
	double ub = 1.;
	VariableHash::iterator vit;
	Variable::VARTYPE varType = Variable::V_Z;
	Column::COLTYPE colType = choseColType(pType, lb, ub);
	// @teste
	//colType = Column::CONTINUOUS;
	
	double bMinus = 0.;
	double bPlus = 0.;
	for (int i = 1; i <= g->nVertices; ++i)
	{
		bMinus += g->vertices[i].getIngree();
		bPlus += g->vertices[i].getEgree();
	}
	
	(bMinus < bPlus) ? coeff = bMinus : coeff = bPlus;

	// * Variable z_e:
	// *
	// * Used to indicate whether the edges e = (i, j) is used to connect the
	// * two core vertex i \in I and j \in I
	for (int i = 1; i <= g->nVertices; ++i)
	{
		Vertex* v = &(g->vertices[i]);

		// @annotation: comment next filter to resolve instances where
		// the vpn terminals may be considered internal nodes
		// 20160125
		if (v->isTerminal())
			continue;

		for (int j = 0; j < g->adjList[i].size(); ++j)
		{
			Vertex* u = &(g->adjList[i][j].getTail());
			Arc* arc = &(g->adjList[i][j]);

			// @annotation: comment next filter to resolve instances where
			// the vpn terminals may be considered internal nodes
			// 20160125
			if (arc->getHead().isTerminal() || arc->getTail().isTerminal())
				continue;

			Variable var(colType, coeff, lb, ub);
			var.setType(varType);
			var.setArc(arc->toEdge());

			vit = vHash[varType].find(var);
			if (vit != vHash[varType].end())
				continue;

			bool isInserted = addCol(&var);
			if (isInserted)
			{
				var.setColIdx(getNCols() - 1);
				vHash[varType][var] = var.getColIdx();
				++nVars;
			}
		}
	}

	return nVars;
}
Beispiel #2
0
void FacilityLocation::builSolutionGraph()
{
	if (s == NULL)
		s = new Graph();

	activeRouters = 0;
	activeArcs = 0;

	s->nVertices = g->nVertices;
	s->nTerminals = g->nTerminals;
	s->nArcs = g->nArcs;
	s->reserve(g->nVertices + 1);

	for (int i = 0; i < g->nTerminals; ++i)
	{
		Vertex terminal = g->terminals[i];

		s->addTerminal(terminal);
		s->addVertex(terminal);
	}

	for (auto& vit : vHash[Variable::V_Y])
	{
		int col = vit.second;
		Variable var = vit.first;
		Vertex v = var.getVertex1();
		int code = v.getCode();


		if (!v.isTerminal() && fabs(xSol[col] - 1.0) < SOLVER_EPS)
		{
			++activeRouters;
			v.setColor("red");
			s->vertices[code] = v;
		}
	}
	printf("");

	for (auto & vit : vHash[Variable::V_X])
	{
		Arc arc = vit.first.getArc();
		int col = vit.second;

		if (fabs(xSol[col] - 1.0) < SOLVER_EPS)
		{
			Vertex router = arc.getHead();
			Vertex terminal = arc.getTail();

			auto & element = g->arcSet[router.getCode()].find(arc);
			if (element != g->arcSet[router.getCode()].end())
			{
				arc.setColor("red");
				arc.setPenwidht(3.5);

				s->addArc(arc);
			}
			else
			{
				std::vector<Arc> path;
				findShortestPath(router, terminal, g, path);

				for (int i = 0; i < path.size(); ++i)
				{
					Arc aux = path[i];
					aux.setColor("red");
					aux.setPenwidht(1.5);

					s->addArc(aux);
					s->vertices[aux.getHead().getCode()].setColor("red");
				}
				activeArcs += path.size();
				printf("");
			}
		}

	}
	printf("");

	for (auto& vit : vHash[Variable::V_Z])
	{
		Variable v = vit.first;
		int col = vit.second;
		Arc arc = v.getArc();

		if (fabs(xSol[col] - 1.0) < SOLVER_EPS)
		{
			++activeArcs;
			arc.setColor("red");
			arc.setPenwidht(3.5);
		}
		else
		{
			arc.setColor("black");
			arc.setStyle("dotted");
			arc.setPenwidht(1.0);
		}
		s->addArc(arc);
	}
	printf("");
#ifdef DEBUG
	s->toDot();
#endif

	return;
}