/// RETORNA LA ECUACION DE PRESION DE DICHO ELEMENTO
vec Elemento::ecuaPresion(int n, double &f){
	
	/// VARIABLES NECESARIAS
	vec ecua(n);

	/// OBTENEMOS LAS ARISTAS PARA CORREGIR LA PRESION
	Arista top = getAri(Nodo(0,1)),
		bot = getAri(Nodo(0,-1)),
		der = getAri(Nodo(1,0)),
		izq = getAri(Nodo(-1,0));
	/// DEFINIMOS EL BIJ (VELOCIDADES)
	double a=0 , aij = 0;
	f=0;
	
//	if(izq.isFront() == 2 || der.isFront() == 2 || bot.isFront() == 2 || top.isFront() == 2){
//		ecua(numero) = 1;
//		return ecua;
//	}
	
	///  **************** TOP
	Elemento veci = top.getVecino(*this);
	f-= (top.getv() + (veci.p - this->p) * dt / top.modulo ); 
	a = (top.isFront())? 0 : dt / top.modulo;
	aij += a;
	/// AGREGAMOS EL ELEMENTO VECINO A LA ECUACION
	ecua(veci.numero) = -a;
	
	///  **************** BOT
	veci =  bot.getVecino(*this);
	f+= (bot.getv() - (veci.p - this->p) * dt / bot.modulo);
	a = (bot.isFront())? 0 : dt / bot.modulo;
	aij += a;
	/// AGREGAMOS EL ELEMENTO VECINO A LA ECUACION
	ecua(veci.numero) = -a;
	
	///  **************** DER
	veci =  der.getVecino(*this);
	f-= (der.getu() + (veci.p - this->p) * dt / der.modulo );
	a = (der.isFront())? 0 : dt / der.modulo;
	aij += a;
	/// AGREGAMOS EL ELEMENTO VECINO A LA ECUACION
	ecua(veci.numero) = -a;
	
	///  **************** IZQ
	veci = izq.getVecino(*this);
	f+= (izq.getu() - (veci.p - this->p) * dt / izq.modulo);
	a = (izq.isFront())? 0 : dt / izq.modulo;
	aij += a;
	/// AGREGAMOS EL ELEMENTO VECINO A LA ECUACION
	ecua(veci.numero) = -a;
	
	/// AGREGAMOS LA VARIABLE DEL ELEMENTO CENTRAL
	ecua(this->numero) = aij;
	
	return ecua;
}
void insertar_arco(Grafo &        grafo, 
		   const string & src_name, 
		   const string & tgt_name)
{
  Grafo::Node * n1 = grafo.search_node(Nodo(src_name));

  if (n1 == NULL)
    n1 = grafo.insert_node(src_name);

  Grafo::Node * n2 = grafo.search_node(Nodo(tgt_name));

  if (n2 == NULL)
    n2 = grafo.insert_node(tgt_name);

  grafo.insert_arc(n1, n2);
}
void build_test_graph_1(Grafo & g)
{
  g.insert_node(Nodo("E"));

  insertar_arco(g, "A", "B");
  insertar_arco(g, "A", "D");
  insertar_arco(g, "B", "C");
  insertar_arco(g, "C", "A");
  insertar_arco(g, "D", "E");
  insertar_arco(g, "E", "B");
  insertar_arco(g, "E", "D");

  insertar_arco(g, "E", "G");

  insertar_arco(g, "G", "F");
  insertar_arco(g, "F", "G");

  insertar_arco(g, "E", "H");

  insertar_arco(g, "H", "I");

  insertar_arco(g, "I", "J");
  insertar_arco(g, "J", "K");
  insertar_arco(g, "K", "I");
}
/// RETORNA LA ECUACION DE PRESION DE DICHO ELEMENTO
vec Elemento::setVecinos(int n){
	
	/// VARIABLES NECESARIAS
	vec ecua(n);
	/// OBTENEMOS LAS ARISTAS PARA CORREGIR LA PRESION
	Arista top = getAri(Nodo(0,1)),
		bot = getAri(Nodo(0,-1)),
		der = getAri(Nodo(1,0)),
		izq = getAri(Nodo(-1,0));
	
	ecua(top.getVecino(*this).numero) = 1.0;
	ecua(bot.getVecino(*this).numero) = 1.0;
	ecua(der.getVecino(*this).numero) = 1.0;
	ecua(izq.getVecino(*this).numero) = 1.0;
	ecua(numero) = 1.0;
	
	return ecua;
	
}
Beispiel #5
0
void SOM::inicializar_som() {

	float pos_x = 0,
		  pos_y = 0;

    tasa_old = -1;

	// Utilizo una grilla rectangular para ubicar las neuronas
	for (unsigned int k = 0; k < this->cant; k++) {
		Neurona Nodo(this->N, pos_x, pos_y, cant_clases);
		neuronas[k] = Nodo;

		pos_x++;

		// Si superamos el ancho de la grilla
		if (pos_x >= cant_x) {
			pos_x = 0;
			pos_y++;
		}
	}
}
Beispiel #6
0
/// CONSTRUCTOR RARO DE LA MALLA (FUNCIONA)
double Malla::makeMalla(mdouble nods, mint e, mdouble cond){
	cout<<"INICIO CARGA MALLA"<<endl;
	
	/// INICIALIZAMOS LOS NODOS 
	vector<vector<Nodo>::iterator > nodoIte;
	int nNodos = nods.size();
	for(int i=0;i<nNodos;i++)
		nodos.push_back(Nodo(nods[i][0],nods[i][1]));
	/// CON SU RESPECTIVO ITERADOR
	for(int i=0;i<nNodos;i++)
		nodoIte.push_back(nodos.begin() + i);
	cout<<"CARGO "<< nNodos<<" NODOS"<<endl;
	
	/// VARIABLE DE CONTROL (TRIANGULOS CUADRADOS)
	int nEle = e.size(), cnod = e[0].size(), id_ari = 0;
	
	/// CREAMOS LOS NUEVOS ELEMENTOS
	for(int i=0;i<nEle;i++){
		/// ASIGNAMOS LOS NODOS DEL ELEMENTO I
		vector<vector<Nodo>::iterator > nele;
		for(int n=0;n<cnod;n++)
			nele.push_back(nodoIte[e[i][n]]);
		
		/// AGREGAMOS EL NUEVO Elemento
		elementos.push_back(Elemento(nele,i));
		
		/// PARA CADA PAR DE NODOS CREAMOS UNA ARISTA Y VERIFICAMOS
		/// QUE NO HAYA SIDO CREADA Y LA GUARDAMOS EN EL ITERADOR "a"
		
		for(int j=0;j<cnod;j++){
			vector<vector<Nodo>::iterator > naux;
			/// GUARDAMOS LOS ITERADORES A LOS NODOS
			naux.push_back(nodoIte[e[i][j]]); naux.push_back(nodoIte[e[i][(j+1)%cnod]]);
			/// CREAMOS LA ARISTA CON EL I PAR DE NODOS
			Arista ari;
			ari.addNodos(naux[0],naux[1]);
			if( ari_NoExiste(*naux[0],*naux[1])){
				/// AGREGAMOS LA CONDICION DE CONTORNO DE LA Arista
				/// DEFINIMOS VARIABLES A UTILIZAR
				int ncond = cond.size();
				/// BUSCAMOS LOS NODOS EN LAS CONDICIONES "cond"
				for(int i=0;i<ncond;i++){
					if((nodos[cond[i][0]] == *naux[0] && nodos[cond[i][1]] == *naux[1]) || 
						(nodos[cond[i][0]] == *naux[1] && nodos[cond[i][1]] == *naux[0])){
							if(cond[i][2] == 1) ari.setFront(cond[i][3],cond[i][4]);
							else ari.setFront(cond[i][3]);
						}
				}
				ari.setId(id_ari);
				aristas.push_back(ari);
				naux[0]->push_ariId(id_ari);
				naux[1]->push_ariId(id_ari);
				id_ari++;
			}
		}
	}
	nEle = elementos.size();
	int nAri = aristas.size();
	
	cout<<"CARGO "<<nAri<<" ARISTAS Y "<<nEle<<" ELEMENTOS"<<endl;
	
	/// RECORREMOS LOS ELEMENTOS PARA ASIGNARLE LAS ARISTAS
	for(int i=0;i<nEle;i++){
		/// SETEAMOS LAS ARISTAS DEL ELEMENTO
		elementos[i].setAristas(aristas.begin(), elementos.begin());
	}
	cout<<"ASIGNO ARISTAS A ELEMENTOS"<<endl;
	
	for(int i=0;i<nNodos;i++)
		nodos[i].aris.clear();
	
	cout<<"ELIMINAMOS LAS ARI DE LOS NODOS"<<endl;
	
	h=aristas[0].getModulo();
	
	U.setSizeCeros(nEle*2,cnod+2);
	M.setSizeCeros(nEle,cnod+2);
	F = vec(nEle); P = vec(nEle); B = vec(nEle*2);
	
	cout<<"FIN -  CARGA MALLA"<<endl;
	
	return h;
}
bool Elemento::top(Nodo midA){/// si esta en top da <0
	return ((midPoint - midA)*Nodo(0,1) < -.0001)? true : false;
}
/// VERIFICAMOS DE QUE LADO ESTA LA ARISTA EN EL ELEMENTO
bool Elemento::left(Nodo midA){/// si esta a la izquierda da >0
	return ((midPoint - midA)*Nodo(1,0) > .0001)? true : false; }
// PRE: coord_en_pixeles=false si se pasan posiciones en tiles. POST: camino posee pares de posiciones EN TILES que debe recorrer secuencialmente.
Camino Calculador::obtenerCaminoMin(Escenario *esc, Coordenada coord_orig, Coordenada coord_dest, Coordenada coord_ceros, bool coord_en_pixeles) {
	Camino camino;
	Coordenada pos_tile_inicial, pos_tile_destino;
	try {
		if (coord_en_pixeles) {
			pos_tile_inicial = tileParaPixel(coord_orig, coord_ceros);
			pos_tile_destino = tileParaPixel(coord_dest, coord_ceros);
		} else {
			pos_tile_inicial = coord_orig;
			pos_tile_destino = coord_dest;
		}

		//if ((!esc->tileEsOcupable(pos_tile_destino)) || (pos_tile_inicial == pos_tile_destino))
		if ((pos_tile_inicial == pos_tile_destino) || ((!esc->tileEsOcupable(pos_tile_destino)) && distEuclidiana(pos_tile_inicial, pos_tile_destino) < 2))
			return camino;
	} catch ( FueraDeEscenario &e ) {
		return camino;
	}

	std::vector<Nodo*> visitados, vecinos;
	Nodo *tile_inicial = new Nodo(pos_tile_inicial, NULL, pos_tile_destino);
	Nodo nodoFinal;
	vecinos.push_back(tile_inicial);
	std::vector<Nodo*>::iterator it, pActualIt;
	Nodo *pActual;

	try {
		while (!vecinos.empty()) {
			bool encontrado = false;
			Coordenada c;
			pActualIt = vecinos.begin();
			pActual = (*pActualIt);

			for (c.y = pActual->pos.y-1; c.y <= pActual->pos.y+1; c.y++) {
				for (c.x = pActual->pos.x-1; c.x <= pActual->pos.x+1; c.x++) {
					if ( (!pActual->padre || !pActual->padre->esTile(c)) && (!pActual->esTile(c)) ) {

						if (c == pos_tile_destino) {
							Nodo nodoAux(c, pActual, pos_tile_destino);
							if ((!encontrado) || nodoAux.f() < nodoFinal.f())
								nodoFinal = nodoAux;
							encontrado = true;

						} else if (esc->tileEsOcupable(c) && std::find_if(visitados.begin(), visitados.end(), Nodo::CmpPointerXY(c)) == visitados.end()) {
							it = std::find_if(vecinos.begin(), vecinos.end(), Nodo::CmpPointerXY(c));
							if (it == vecinos.end()) {
								std::vector<Nodo*>::iterator itV = std::lower_bound(vecinos.begin(), vecinos.end(), Nodo(c, pActual, pos_tile_destino), Nodo::CmpNodoVsPointerF());
								vecinos.insert(itV, new Nodo(c, pActual, pos_tile_destino));
							} else if ((*it)->guardarMenorG(pActual)) {
								Nodo *ppVecino = *it;
								vecinos.erase(it);
								it = std::lower_bound(vecinos.begin(), vecinos.end(), ppVecino, Nodo::CmpPointersF());
								vecinos.insert(it, ppVecino);
							}
						}

					}
				}
			}
			if (encontrado) {
				pActual = nodoFinal.padre;
				throw DestinoEncontrado();
			}
			visitados.push_back(pActual);
			pActualIt = std::find_if(vecinos.begin(), vecinos.end(), Nodo::CmpPointerXY(pActual->pos));
			vecinos.erase(pActualIt);
		}
	} catch ( DestinoEncontrado &e ) {	// pActual tiene ahora el último tile del camino, NO el destino.
		while (!pActual->esTile(tile_inicial)) {
				camino.agregar( pActual->pos );
				pActual = pActual->padre;
			}
			camino.invertir();
			if (esc->tileEsOcupable(pos_tile_destino))
				camino.agregar( pos_tile_destino );
			// Nuevo: En el caso de que se pueda hacer el camino entero hasta el lugar anterior porque el destino está ocupado, lo hará.
	}

	for (pActualIt = visitados.begin(); pActualIt < visitados.end(); ++pActualIt)
		delete *pActualIt;
	for (pActualIt =   vecinos.begin(); pActualIt <   vecinos.end(); ++pActualIt)
		delete *pActualIt;
	visitados.clear();
	vecinos.clear();

	return camino;
}