graph-theory

Most efficient implementation for a complete undirected graph

喜夏-厌秋 提交于 2019-12-10 21:14:34
问题 Problem background I am currently developing a framework of Ant Colony System algorithms. I thought I'd start out by trying them on the first problem they were applied to: Travelling Salesman Problem (TSP). I will be using C# for the task. All TSP instances will consist of a complete undirected graph with 2 different weights associated with each edge. Question Until now I've only used adjacency-list representations but I've read that they are recommended only for sparse graphs. As I am not

What is an “external node” of a “magic” 3-gon ring?

喜夏-厌秋 提交于 2019-12-10 19:59:43
问题 I want to solve Project Euler's problem #68 in C#, but I've so far not understood the question clearly. What does external node mean in this problem statement? Consider the following "magic" 3-gon ring, filled with the numbers 1 to 6, and each line adding to nine. 4 \ 3 / \ 1 - 2 - 6 / 5 Working clockwise , and starting from the group of three with the numerically lowest external node (4,3,2 in this example), each solution can be described uniquely. For example, the above solution can be

Implementing Disjoint Set Approximation (Union Find) in SQL

我的梦境 提交于 2019-12-10 19:52:59
问题 What would be the best way to implement approximate Disjoint Sets using SQL? Details I have a table of edges, stored as a two-column table of [vertex_a, vertex_b] . I need a table of distinct sets, stored as [vertex, set_id] with one row per vertex, labeling each vertex with a disjoint set_id. Constraints Must be a purely SQL implementation. It can leverage Postgres-specific functions, but pure ANSI SQL highly preferred. The result can be approximate- it's acceptable to label a few sets as

Obtaining a tree decomposition from an elimination ordering and chordal graph

半腔热情 提交于 2019-12-10 12:20:25
问题 I need a nice tree decomposition of a graph given an elimination ordering and a chordalization of the graph. My idea is to obtain all cliques in the graph (which I can do) and build a binary tree starting from a root and make children (i.e., cliques) depending on how many veritices the cliques have in common. I want to do this until all cliques are used and hence, I have a tree. The problem is that the cliques could have more than 2 vertices so I can not recursively run for each vertex as

Graph coloring Gurobi constraints

我们两清 提交于 2019-12-10 11:49:06
问题 I'm trying to fix some constraints for the Graph coloring problem using networkx and gurobi. This is all the code that i wrote: import networkx as nx import gurobi as gb from itertools import combinations, chain import pygraphviz as pygv import os import matplotlib.pyplot as plt from IPython.display import SVG, display Creation of the graph, adding nodes and edges and two lists. G = nx.Graph() G.add_nodes_from ([1,2,3,4,5]) G.add_edge(1,2) G.add_edge(1,3) G.add_edge(1,4) G.add_edge(1,5) G.add

Finding the shortest path in a graph between 2 nodes that goes through a subset of nodes

亡梦爱人 提交于 2019-12-10 11:28:57
问题 I'm trying to find out an efficient way of finding the shortest path between 2 nodes in a graph with positive edge costs that goes trough a subset of nodes. More formally: Given a graph G = (U, V) where U is the set of all nodes in the graph and V is the set of all edges in the graph, a subset of U called U' and a cost function say: f : UxU -> R+ f(x, y) = cost to travel from node x to node y if there exists an edge between node x and node y or 0 otherwise, I have to find the shortest path

Barabasi-Albert model, wrong degree exponent

萝らか妹 提交于 2019-12-10 11:09:18
问题 I'm trying to generate a scale-free network using the Barabasi-Albert model. The model predicts a degree distribution that follows p(k) ~ k^-3 but mine shows k^-2. The algorithm was taken from Barabasi's book at this URL: http://barabasi.com/networksciencebook, here is the relevant paragraph: Barabasi's algorithm Here is my code, could someone please help me figure out what is wrong? import numpy as np import matplotlib.pyplot as plt from collections import Counter plt.rcParams["figure

Can I choose a random element from a set if I don't know the size of the set?

元气小坏坏 提交于 2019-12-10 10:29:19
问题 I'm writing a bit of JavaScript code which should select a random item from a canvas if the item meets certain requirements. There are different kinds of items (circles, triangles, squares etc.) and there's usually not the same number of items for each kind. The items are arranged in a hierarchy (so a square can contain a few circles, and a circle can contain other circles and so on - they can all be nested). Right now, my (primitive) approach at selecting a random item is to: Recursively

identifying connected graphs given edges

本小妞迷上赌 提交于 2019-12-10 10:19:59
问题 How do I group people who are related, even indirectly? Concretely, using the first two columns of the data set like below, how do I in SAS (maybe using a DATA step or PROC SQL) programmatically derive the third column? Is there a non-iterative algorithm? Background: Each person has multiple addresses. Through each address, each person is connected to zero or more persons. If two people are connected, they get the same group ID. If person A is directly connected to B and B is connected to C,

How to find all vertex-disjoint paths in a graph?

旧时模样 提交于 2019-12-09 12:46:25
问题 Suppose there are 3 target nodes in a graph. A vertex-disjoint path means there is not any same node except the end nodes during the path. For any one single node, say node i, how to find all vertex-disjoint paths from node i to the three target nodes? 回答1: You can solve this problem by reducing it to a max-flow problem in an appropriately-constructed graph. The idea is as follows: Split each node v in the graph into to nodes: v in and v out . For each node v, add an edge of capacity one from