2

This is intended to uniquely number the links between a mesh of an arbitrary number o nodes (for my needs anywhere between 1 and 50 is OK. The upper limit can be your choice as long as it is higher than 9.

Here are my requirements:
-the result must be an integer between 0 and 255 -the result must be unique in the sense that each pair of numbers shall result in a unique number (call it link ID)
-the input data is a pair of numbers between 1 and X where X can be between 1 and 100. (you can change that to any number higher than 9, the higher the number the better)
-the result must be intuitive in the sense that if I look at the input pair I should be able to guess

Here is an example:
A1 A2 A3 A4 are the nodes
The A1A2 link will be 12
A3A2 link will be 23

Algorithm: take the node indexes arrange them in an ascending order and you have your Link ID
The problem appears when I try to use the above for numbers higher than 10 because A8A10 will be 810 which is greater than 255

Note: I am fine for nodes from 1 to 9. I need solutions for more than 9 nodes

MiniMe
  • 153
  • 4
  • Is it between 1 and 100 or between 1 and 99? – Kenny Lau Jun 28 '16 at 16:33
  • Let the two numbers in the input be $a$ and $b$. You can just do the remainder of $100a+b$ divided by $255$. – Kenny Lau Jun 28 '16 at 16:34
  • this is flexible, For practical purposes it can be anywhere between 10 and 100 or 200 if that makes the algorithm easier to design – MiniMe Jun 28 '16 at 16:35
  • I am afraid that your suggestion will not result in unique link numbers – MiniMe Jun 28 '16 at 16:36
  • Must the function be one-one? Because the number of possible pairs is $\binom{100}{2}=4950$, and in no way can the mapping be one-one unless more information about the links is known. – GoodDeeds Jun 28 '16 at 16:40
  • Any pair of input numbers shall produce a unique number or set of numbers. A pair can result in more than one set of numbers (link ID options) but to distinct pairs should not produce the same number or intersecting sets of numbers – MiniMe Jun 28 '16 at 16:42
  • The pair 20-30 is considered identical with pair 30-20 these are links between nodes – MiniMe Jun 28 '16 at 16:52
  • @MiniMe But the number of possible links is much more than the number of values it can map to - so unless any additional information about possible links is known, or you have an order of links, say, the first link maps to 1, the second to 2 and so on, this is not possible – GoodDeeds Jun 28 '16 at 16:53
  • I agree, just adjust the upper limit (number of nodes) to any limit convenient for you. The link number must be the result of an algorithm not an arbitrary mapping like you said.. – MiniMe Jun 28 '16 at 16:54

2 Answers2

1

If you have $23$ nodes then there are $\binom{23}{2} = 253$ possible links, assuming that any node may be linked to any other. If you had $24$ nodes there would be $\binom{24}{2} = 276$ possible links, so $23$ nodes is the most you can have if every pair of nodes must have a unique integer identifier $n$ in the range $0 \leq n \leq 255$.

Number the links as follows: for nodes $A_x$ and $A_y$, let $v = \max\{x,y\}, u = \min\{x,y\}.$ In other words, the nodes are identified as nodes number $u$ and $v$ with $1 \leq u < v \leq 23$. Then let the link between these nodes be identified by $$ L(u,v) = \frac12(v-1)(v-2) + u - 1. $$

For example, if we link nodes $A_1$ and $A_2$, which are the lowest-numbered possible pair of nodes, the link is link number $L(1,2) = \frac12(2-1)(2-2) + 1 - 1 = 0$, the lowest possible link number. If we link nodes $A_{22}$ and $A_{23}$, which are the highest-numbered possible pair of nodes, we get link number $L(22,23) = \frac12(23-1)(23-2) + 22 - 1 = 252$.

Some other nodes and their link numbers are: \begin{align} A_1 &&& A_3 & L(1,3) &= 1 \\ A_2 &&& A_3 & L(1,3) &= 2 \\ A_1 &&& A_4 & L(1,3) &= 3 \\ A_3 &&& A_4 & L(1,3) &= 5 \\ A_1 &&& A_5 & L(1,3) &= 6 \\ A_1 &&& A_{21} & L(1,21) &= 190 \\ A_{20} &&& A_{21} & L(20,21) &= 209 \\ A_1 &&& A_{22} & L(1,22) &= 210 \\ A_{21} &&& A_{22} & L(21,22) &= 230 \\ A_1 &&& A_{23} & L(1,23) &= 231 \\ \end{align}

The reasoning behind this formula is that there are $\binom{v-1}{2} = \frac12(v-1)(v-2)$ pairs of nodes where both nodes have node numbers less than $v$, and these will get node numbers $0$ through $\frac12(v-1)(v-2) - 1$, inclusive; then the pair $A_1$, $A_v$ will get the next link number, $\frac12(v-1)(v-2)$, the pair $A_1$, $A_v$ will get link number $\frac12(v-1)(v-2) + 1$, and so forth up to $A_{v-1}$, $A_v$, which gets link number $\frac12(v-1)(v-2) + v - 2 = \frac12 v(v-1) - 1$.

David K
  • 98,388
  • HI David, Excellent answer. Before I mark it as correct I have a couple of questions These are going to be routers in a network. It will be pointless to connect any to any in a realistic topology. An any to any corresponds to a let's call it spatial structure win 23 dimensions. Most of the topologies that I have seen would correspond to maximum a 3D structure. I would rather say that any routers should not have not more than 6 connections to other routers (2 on each x,y,z coordinate) . How does that affect the answer that you provided? – MiniMe Jun 29 '16 at 00:47
  • Perhaps I should rephrase the requirements in a different question. Would you prefer me to do that ? – MiniMe Jun 29 '16 at 00:50
  • This answer is what you get if the numbered nodes could be assigned arbitrarily into any realistic topology; that would include a star topology in which node $17$ is connected to every other node and there are no other links. But if you can pick any node to put in the center, given any pair of nodes it's possible one is in the center and so there might be a link between them. That's a reason to have a distinct link number for each pair of nodes even though you know you will never have anywhere near that many links. – David K Jun 29 '16 at 01:54
  • If you know something more specific about the network topology that dictates that some links can never exist, for example it will be a square grid (possibly with some edges missing) and the nodes will be numbered from left to right starting at the bottom row, you can have a lot more nodes and still give each possible link a unique number in the range $0\leq n \leq 255$. A $10\times10$ square grid has only $180$ possible links, $200$ if you connect the opposite edges in a toroidal topology. A cubical lattice likewise has limited possible links, especially if you already know its dimensions. – David K Jun 29 '16 at 02:02
  • This document describes the problem better then I would: http://www.pitt.edu/~dtipper/2110/Slides4.pdf . My concern is unique and meaningfull IP addressing using 4 octets. My idea was to encode the link on the third octet and the host would be the router number. Maybe working with three octets will make the job easier for you.

    However I was planning to use the first two octets for encoding the carrier with the fist octet and respectively company ID with the second. The Routers can be named or arranged as convenient as possible. I hope these make the solution easier

    – MiniMe Jun 29 '16 at 02:31
  • So just to make it clear I am not looking for optimal paths (an issue addressed by the above doc) but for unique and meaningfull IP addressing scheme (link IDs) – MiniMe Jun 29 '16 at 02:32
  • A device with one IP address may have several links to other devices, so it's unclear how we encode "the" link in one of the octets of that device's address. The question is now more obscure than ever. – David K Jun 29 '16 at 02:58
  • the IP addresses are per interface, each device is attached to a link with one interface. 10.5.56.6 in a topology of 9 devices, following my limited but meaningful convention means: Company ID=10, location=5, link between devices 5 and 6 and the last octet is 6 which means we are speaking about router 6. An IP address has the format A.B.C.D with A-D between 0-255 – MiniMe Jun 29 '16 at 10:53
  • I just came across a webpage that says that a network topology is a planar graph. Not sure if this helps in any way http://math.stackexchange.com/questions/1118286/is-a-network-topology-a-topological-space – MiniMe Jun 29 '16 at 11:03
  • That page does not say a network topology is a planar graph. There is a comment describing one of the related concepts as a "generalization of planar graphs," using the word generalization because the graphs in question are not planar according to the standard definition. – David K Jun 29 '16 at 11:45
  • responded in chat – MiniMe Jun 29 '16 at 13:58
0

For x,y in [1..10] you could map AxAy to 10M+m, where M=max(x,y) and m=min(x,y)

-This yields a number in [11..110] which is guaranteed in [0..255] -AxAy maps to the same number as AyAx since changing order doesn’t affect max or min -Distinct unordered (x,y) pairs always map to different numbers (since they must differ in either max or min, and per the formula no distinct (max,min) pairs map to the same number) -It’s ez to compute mentally

  • My problem is for more than 10 nodes. For under 10 nodes simple ordering the node ascending and concatenating their values meets the requirements – MiniMe Jun 28 '16 at 18:07
  • Sorry I may have misinterpreted "The upper limit can be your choice as long as it is higher than 9". How many nodes must this be able to handle? – user34099 Jun 28 '16 at 18:12