Beefy Boxes and Bandwidth Generously Provided by pair Networks
go ahead... be a heretic
 
PerlMonks  

Re: Task scheduling using perl

by davidrw (Prior)
on Aug 18, 2005 at 13:42 UTC ( [id://484758]=note: print w/replies, xml ) Need Help??


in reply to Task scheduling using perl

Is that sample data you real data? How do you plan to solve the dependency loops (Task1 requires Task3, but Task3 requires Task1)? Also, Task2 requires Task2?

Anyways, my first thought is build a hash structure of the form $deps{$task}{$requiredTask} .. so with the above you would have something like:
%deps = ( 1 => { 2 => undef, 3 => undef }, 2 => { 2 => undef, 4 => undef }, 3 => { 1 => undef, 4 => undef }, 5 => { 2 => undef, 3 => undef }, );
So now, to see if X requires Y, you can just do exists $deps{$X}->{$Y}, or to list the deps (1 level) do keys %{$deps{$X}} . From there you can loop through listing dependencies or make a recursive rountine to find all levels (but be very careful of the cyclic deps).

To build the above data structure, it could just be something like:
my %deps; while(<STDIN>){ my @cols = split; my $task = shift @cols; $deps{$task}->{$_} = undef for @cols; # or another way: %{$deps{$task}} = map { $_ => undef } @cols; }

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: note [id://484758]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others learning in the Monastery: (3)
As of 2024-04-19 01:55 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found