I have a string containing a Polish notation that represents a floor-plan (VLSI placement), and it contains something like: "1234VHV56HV". (FYI, this means: Separate 3 & 4 vertically then separate the result & 2 horizontally then separate the result & 1 vertically, separate 5 & 6 horizontally, then separate the previous two results vertically.)
Assume the string variable is called: polishNotation. The letters contained are ONLY 'V' for vertical or 'H' for horizontal.
I am trying to apply an algorithm called: "Simulated Annealing" to change the Polish notation, so I want to randomly select an index (which is of course less than the polishNotation.Length) and if this index points to a letter ('V' or 'H'), I want to get the chain of letters including it and then change every 'V' to 'H' and change every 'H' to 'V'... In other words: complement the chain!
- For example: Assume polishNotation = "1234VHV56HV" and the random index = 5, so the result is "H"... I want to retrieve "VHV" and complement it to become: "1234HVH56HV".
- Another example: Assume polishNotation = "1234VHV56HV" and the random index = 9, so the result is "H"... I want to retrieve "HV" and complement it to become: "1234VHV56VH".
- Another example: Assume polishNotation = "1234VHV56HV" and the random index = 6, so the result is "V"... I want to retrieve "VHV" and complement it to become: "1234HVH56HV".
I hope I got myself clear... Any suggestions? I am using C#.net