S.O.S. Mathematics CyberBoard

Your Resource for mathematics help on the web!
It is currently Thu, 20 Jun 2013 13:23:38 UTC

All times are UTC [ DST ]




Post new topic Reply to topic  [ 5 posts ] 
Author Message
 Post subject: A code to find a path
PostPosted: Wed, 18 Jan 2012 22:00:21 UTC 
Offline
Senior Member

Joined: Tue, 7 Aug 2007 11:37:58 UTC
Posts: 121
Hi everyone

Assume we have some points so that each point can call the other.
take for instance, five points: a, b, c, d, and e; they communicate each other as follows:
a calls b
b calls c
c replies i.e., to b
b replies i.e., to a
a calls d
d calls c
c replies i.e., to d
d calls e
e replies i.e., to d
d replies i.e, to a

I need to find the path in order way like this:
a, b, c, b, a, d, c, e, d, a

I used a software tool to do this but it generated a path similar to what I want ..like this:
a, b, c, -, -, d, c, -, e, -, -

where - is the caller point i.e it generates the uiques points' names

Now I took such result and store it in an array or list but I failed to replace dashes with the suiatble point

Can anyone help me to replace these dashes

The tool which I used names Altova UModel


Many thanks for any suggestion
full_adder


Top
 Profile  
 
 Post subject: Re: A code to find a path
PostPosted: Thu, 19 Jan 2012 10:45:08 UTC 
Online
Moderator
User avatar

Joined: Mon, 29 Dec 2008 17:49:32 UTC
Posts: 6071
Location: 127.0.0.1, ::1 (avatar courtesy of UDN)
full_adder wrote:
Hi everyone

Assume we have some points so that each point can call the other.
take for instance, five points: a, b, c, d, and e; they communicate each other as follows:
a calls b
b calls c
c replies i.e., to b
b replies i.e., to a
a calls d
d calls c
c replies i.e., to d
d calls e
e replies i.e., to d
d replies i.e, to a

I need to find the path in order way like this:
a, b, c, b, a, d, c, e, d, a

I used a software tool to do this but it generated a path similar to what I want ..like this:
a, b, c, -, -, d, c, -, e, -, -

where - is the caller point i.e it generates the uiques points' names

Now I took such result and store it in an array or list but I failed to replace dashes with the suiatble point

Can anyone help me to replace these dashes

The tool which I used names Altova UModel


Many thanks for any suggestion
full_adder


Use a stack. Convert a,b,... into "push (whatever)", and - as "pop".

_________________
\begin{aligned}
Spin(1)&=O(1)=\mathbb{Z}/2&\quad&\text{and}\\
Spin(2)&=U(1)=SO(2)&&\text{are obvious}\\
Spin(3)&=Sp(1)=SU(2)&&\text{by }q\mapsto(\mathop{\mathrm{Im}}\mathbb{H}\ni p\mapsto qp\bar{q})\\
Spin(4)&=Sp(1)\times Sp(1)&&\text{by }(q_1,q_2)\mapsto(\mathbb{H}\ni p\mapsto q_1p\bar{q_2})\\
Spin(5)&=Sp(2)&&\text{by }\mathbb{HP}^1\cong S^4_{round}\hookrightarrow\mathbb{R}^5\\
Spin(6)&=SU(4)&&\text{by the irrep }\Lambda_+\mathbb{C}^4
\end{aligned}


Top
 Profile  
 
 Post subject: Re: A code to find a path
PostPosted: Thu, 19 Jan 2012 11:27:28 UTC 
Offline
Senior Member

Joined: Tue, 7 Aug 2007 11:37:58 UTC
Posts: 121
Stack is Ok if the path is straightline one by one
i.e., the next point depends on the previuos one
but in the mentiond example , the matter is different

a calls b
b calls c
c replies i.e., to b
b replies i.e., to a
a calls d
d calls c
c replies i.e., to d
d calls e
e replies i.e., to d
d replies i.e, to a
a calls f
f replies i.e., to a

a, b, c, -, -, d, c, -, e, -, -,f,-

Stack tracing: (n dashes requires n+1 pops s.t. the first pop is discarded)
operation stack cont.
---------- --------------------
push(a) a
push(b) a,b
push(c) a,b,c
pop (discarded) a,b
pop a
pop <empty>
push(d) d
push(c) d,c
pop (discarded) d
pop <empty>
push(e) e
pop (discarded)
pop <empty>
pop <empty>
push(f) f
pop <empty>

If we print out the result of each operation to the screen
a,b,c,b,a,d,c,d,e,f

the right path is: a,b,c,b,a,d,c,d,e,d,a,f,a

What do you think?

full_adder


Top
 Profile  
 
 Post subject: Re: A code to find a path
PostPosted: Thu, 19 Jan 2012 12:54:43 UTC 
Online
Moderator
User avatar

Joined: Mon, 29 Dec 2008 17:49:32 UTC
Posts: 6071
Location: 127.0.0.1, ::1 (avatar courtesy of UDN)
full_adder wrote:
Stack is Ok if the path is straightline one by one
i.e., the next point depends on the previuos one
but in the mentiond example , the matter is different

a calls b
b calls c
c replies i.e., to b
b replies i.e., to a
a calls d
d calls c
c replies i.e., to d
d calls e
e replies i.e., to d
d replies i.e, to a
a calls f
f replies i.e., to a

a, b, c, -, -, d, c, -, e, -, -,f,-

Stack tracing: (n dashes requires n+1 pops s.t. the first pop is discarded)
operation stack cont.
---------- --------------------
push(a) a
push(b) a,b
push(c) a,b,c
pop (discarded) a,b
pop a
pop <empty>
push(d) d
push(c) d,c
pop (discarded) d
pop <empty>
push(e) e
pop (discarded)
pop <empty>
pop <empty>
push(f) f
pop <empty>

If we print out the result of each operation to the screen
a,b,c,b,a,d,c,d,e,f

the right path is: a,b,c,b,a,d,c,d,e,d,a,f,a

What do you think?

full_adder


You want a temporary variable ("at") too. So when you get a,b,c,... you first push whatever on "at" to the stack, and let your "at" holds the new point name. When you encounter a "-" you pop to "at".

So taking your example "a, b, c, -, -, d, c, -, e, -, -, f, -", it looks like
Code:
path        stack           at
------   ------------   ----------
a          (empty)          a
b             a             b
c            a,b            c
-             a             b
-          (empty)          a
d             a             d
c            a,d            c
-             a             d
e            a,d            e
-             a             d
-          (empty)          a
f             a             f
-          (empty)          a

_________________
\begin{aligned}
Spin(1)&=O(1)=\mathbb{Z}/2&\quad&\text{and}\\
Spin(2)&=U(1)=SO(2)&&\text{are obvious}\\
Spin(3)&=Sp(1)=SU(2)&&\text{by }q\mapsto(\mathop{\mathrm{Im}}\mathbb{H}\ni p\mapsto qp\bar{q})\\
Spin(4)&=Sp(1)\times Sp(1)&&\text{by }(q_1,q_2)\mapsto(\mathbb{H}\ni p\mapsto q_1p\bar{q_2})\\
Spin(5)&=Sp(2)&&\text{by }\mathbb{HP}^1\cong S^4_{round}\hookrightarrow\mathbb{R}^5\\
Spin(6)&=SU(4)&&\text{by the irrep }\Lambda_+\mathbb{C}^4
\end{aligned}


Top
 Profile  
 
 Post subject: Re: A code to find a path
PostPosted: Thu, 19 Jan 2012 20:36:55 UTC 
Offline
Senior Member

Joined: Tue, 7 Aug 2007 11:37:58 UTC
Posts: 121
I solved it without Stack and "at"

i.e., save memory.. right?
changing is done on the same list
I differentiate between original elements in the array and non-original elements
where the original one is that appears on the original path while the non-original elements are those replaced with "-"s

We cab do such differentiation with appending a flag to the replaced elements

so the code will look like this

for i=1 to n
if A(i) is "-" then
tmp = A(i-1)
for j= i-1 down to 1
if A(j) is original and equlas tmp then
replace A(i) with A(j-1)
exit loop
end if
end for
end if
end for

I tested it with, it works well

However, I feel the code of "outermeasure" i.e., using Stack and "at" temp List is more safe..

I am not sure about this point exactly.. :confused:

What do you think?
full_adder


Top
 Profile  
 
Display posts from previous:  Sort by  
Post new topic Reply to topic  [ 5 posts ] 

All times are UTC [ DST ]


Who is online

Users browsing this forum: No registered users


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum

Search for:
Jump to:  
Contact Us | S.O.S. Mathematics Homepage
Privacy Statement | Search the "old" CyberBoard

users online during the last hour
Powered by phpBB © 2001, 2005-2011 phpBB Group.
Copyright © 1999-2013 MathMedics, LLC. All rights reserved.
Math Medics, LLC. - P.O. Box 12395 - El Paso TX 79913 - USA