[lnkForumImage]
TotalShareware - Download Free Software

Confronta i prezzi di migliaia di prodotti.
Asp Forum
 Home | Login | Register | Search 


 

Forums >

comp.lang.python

Prioritization function needed (recursive help!

rh0dium

1/21/2008 10:30:00 PM

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
3 Answers

Paul Rubin

1/21/2008 10:36:00 PM

0

rh0dium <steven.klass@gmail.com> 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.

Arnaud Delobelle

1/21/2008 10:38:00 PM

0

On Jan 21, 10:30 pm, rh0dium <steven.kl...@gmail.com> 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

Kent Johnson

1/21/2008 10:50:00 PM

0

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/Topolo...

Two Python implementations:
http://pypi.python.org/pypi/t...
http://www.bitformation.com/art/python_top...

Kent