Exemplo n.º 1
0
def main(graph_path, nr_of_iterations, threads_per_block, blocks_per_grid,nrParticles):
  # nrParticles = 2000
  filename = r'./graphs/graph1000'
  nrNodes, neighborhood, nodes = graph.loadGraph(filename)
  edges = graph.generateEdges(nodes, neighborhood)



  s = time.time()
  pathLen =  pso.pso(nodes, edges, nrParticles, nr_of_iterations, threads_per_block, blocks_per_grid)
  f = time.time()
  return f-s, pathLen
Exemplo n.º 2
0
def set_graph():
    """
    sekvencijalno kreira graf, sprema ga na disk, učitava i ispisuje radi provjere
   
    Parameters 
    ----------
    None
    
    Returns:
    -------
    None
    
    """

    nodes = int(input("Enter number of nodes: "))
    generatedGraph = create_graph(nodes)

    saveGraph(generatedGraph, 'testExample.txt')
    loadedGraph = loadGraph('testExample.txt')

    print('Initial graph:\n', loadedGraph, '\nNote: initial graph visualization is stored in pdf file')
Exemplo n.º 3
0
from graph import create_graph, create_pdf, loadGraph, saveGraph
from file import set_graph

# mpiexec -n 4 python main.py

comm = MPI.COMM_WORLD
rank = comm.Get_rank()
size = comm.Get_size()

INF = 9999
generatedGraph = None


if rank==0:  
    set_graph()
    generatedGraph = loadGraph('testExample.txt')

    #https://www.quora.com/Are-NumPy-arrays-faster-than-lists
    #bez konvertiranja numpy polja u listu je read i write duplo sporiji
    generatedGraph = generatedGraph.tolist()

'''
generatedGraph = [[0, 5, INF, 10],
        [INF, 0, 3, INF],
        [INF, INF, 0,   1],
        [INF, INF, INF, 0]
        ]
'''

graph = comm.bcast(generatedGraph, root=0)
n = comm.bcast(len(graph), root=0)
Exemplo n.º 4
0
                                     distance[i][k] + distance[k][j])
        #print(distance)
    #print_solution(distance)


# Printing the solution
def print_solution(distance):
    for i in range(nV):
        for j in range(nV):
            if (distance[i][j] == INF or distance[i][j] > 9000):
                print("INF", end=" ")
            else:
                print(distance[i][j], end="  ")
        print(" ")


G = loadGraph('testExample.txt')
nV = len(G)
'''
G =  [[0, 5, INF, 10],
        [INF, 0, 3, INF],
        [INF, INF, 0,   1],
        [INF, INF, INF, 0]
        ]
nV=len(G)
'''
floyd_warshall(G)

#t.stop() vraća lijepo formatiran rezultat pa nije potreban print
execution_time = t.stop()
Exemplo n.º 5
0
# Mounting default Vue files after running npm run build 
app.mount("/dist", StaticFiles(directory="./ui/dist/"), name="dist")

if path.exists("./ui/dist/css"):
    app.mount("/css", StaticFiles(directory="./ui/dist/css"), name="css")

if path.exists("./ui/dist/img"):
    app.mount("/img", StaticFiles(directory="./ui/dist/img"), name="img")

if path.exists("./ui/dist/js"):    
    app.mount("/js", StaticFiles(directory="./ui/dist/js"), name="js")

templates = Jinja2Templates(directory="./ui/dist")


(G, V, E) = loadGraph(domination_scores_file=settings.domination_score_file, nodes_file=settings.nodes_file, edges_file=settings.edges_file)

class Item(BaseModel):
    numbers: list

@app.get("/")
async def serve_home(request: Request):
    return templates.TemplateResponse("index.html", {"request": request})

@app.post("/")
async def sort(item: Item):
    return { "sorted" : sorted(item.numbers) } 

# @app.get("/sub/{item_id}/{hops}")
# async def getSubGraph(item_id: int, hops: int = 1):
#     max = V.iloc[0].to_dict()