/*****************************
 * Practica 9 MP
 * Curso 2008-2009
 *
 * Vicente Lujan Mansilla
 * Lorena Margareto Bisquert
 *****************************/
#include <stdlib.h>
#include <iostream>
#include <time.h>
#include <vector>
#include <assert.h>

#include "Graph.h"

using namespace std;

Graph::Graph(unsigned n)
{
	//srand(time(NULL));
	
	tam = n;
	matriz.resize(tam);
	
	for(int i=0; i<tam; i++)
		matriz[i].resize(size());
}

unsigned Graph::size()
{
	return tam;
}
		
void Graph::print()
{
	for(unsigned i=0; i<matriz.size(); i++)
	{
		for(unsigned j=0; j<matriz.size(); j++)
			cout << (*this)(i, j) << " " ;			
		cout << endl;
	}	
}
 
unsigned Graph::nodoAleat()
{
	return (rand()%(tam-1));
}
		
void Graph::grafoAleat(int min, int max)
{	
	for(unsigned i=0; i<tam; i++)
	{
		for(unsigned j=0; j<tam; j++)
		{
			if(i != j)
				(*this)(i, j) = min + rand()%(max-min+1);			 
		}	
	}
} 

void Graph::grafoAleatND(int min, int max)
{
	unsigned aleat;
	
	for(unsigned i=0; i<tam; i++)
	{
		for(unsigned j=0; j<tam; j++)
		{
			if(i != j)					 
			{
				aleat = min + rand()%(max-min+1);
				(*this)(i, j) = aleat; 
				(*this)(j, i) = aleat; 
			}
			if(i == j)
				(*this)(i, j) = 0;
		}	
	}
}

unsigned Graph::getAccesos()
{
	return accesos;
} 

void Graph::initAccesos()
{
	accesos=0;
}

void Graph::conectar(int n1, int n2, float grado_conect)
{
	for(int i=n1; i<n2; i++)
		(*this)(i, i+1) = 1 + rand()%tam;
	
	for(int i=n1; i<n2; i++)
	{
		for(int j=(i+1); j<=n2; j++)
		{
			if((rand()%100) < grado_conect)
				(*this)(i, j) =  1 + rand()%tam;	
		}
	}
}




	






