0

I am working on a problem which could be reduced to a graph optimization problem as below.

A set of colored nodes are given.

A set of rules are given about the cost contribution from the nodes.

Ex.

  • If a red node is not connected, cost is 100

  • If a red node connects to red node, cost is 10

  • If a red node connects to a blue node, cost is 20

  • Any node can have only 4 connections at max.

The problem is to optimize the connections (vertices) such that the total cost is minimized and the final graph obeys the rules.

I am wondering if this problem, maybe in some other way, known. If so, please provide any pointers that might be of help. Thanks.

( Please let me know if any of the tags should be removed. )

Suresh
  • 925
  • 1
  • 9
  • 23
  • FYI: vertices are nodes, edges are connections. – Paul Brodersen Apr 24 '17 at 08:47
  • Also, for unequal number of red and blue nodes, and a total equal or exceeding 5 nodes, you will have multiple optimal solutions with equal cost. – Paul Brodersen Apr 24 '17 at 08:55
  • Sorry about the incorrect use the word vertice. Updated the question. – Suresh Apr 24 '17 at 09:14
  • Cross-posted: https://cs.stackexchange.com/q/74442/755, http://stackoverflow.com/q/43587648/781723, http://stackoverflow.com/q/43581690/781723. Please [do not post the same question on multiple sites](https://meta.stackexchange.com/q/64068). Each community should have an honest shot at answering without anybody's time being wasted. – D.W. May 19 '17 at 16:02

1 Answers1

1

1) In the case that the numbers of red and blue nodes are balanced, the optimal solution is a chain with alternating colours.

2) If you deviate from balance, you will want to connect your surplus nodes to nodes of the opposite colour with free slots.

3) If no 'free' slots are available, you will want to add the remaining nodes in subgraphs that are tree-like.

EDIT:

This solution only applies to the original formulation of the question, which indicated the existence of only 2 colours.

Paul Brodersen
  • 11,221
  • 21
  • 38
  • Thanks for this answer. Actually, only a simplified description was given. In reality, the number of colors would be as high as 30 and correspondingly rules would also be a long list. I will update the question with these details - I think I have oversimplified in the presentation of the problem. – Suresh Apr 24 '17 at 09:18
  • Open a new question for that, as the problem changes considerably. Also, the algorithms stackexchange is probably a better fit for this question than stackoverflow. – Paul Brodersen Apr 24 '17 at 09:22
  • OK. I will do. Did you mean this one - https://cs.stackexchange.com/ ? – Suresh Apr 24 '17 at 09:24
  • Yeah. That's the one. – Paul Brodersen Apr 24 '17 at 09:25
  • 1
    It just occurred to me that even with more colours, the solution boils down to finding the [minimum spanning tree (MST)](https://en.wikipedia.org/wiki/Minimum_spanning_tree#Minimum-cost_subgraph) for fully connected (weighted) graph. – Paul Brodersen Apr 24 '17 at 09:29
  • Here some nodes being not connected to any other is acceptable. But in MST it is not so. Also, here cycles are allowed. – Suresh Apr 24 '17 at 10:38
  • a) An optimal solution will be acyclic. b) If nodes can be unconnected, then the trivial solution where all nodes are unconnected will always be optimal. – Paul Brodersen Apr 24 '17 at 10:49
  • The edges contribute negative cost. Maybe I should have framed the question as that of maximizing with non-negative contribution from edges. – Suresh Apr 24 '17 at 11:11
  • Lol, yes, indeed. In that case, my proposals are obviously garbage, as I assumed that you wanted to minimise an overall penalty imposed by each edge. I would suggest that you write a new question, where you posit the problem positively and include the fact that there are more colours than 2. Also, provide an example table of costs (all-to-all). – Paul Brodersen Apr 24 '17 at 11:31
  • :) Ok. Updated the question accordingly. – Suresh Apr 24 '17 at 11:43
  • 1
    If you change the question considerably (which you have done twice with regards to my reading), you should really post a new question instead. My answer was valid for the original question (and might help somebody in the future); it is no longer valid as the question stands now, and I can't even delete the answer as you have accepted it. Also, if you only amend the question, the visibility of your question for most SO users will be low as they will sort questions by newest & unanswered. – Paul Brodersen Apr 24 '17 at 11:50
  • Thanks for that suggestion. I will post a new question. – Suresh Apr 24 '17 at 12:00