Delaunay triangulation with restrictions - delaunay

I need Delaunay triangulation (DT) but with one specific: not all points can be connected. In other words
bool Test( const Point & p0, const Point & p1 );
if this function returns false, then the edge between p0-p1 should NOT be created. There is a lot of info about DT in web, but what is a name for the case I need?
Thanks

Related

Initialization of Arcs depening on Sets/Subsets in directed graphs in CPLEX

I am dealing with a directed weighted graph and have a question about how to initialize a set a defined in the following:
Assume that the graph has the following nodes, which are subdivided into three different subsets.
//Subsets of Nodes
{int} Subset1= {44,99};
{int} Subset2={123456,123457,123458};
{int} Subset3={1,2,3,4,5,6,7,8,9,10,11,12,13,14,15};
{int} Nodes=Subset1 union Subset2 union Subset3;
Now there is a set of H_j arcs, where j is in Nodes. H_j gives all arcs outgoing from Node j.
The arcs are stored in an excel file with the following structure:enter image description here
For node 44 in Nodes (Subset 1), there are the arcs <44,123456>, <44,123457>, <44,123458>. For 66 in Nodes (Subset 2), there is no arc. Can somebody help me how to implement this?
Important is that the code uses the input from the excel because in my real case there will be too much data to make a manual input... :(
Maybe there is a real easy solution for that. I would be very thankful!
Thank you so much in advance!
enter image description here
This addition refers to the answer from #Alex Fleischer:
Your code seems to work also in the overall context.
I am trying to implement the following constraints within a Maximization optimization ( The formulations (j,99) and (j,i) in the lower sum boundaries represent arcs):
enter image description here
I tried to implement it like this:
{int} TEST= {99};
subject to {
sum(m in M, j in a[m])x[<44,j>]==3;
sum(j in destPerOrig[99], t in TEST)x[<j,t>]==3;
forall(i in Nodes_wo_Subset1)
sum(j in destPerOrig[i],i in destPerOrig[i])x[<j,i>]==1;
}
M is a set of trains and a[M] gives a specific cost value for each indiviudal train. CPLEX shows 33 failure messages.
The most frequent one is that it cannot extract x[<j,i>], sum(in in destPerOrig[i]), sum(j in destPerOrig[i] and that x and destPerOrig are outside of the valid area.
Most probably the problem is that I implement the constraints in the wrong manner. Again, it is a directed graph.
Referring to the mathematical formulation in the screenshot: Could the format of destPerOrig[i] be a problem?
At the moment destPerOrig[44] gives {2 3 4}. But should´t it give:
{<44 2> <44 3> <44 4>} to work within the mathematical formulation?
I hope that this is enoug information for you to help me :(
I would be very thankful!
all arcs outgoing from Node j.
How to do this depends on how you store the adjacencies of the graph.
Perhaps you store a vector of arcs:
LOOP over arcs
IF arc source == node J
ADD to output
.mod
tuple arcE
{
string o;
string d;
}
{arcE} arcsInExcel=...;
{int} orig={ intValue(a.o) | a in arcsInExcel};
{int} destPerOrig[o in orig]={intValue(a.d) | a in arcsInExcel : intValue(a.o)==o && a.d!="" };
execute
{
writeln(orig);
writeln("==>");
writeln(destPerOrig);
}
/*
which gives
{44 66}
==>
[{2 3 4} {}]
*/
https://github.com/AlexFleischerParis/oplexcel/blob/main/readarcs.mod
.dat
SheetConnection s("readarcs.xlsx");
arcsInExcel from SheetRead(s,"A2:B5");
https://github.com/AlexFleischerParis/oplexcel/blob/main/readarcs.dat

Tinkerpop/Gremlin: How to join multiple traversals and use their value in a main traversal?

I want to use the result of two traversals a, b to calculate the value for an property. I don't know how to join them into combinedTraversal with both traversals starting from the origin element/vertex.
Graph graph = TinkerFactory.createModern();
GraphTraversal a = __.values("age").count().as("count")
.constant(10).as("allCount")
.math("count / allCount")
// .as("a");
GraphTraversal b = __.values("age").count().as("count")
.constant(10).as("allCount")
.math("count / allCount")
// .as("b");
GraphTraversal combinedTraversal = __
.local(a).as("a")
.local(b).as("b")
.math("a * b");
graph.traversal().V()
.has("age")
.property(Cardinality.single, "value", combinedTraversal)
.iterate();
In the example, traversal a and b assume to start at a given vertex and calculate their value. When i'm using local() the position of the traversal is changed and I don't know how to step back to the origin.
Using sideEffect() on the other hand does not refer to the current element, instead calculating the values for all elements into a map.
Is there any way to build such a combinedTraversal? (The "complex" calculation traversals are chosen on purpose, of course there are simpler ways to solve this example)
Thank You.
I found a solution: projection https://tinkerpop.apache.org/docs/current/reference/#project-step
GraphTraversal combinedTraversal = __.project("a", "b").by(a).by(b).math("a * b");

How to create a bipartite graph in GraphX

I am able to build a graph using a vertexRDD and an edgeRDD via the GraphX API, no problem there. i.e.:
val graph: Graph[(String, Int), Int] = Graph(vertexRDD, edgeRDD)
However, I don't know where to start if I want to use two separate vertexRDD's instead of just one (a bipartite graph). Fore example, a graph containing shopper and product vertices.
My question is broad so I'm not expecting a detailed example, but rather a hint or nudge in the right direction. Any suggestions would be much appreciated.
For example to model users and products as a bipartite graph we might do the following:
trait VertexProperty
case class UserProperty(val name: String) extends VertexProperty
case class ProductProperty(val name: String,
val price: Double) extends VertexProperty
val users: RDD[(VertexId, VertexProperty)] = sc.parallelize(Seq(
(1L, UserProperty("user1")), (2L, UserProperty("user2"))))
val products: RDD[(VertexId, VertexProperty)] = sc.parallelize(Seq(
(1001L, ProductProperty("foo", 1.00)), (1002L, ProductProperty("bar", 3.99))))
val vertices = VertexRDD(users ++ products)
// The graph might then have the type:
val graph: Graph[VertexProperty, String] = null

Parallel edge detection

I am working on a problem (from Algorithms by Sedgewick, section 4.1, problem 32) to help my understanding, and I have no idea how to proceed.
"Parallel edge detection. Devise a linear-time algorithm to count the parallel edges in a (multi-)graph.
Hint: maintain a boolean array of the neighbors of a vertex, and reuse this array by only reinitializing the entries as needed."
Where two edges are considered to be parallel if they connect the same pair of vertices
Any ideas what to do?
I think we can use BFS for this.
Main idea is to be able to tell if two or more paths exist between two nodes or not, so for this, we can use a set and see if adjacent nodes corresponding to a Node's adjacent list already are in the set.
This uses O(n) extra space but has O(n) time complexity.
boolean bfs(int start){
Queue<Integer> q = new Queue<Integer>(); // get a Queue
boolean[] mark = new boolean[num_of_vertices];
mark[start] = true; // put 1st node into Queue
q.add(start);
while(!q.isEmpty()){
int current = q.remove();
HashSet<Integer> set = new HashSet<Integer>(); /* use a hashset for
storing nodes of current adj. list*/
ArrayList<Integer> adjacentlist= graph.get(current); // get adj. list
for(int x : adjacentlist){
if(set.contains(x){ // if it already had a edge current-->x
return true; // then we have our parallel edge
}
else set.add(x); // if not then we have a new edge
if(!marked[x]){ // normal bfs routine
mark[x]=true;
q.add(x);
}
}
}
}// assumed graph has ArrayList<ArrayList<Integer>> representation
// undirected
Assuming that the vertices in your graph are integers 0 .. |V|.
If your graph is directed, edges in the graph are denoted (i, j).
This allows you to produce a unique mapping of any edge to an integer (a hash function) which can be found in O(1).
h(i, j) = i * |V| + j
You can insert/lookup the tuple (i, j) in a hash table in amortised O(1) time. For |E| edges in the adjacency list, this means the total running time will be O(|E|) or linear in the number of edges in the adjacency list.
A python implementation of this might look something like this:
def identify_parallel_edges(adj_list):
# O(n) list of edges to counts
# The Python implementation of tuple hashing implements a more sophisticated
# version of the approach described above, but is still O(1)
edges = {}
for edge in adj_list:
if edge not in edges:
edges[edge] = 0
edges[edge] += 1
# O(n) filter non-parallel edges
res = []
for edge, count in edges.iteritems():
if count > 1:
res.append(edge)
return res
edges = [(1,0),(2,1),(1,0),(3,4)]
print identify_parallel_edges(edges)

How to find the longest path in an acyclic directed graph using OGDF library?

I'm new to OGDF library and need to find the longest path in an acyclic directed graph (I want to use OGDF built in functions).
I know, it is possible to find longest path using shortest path algorithms with negative weights for edges, but also could not find a proper function for it.
Does OGDF has a specific function to do that?
If yes, how can I use it?
In OGDF, you can find the shortest path between node s and other nodes using ShortestPathWithBFM. The lengths (weights) of edges should be passed to the function, using EdgeArray<int>. Here is the class definition from its source code:
namespace ogdf {
class OGDF_EXPORT ShortestPathWithBFM : public ShortestPathModule
{
public:
ShortestPathWithBFM() { }
// computes shortest paths
// Precond.:
//
// returns false iff the graph contains a negative cycle
bool call(
const Graph &G, // directed graph
const node s, // source node
const EdgeArray<int> &length, // length of an edge
NodeArray<int> &d, // contains shortest path distances after call
NodeArray<edge> &pi
);
};
} // end namespace ogdf
The algorithm would compute the longest path if you pass lengths in negative.
For more information, please refer to: http://www.ogdf.net/doc-ogdf/classogdf_1_1_shortest_path_with_b_f_m.html

Resources