JOIN
Get Time
long_comps_topcoder  Problem Statement
Contest: Marathon Match 24
Problem: CompoundHypergraphDrawing

Problem Statement

    A compound hypergraph consists of a set V of nodes and a set E of hyperedges connecting sets of those nodes. Each node v in V may have a parent node, given by parent(v). Each hyperedge consists of a subset of the nodes in V. Your task in this problem is to create a visually appealing layout of a compound hypergraph.



In this layout, each node will be represented by a rectangle, and each node will have a minimum height and width requirement. Each hyperedge will be represented by a number of horizontal, vertical, or diagonal (at 45 degree angle) line segments. The segments from one hyperedge should create a path from each node in the hyperedge to each other node in the hyperedge. A segment connects to a node if it touches the rectangle defining that node at any point.



The layout must meet all of the following requirements:
  1. Each set of segments forming a hyperedge must connect all the nodes in that hyperedge.
  2. Each node must meet or exceed its minimum size requirements.
  3. Each segment must be horizontal, vertical, or diagonal.
  4. Each node must be entirely contained within its parent node (the boundaries may not touch).
  5. No two segments may overlap at more than one point (be on top of each other).
  6. No segment may overlap any rectangle edge of any node at more than one point (be on top of its edge).
  7. No segment may touch another segment at its endpoint unless they are part of the same hyperedge.
  8. A segment in an edge may not cross (or touch) the boundary of a node unless that node is an ancestor of some of the nodes being connected, and not an ancestor of some other nodes being connected, or that node is one of the ones being connected. In other words, it may not cross a node boundary unless doing so is necessary to connect the nodes in the hyperedge.
  9. No two nodes may overlap, except in the case where one is contained entirely inside one of its ancestors.
  10. Each coordinate defining a rectangle or segment must be an integer.


For instance, consider the example shown by this image. C is the parent of A and B, while M is the parent of C, D, E, and F. Similarly, N is the parent of G-L. M and N have no parent. The hyperedges consist of the following sets: (A,B), (C,D,E,F), (D,F,G,K,L), (G,H), (G,I), and (G,J,K). Note, for instance, the three segments which connect C, D, E and F. On the other hand, 7 segments are used to connect D, F, G, K, and L.



You will be given the input as a int[] parents where element i of parents is -1 if node i has no parent, and otherwise denotes the parent of node i. You will also be given a String[], hyperedges, where each element is a single-space delimited list of two or more nodes forming a hyperedge. Finally, elements i of width and height will give the minimum width and height requirements for node i.



For each node, you should return the coordinates of the rectangle corresponding to that node, formated as "NODE <node_id> <x1> <y1> <x2> <y2>". For each hyperedge, you should return a list of segments "EDGE <edge_id> <x1> <y1> <x2> <y2> ... <xn> <yn>", where (x2i-1,y2i-1) and (x2i,y2i) specify a segment for each i. The <edge_id> and <node_id> correspond to the indices of the inputs (starting from 0).



Scoring is based on crossings, total length, total size, and number of segments. Each crossing of two segments from different hyperedges will incur a cost of C. Each unit of length in segments will incur a cost of L. Each segment will incur a cost of S. Finally the perimeter of the bounding box around your drawing will incur a cost of P per unit. For each test case, your score will be BEST/YOU, where BEST is the lowest cost incurred on a test case. Invalid returns or program crashes will be treated as a cost of infinity, yielding 0 points for the test case.



Test data will be generated by sampling from a large dataset from a real problem. The sampling process is complicated, and hence a corpus of samples may be downloaded for testing purposes. No more tests will be provided, and the exact process by which the tests are generated will not be further described. All of the minimum width and height requirements will be chosen randomly between 5 and 25, inclusive. Examples may be downloaded at www.topcoder.com/contest/problem/CompoundHypergraphDrawing/examples, while 10,000 other tests may be downloaded from www.topcoder.com/contest/problem/CompoundHypergraphDrawing/tests.gz. Additionally, a simple tool is provided for visualizing your drawings at www.topcoder.com/contest/problem/CompoundHypergraphDrawing/vis.html.
 

Definition

    
Class:CompoundHypergraphDrawing
Method:draw
Parameters:int[], int[], int[], String[], int, int, int, int
Returns:String[]
Method signature:String[] draw(int[] parent, int[] width, int[] height, String[] hyperedges, int C, int L, int S, int P)
(be sure your method is public)
    
 

Notes

-The memory limit is 1024M and the time limit is 2 minutes.
-If two segments from the same hyperedge cross, they are considered connected, and this does not count as a crossing.
-If more than two segments cross at the same point, each pair will count as a crossing.
-All coordinates must be in [-100000,100000].
-Lines have no width.
-You may use at most 1000 segments.
-The largest test case in the tests file has 99 nodes. The average is 59 nodes and 8.6 hyperedges.
-Overlapping includes touching.
-No hyperedge will include a node and one of its ancestors.
 

Constraints

-All the following ranges are selected uniformly at random and are inclusive.
-C will be between 200 and 400.
-L will be between 1 and 3.
-S will be between 5 and 20.
-P will be between 1 and 5.
 

Examples

0)
    
16 nodes and 2 hyperedges.
Seed = -1856808928
C = 380
L = 1
S = 13
P = 1
1)
    
18 nodes and 5 hyperedges.
Seed = -1790372174
C = 330
L = 3
S = 14
P = 1
2)
    
19 nodes and 5 hyperedges.
Seed = -255016001
C = 248
L = 1
S = 12
P = 5
3)
    
22 nodes and 6 hyperedges.
Seed = -1241721039
C = 388
L = 3
S = 5
P = 2
4)
    
32 nodes and 10 hyperedges.
Seed = 1933896167
C = 283
L = 3
S = 20
P = 2
5)
    
48 nodes and 9 hyperedges.
Seed = 1825782255
C = 200
L = 3
S = 15
P = 3
6)
    
52 nodes and 5 hyperedges.
Seed = 1111485637
C = 314
L = 2
S = 13
P = 3
7)
    
52 nodes and 12 hyperedges.
Seed = -55340767
C = 272
L = 1
S = 19
P = 5
8)
    
55 nodes and 9 hyperedges.
Seed = 1142965478
C = 285
L = 3
S = 6
P = 1
9)
    
96 nodes and 4 hyperedges.
Seed = -405961877
C = 285
L = 2
S = 13
P = 4

This problem statement is the exclusive and proprietary property of TopCoder, Inc. Any unauthorized use or reproduction of this information without the prior written consent of TopCoder, Inc. is strictly prohibited. (c)2010, TopCoder, Inc. All rights reserved.