Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > Python > Prioritization function needed (recursive help!)

Reply
Thread Tools

Prioritization function needed (recursive help!)

 
 
rh0dium
Guest
Posts: n/a
 
      01-21-2008
Hi all,

I need some help on writing a recursive priority function

Given a list = [ A, B, C, D]

Where the following constraints are in place:

A depends on [B, C]
C depends on [B]

Figure out real order that prioritizes these.

Output [ B, C, A, D ] is valid. (Actually D could be anywhere in it
as it doesn't matter..)

I am really struggling on simply how to organize the data and write
the corresponding function - I tried classes but I don't know if
that's the best approach. See my other post on this.

Thanks
 
Reply With Quote
 
 
 
 
Paul Rubin
Guest
Posts: n/a
 
      01-21-2008
rh0dium <(E-Mail Removed)> writes:
> I am really struggling on simply how to organize the data and write
> the corresponding function - I tried classes but I don't know if
> that's the best approach. See my other post on this.


We just had a discussion thread about this. Is it a homework problem?

Anyway, look up "topological sorting" in a CS textbook or on Wikipedia.
 
Reply With Quote
 
 
 
 
Arnaud Delobelle
Guest
Posts: n/a
 
      01-21-2008
On Jan 21, 10:30*pm, rh0dium <(E-Mail Removed)> wrote:
> Hi all,
>
> I need some help on writing a recursive priority function
>
> Given a list = [ A, B, C, D]
>
> Where the following constraints are in place:
>
> A depends on [B, C]
> C depends on [B]
>
> Figure out real order that prioritizes these.
>
> Output [ B, C, A, D ] is valid. *(Actually D could be anywhere in it
> as it doesn't matter..)
>
> I am really struggling on simply how to organize the data and write
> the corresponding function - I tried classes but I don't know if
> that's the best approach. *See my other post on this.
>
> Thanks


There's a very recent thread on this subject (topological sort)

--
Arnaud

 
Reply With Quote
 
Kent Johnson
Guest
Posts: n/a
 
      01-21-2008
rh0dium wrote:
> Hi all,
>
> I need some help on writing a recursive priority function
>
> Given a list = [ A, B, C, D]
>
> Where the following constraints are in place:
>
> A depends on [B, C]
> C depends on [B]
>
> Figure out real order that prioritizes these.


You need a topological sort.
http://en.wikipedia.org/wiki/Topological_sort

Two Python implementations:
http://pypi.python.org/pypi/topsort/0.9
http://www.bitformation.com/art/python_toposort.html

Kent
 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
prioritization of traffic doesn't work with on frame-relay. jefflin.choi@gmail.com Cisco 3 10-11-2006 02:10 AM
prioritization of traffic doesn't work with on frame-relay. jefflin.choi@gmail.com Cisco 0 10-10-2006 03:48 AM
write a function such that when ever i call this function in some other function .it should give me tha data type and value of calling function parameter komal C++ 6 01-25-2005 11:13 AM
Passing a C++ object's member function to a C function expecing a function pointer! James Vanns C++ 7 01-21-2004 02:39 AM
Queues, prioritization, changing priorites and algorithms AlanR Java 6 10-06-2003 08:42 AM



Advertisments