示例#1
0
	def GraficoFase(self, id_fase):
		tipos = DBSession.query(TipoItem.id_tipoitem).filter(TipoItem.id_fase==id_fase).all()
		
		itemfase = []
			# todos los items que estan en la fase 
		for j in tipos:
			item = DBSession.query(Item.id_item).filter(Item.id_tipoitem==j.id_tipoitem)
			itemfase.extend(item) 
			
		listitems = []
		grafo = digraph()
		for nodo in itemfase:
			grafo.add_nodes([nodo.id_item])
		
		#~ buscar relaciones de los nodos... (items)
		for nodo in itemfase:
			listitems = listitems + [nodo.id_item] #agrega el id del item a la lista
			
		relaciones = DBSession.query(Relacion).\
		filter(Relacion.tiporelacion=="Padre Hijo").\
		filter(Relacion.id_item1.in_(listitems)).\
		filter(Relacion.id_item2.in_(listitems)).all()
			
		for relacion in relaciones:
			grafo.add_edge((relacion.id_item1,relacion.id_item2))

		return grafo
示例#2
0
def convert_transition_system_into_digraph(ts, starting_player, alphabet,
                                           mp_parameters, options):
    (tool, opt, critical, verbosity, nbw_constr, chk_method, chk_dir, k_start,
     k_bound, k_step, unrea, set_of_winning_strategies, path,
     filename) = options
    (inputs, outputs, dimension, values_I, values_O, values_not_I,
     values_not_O, nu, c_start, c_bound, c_step) = mp_parameters

    # If the transition system is small enough, simplify labels of transitions
    label_simplification = False
    if ts.contents.size_states_PO <= 20:
        label_simplification = True

    if starting_player == P_O:
        alphabet_starting_p = alphabet.contents.output
        alphabet_starting_p_size = alphabet.contents.output_size
        alphabet_other_p = alphabet.contents.input
        alphabet_other_p_size = alphabet.contents.input_size
        first_state_index = 0
        last_state_index = ts.contents.size_states_PO
    else:
        alphabet_starting_p = alphabet.contents.input
        alphabet_starting_p_size = alphabet.contents.input_size
        alphabet_other_p = alphabet.contents.output
        alphabet_other_p_size = alphabet.contents.output_size
        first_state_index = ts.contents.size_states_PO
        last_state_index = ts.contents.size_states_PO + ts.contents.size_states_PI

    alphabet = (alphabet_starting_p, alphabet_starting_p_size,
                alphabet_other_p, alphabet_other_p_size)

    # Initialize the digraph
    g = digraph()
    g.__init__()

    if label_simplification == True:
        for state_index in range(first_state_index, last_state_index):
            add_state_to_digraph_with_formula_simplification(
                g, ts, state_index, alphabet, starting_player)
    else:
        for state_index in range(first_state_index, last_state_index):
            add_state_to_digraph(g, ts, state_index, alphabet)

    initial_states = convert_c_array_to_python_list(
        ts.contents.initial_states, ts.contents.nb_initial_states)

    for initial_state in initial_states:
        g.add_node_attribute(initial_state, ('initial', True))

    return g
示例#3
0
	def GraficoProyecto(self, id_proyecto):
		fases = DBSession.query(Fase).filter(Fase.id_proyecto==id_proyecto).all()
		
		grafo = digraph()
		tipos = []
		items = []
		listitem = []

		###Aca empieza lo que cambie ######
		colores = ['blue','cyan','green','yellow','orange','purple','gray', 'black']
		indexColor = 0

		for i in fases: # todos los items que estan en la fase 
			tipo = DBSession.query(TipoItem.id_tipoitem).filter(TipoItem.id_fase==i.id_fase)
			#tipos.extend(tipo)

			for j in tipos:
				item = DBSession.query(Item.id_item).filter(Item.id_tipoitem==j.id_tipoitem)
				#items.extend(item) 

				for k in items: # por cada item que este en la fase agregamos los nodos del mismo color

					#Agrego el nodo
					grafo.add_node(int(k.id_item),attrs=[('color', colores[indexColor])])
					
					#Agrego a mi lista grobal de items, para luego sacar las relaciones
					listitem = listitem + [k.id_item]

			# Cambio el color para la siguiente fase			
			if indexColor ==7:
				indexColor = 0
			else:
				indexColor = indexColor + 1
		
		###Aca termina lo que cambie ######

		# de la lista final de items obtiene las relaciones
		relaciones = DBSession.query(Relacion).\
		filter((Relacion.id_item1).in_(listitem)).all()

		for r in relaciones: #agrega la aristas al grafo
			grafo.add_edge((int(r.id_item1), int(r.id_item2)))

		return grafo
示例#4
0
def convert_transition_system_into_digraph(ts, starting_player, alphabet, mp_parameters, options):
    (tool, opt, critical, verbosity, nbw_constr, chk_method, chk_dir, k_start, k_bound, k_step, unrea, set_of_winning_strategies, path, filename) = options
    (inputs, outputs, dimension, values_I, values_O, values_not_I, values_not_O, nu, c_start, c_bound, c_step) = mp_parameters

    # If the transition system is small enough, simplify labels of transitions
    label_simplification = False
    if ts.contents.size_states_PO <= 20:
        label_simplification = True
       
    if starting_player == P_O:
        alphabet_starting_p = alphabet.contents.output
        alphabet_starting_p_size = alphabet.contents.output_size
        alphabet_other_p = alphabet.contents.input
        alphabet_other_p_size = alphabet.contents.input_size
        first_state_index = 0
        last_state_index = ts.contents.size_states_PO
    else:
        alphabet_starting_p = alphabet.contents.input
        alphabet_starting_p_size = alphabet.contents.input_size
        alphabet_other_p = alphabet.contents.output
        alphabet_other_p_size = alphabet.contents.output_size
        first_state_index = ts.contents.size_states_PO
        last_state_index = ts.contents.size_states_PO + ts.contents.size_states_PI
        
    alphabet = (alphabet_starting_p, alphabet_starting_p_size, alphabet_other_p, alphabet_other_p_size)

    # Initialize the digraph
    g = digraph()
    g.__init__()
    
    if label_simplification == True:
        for state_index in range(first_state_index, last_state_index):
            add_state_to_digraph_with_formula_simplification(g, ts, state_index, alphabet, starting_player)
    else:
        for state_index in range(first_state_index, last_state_index):
            add_state_to_digraph(g, ts, state_index, alphabet)
    
    initial_states = convert_c_array_to_python_list(ts.contents.initial_states, ts.contents.nb_initial_states)

    for initial_state in initial_states:
        g.add_node_attribute(initial_state, ('initial', True))
    
    return g
示例#5
0
estados = ["q0", "q1", "q2", "q3"]
estado_final = ["q0", "q3"]
estado_inicial = "q0"
alfabeto = ["a", "b"]

print("------------------------")
print("estados:")
print(estados)
print("------------------------")
print("estado inicial: " + estado_inicial)
print("------------------------")
print("estados finais: ")
print(estado_final)
print("------------------------")

grafo = digraph()

grafo.add_nodes(estados)
grafo.add_edge(("q0", "q1"), label=alfabeto[0])
grafo.add_edge(("q0", "q2"), label=alfabeto[1])
grafo.add_edge(("q1", "q3"), label=alfabeto[0])
grafo.add_edge(("q1", "q0"), label=alfabeto[1])
grafo.add_edge(("q2", "q0"), label=alfabeto[0])
grafo.add_edge(("q2", "q3"), label=alfabeto[1])
grafo.add_edge(("q3", "q2"), label=alfabeto[0])
grafo.add_edge(("q3", "q1"), label=alfabeto[1])

estado_atual = estado_inicial

while True:
示例#6
0
 def sampleLink(self, index, list_index, ll):
     s = SamplerStateTracker.samplerStates[SamplerStateTracker.current_iter]
     table_id = s.get_t(index, list_index)
     customersAtTable = s.getCustomersAtTable(table_id, list_index)
     orig_table_members = []
     g = digraph()
     ug = graph()
     for i in customersAtTable:
         orig_table_members.append(i)
         if not g.has_node(i):
             ug.add_node(i)
             g.add_node(i)
         j = s.getC(i, list_index)
         if not g.has_node(j):
             ug.add_node(j)
             g.add_node(j)
         g.add_edge((i,j))
         ug.add_edge((i,j))
     cycles = find_cycle(g)
     isCyclePresent = False
     if index in cycles:
         isCyclePresent = True
     if not isCyclePresent:
         # obs to sample moval will split the table into 2
         ug.del_edge((index, s.getC(index, list_index)))
         temp, new_table_members = breadth_first_search(ug, index)
         orig_table_members = new_table_members
         temp, old_table_members = breadth_first_search(ug, s.getC(index, list_index))
         s.setT(s.getT() + 1)
         s.setC(None, index, list_index)
         new_table_id = self.emptyTables[list_index].remove(0)
         for l in new_table_members:
             s.set_t(new_table_id, l , list_index)
         old_table_id = table_id
         s.setCustomersAtTable(set(old_table_members), old_table_id, list_index)
         table_id = new_table_id
         s.setCustomersAtTable(set(new_table_members), new_table_id, list_index)
     distanceMatrices = Data.getDistanceMatrices()
     distance_matrix = distanceMatrices[list_index]
     priors = distance_matrix[index]
     priors[index] = ll.getHyperParameters().getSelfLinkProb()
     sum_p = sum(priors)
     priors = priors/sum_p
     posterior = []
     indexes = []
     for i in range(len(priors)):
         if priors[i] != 0:
             indexes.append(i)
             table_proposed = s.get_t(i, list_index)
             if table_proposed == table_id:
                 posterior.append(priors[i])
             else:
                 proposedTableMembersSet = s.getCustomersAtTable(table_proposed, list_index)
                 proposed_table_members = list(proposedTableMembersSet)
                 change_in_log_likelihood = self.compute_change_in_likelihood(ll, orig_table_members,proposed_table_members, list_index)
                 posterior.append(exp(log(priors[i]+change_in_log_likelihood)))
     sample = Util.sample(posterior)
     customer_assignment_index = indexes[sample]
     assigned_table = s.get_t(customer_assignment_index, list_index)
     s.setC(customer_assignment_index, index, list_index)
     if assigned_table != table_id:
         s.setT(s.getT()-1)
         for members in orig_table_members:
             s.set_t(assigned_table, members, list_index)
         hs_orig_members_in_new_table = set(s.getCustomersAtTable(assigned_table, list_index))
         for i in range(len(orig_table_members)):
             hs_orig_members_in_new_table.add(orig_table_members[i])
         s.setCustomersAtTable(hs_orig_members_in_new_table, assigned_table, list_index)
         s.setCustomersAtTable(None, table_id, list_index)
         self.emptyTables[index].append(table_id)
# Definicion de un grafo y uso del algoritmo de Dijkstra
# para encontrar la ruta mas corta entre un origen y todos
# los demas vertices

# Import pygraph
from pygraph.classes.graph import *
from pygraph.classes.digraph import *
from pygraph.algorithms.minmax import shortest_path
import unittest
from pygraph.algorithms.pagerank import pagerank
# Graph creation
gr = digraph()

# Add nodes and edges
gr.add_nodes(["a", "b", "c", "d", "e", "f"])

# notar que los vertices o edge, ahora tienen definido un peso
gr.add_edge(("a", "b"), 3)
gr.add_edge(("a", "f"), 5)
gr.add_edge(("a", "d"), 4)
gr.add_edge(("b", "f"), 1)
gr.add_edge(("b", "c"), 1)
gr.add_edge(("f", "d"), 2)
gr.add_edge(("c", "d"), 2)
gr.add_edge(("d", "b"), 3)
gr.add_edge(("e", "f"), 2)
gr.add_edge(("e", "d"), 3)

#mostrar el grafo
print "\nEl grafo: \n"
print gr