Grafos
`
Modelo relacional
`
Conexo
Acclico
No estrictos
`
`
Grado de un grafo (G )
`
Densidad
M
p=
N ( N 1)
2
CARDINALIDADES
`
`
2
4
1
5
x 1 0 1 1 1
x
1
1
1
0
x 0 0 0
x 1 0
x 1
cmake
CMakeLists.txt
MakeFile
Binarios
cmake_minimum_required(VERSION 2.8)
PROJECT(CICLOS)
ADD_LIBRARY(common
xxx.cpp .)
ADD_EXECUTABLE(test test.cpp)
IF(WIN32)
TARGET_LINK_LIBRARIES(test common)
ELSE(WIN32)
TARGET_LINK_LIBRARIES(test common pthread)
ENDIF(WIN32)
Vectores
`
`
`
`
`
`
#include <vector>
push_back () y pop()
Iteradores
Sobrecarga []
clear()
erase()
Sets
`
`
`
`
`
#include <set>
insert()
Iteradores
clear()
erase()
int ** matrix
matrix[0][0]=0;
//...
//Borrar
int main(void)
{
vector< vector<int> > matrix;
vector<int> myv;
myv.push_back(0);
myv.push_back(1);
matrix.push_back(myv);
myv.clear();
myv.push_back(1);
myv.push_back(0);
matrix.push_back(myv);
for(unsigned int i=0; i<matrix.size(); i++){
for(unsigned int j=0; j<matrix[i].size(); j++){
cout<<matrix[i][j]<<" ";
}
cout<<endl;
}
return 0;
}
2
4
int main(void)
{
//Vertices adyacentes a V1
set<int> myset;
myset.insert(2);
myset.insert(4);
myset.insert(5);
myset.insert(6);
mysert.insert(2);
//???
5
return 0;
}
6
Ejercicio
2
4
1
5
Clase Graph
`
Datos miembros
`
`
Funciones miembro
`
`
`
`
EJERCICIOS
Funcin miembro para
calcular el grado del grafo
Algoritmo de optimizacin
int Graph::GraphDegree()
{
int temp, graph_deg=0;
for(int i=0; i<m_N;i++)
{
temp=0;
for(int j=0; j<m_N; j++){
(m_graph[i][j])? temp++ : 1;
}
//Maximizacin
if(temp>graph_deg)
graph_deg=temp;
}
return graph_deg;
}
int Graph::NumberOfEdges ()
{
int nEdges=0;
for(int i=0; i<m_N-1; i++)
for(int j=i+1; j<m_N; j++)
if(m_graph[i][j]==1)
nEdges++;
return nEdges;
}
Streams (STL)
EJERCICIOS
`
`
`
ofstream f(log.txt,ios::iout)
if(!f){
cout<<"error "<<endl;
return -1;
}
//Leer
//Escribir
f.close();
f.close();
Streams (STL)
`
EJERCICIOS
`
Objeto string
string str ;
str = hola + + adios;
If (str.find(hola)==string::npos){
cout<<cadena no encontrada<<endl;
}
Operador texto
class graph {
friend ostream & operator << (ostream & , const Graph& );
}
Formato DIMACS
Formato SGF (simple graph format)
SGF
c tamao 9, aristas 14
c Bosque con dos arboles y
c un ciclo en el segundo
p9
010000000
101000000
010100000
001010000
000101000
000010000
000000011
000000101
000000110
DIMACS
c File: johnson8-2-4.clq
c
c Source: Panos Pardalos
c pardalos@math.ufl.edu
p edge 28 210
e43
e52
e61
e73
e75
e76
e82
e84
e86
//
argv: tabla de
parmetros
#include <iostream>
using namespace std;
int main (int argc, char** argv )
{
if(argc>1){
for(int i=1; i<=argc; i++){
cout<<"param: "<<i<<" es "<<argv[i]<<endl;
}
}
}