Hi,
Let me try to see if I can help:
> trials = []
>
> @TaskGenerator
> def runACO(arg,ants,iterations):
> cmd = "/home/hamiltont/AntHybrid --%s -m %d -i %d" % \
> (arg, ants, iterations)
> import shlex, subprocess
> cargs = shlex.split(cmd)
> output,error = subprocess.Popen(cargs,
> stdout=subprocess.PIPE,
> stderr=subprocess.PIPE).communicate()
> return result
This looks good
> for file in os.dirlist(data_files):
> # Many, many for loops later to create arg
> # ...
> #
> results = [runACO(arg,ants,iterations) for i in range(0,rounds)]
OK so far.
The following needs to go into Tasks too:
> # I need to do this for each result
> score = result.split(",")[0]
> time = result.split(",")[1]
> scores.append(float(score))
> times.append(float(time))
>
> # This is my main issue - I only want to store the median values for each
> run of 0...rounds
> score_best = sorted(scores)[:-1][0]
> score_median = getMedian(scores)
> time_median = getMedian(times)
>
> trials.append({'best':score_best,'median':score_median,'ants':ants,'iter':it
> erations % Omitted rest % })
@TaskGenerator:
def summarize(results, ants)
score = result.split(",")[0]
time = result.split(",")[1]
scores.append(float(score))
times.append(float(time))
score_best = sorted(scores)[:-1][0]
score_median = getMedian(scores)
time_median = getMedian(times)
return {'best':score_best,'median':score_median,'ants':ants}
trials = [summarize(r, ants) for r in results]
*
Of course, if you really don't care to have all the results, then this might
be part of runACO:
### NOTE: NOT A TaskGenerator
def summarize(results, ants)
score = result.split(",")[0]
time = result.split(",")[1]
scores.append(float(score))
times.append(float(time))
score_best = sorted(scores)[:-1][0]
score_median = getMedian(scores)
time_median = getMedian(times)
return {'best':score_best,'median':score_median,'ants':ants}
@TaskGenerator
def runACO(arg,ants,iterations):
cmd = "/home/hamiltont/AntHybrid --%s -m %d -i %d" % \
(arg, ants, iterations)
import shlex, subprocess
cargs = shlex.split(cmd)
output,error = subprocess.Popen(cargs,
stdout=subprocess.PIPE,
stderr=subprocess.PIPE).communicate()
return summarize(result,ants)
*
HTH
--
Luis Pedro Coelho | Institute for Molecular Medicine |
http://luispedro.org