Skip to content

Commit 4fa69c5

Browse files
committed
add write_population
1 parent 91b5a51 commit 4fa69c5

File tree

5 files changed

+20
-29
lines changed

5 files changed

+20
-29
lines changed

example/client.jl

Lines changed: 1 addition & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -23,19 +23,9 @@ par = Parameter(budget=400, evaluation_server_num=2, control_server_ip_port="192
2323
sol = zoo_min(obj, par)
2424
# print the Solution object
2525
sol_print(sol)
26-
f = open("result.txt", "w")
2726
positive_data = take!(par.positive_data)
2827
negative_data = take!(par.negative_data)
29-
write(f, "########################################\n")
30-
write(f, "positive_data: \n")
31-
for sol in positive_data
32-
sol_write(sol, f)
33-
end
34-
write(f, "########################################\n")
35-
write(f, "negative_data: \n")
36-
for sol in negative_data
37-
sol_write(sol, f)
38-
end
28+
write_population("population.txt", positive_data, negative_data)
3929
# visualize the optimization progress
4030
# history = get_history_bestsofar(obj)
4131
# plt[:plot](history)

src/ZOOclient.jl

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ export Dimension, dim_print
66
export Objective, get_history_bestsofar
77
export zoo_min
88
export Parameter, print_population, get_positive_data, get_negative_data
9-
export Solution, sol_print, sol_equal, sol_write
9+
export Solution, sol_print, sol_equal, sol_write, write_population
1010

1111
export zoolog
1212
export rng, my_precision, set_seed, set_precision

src/ZOOclient/algos/asracos/asracos_opt.jl

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -132,6 +132,7 @@ function asracos_updater!(asracos::ASRacos, budget, ub, finish)
132132
f = open(output_file, "w")
133133
end
134134
br = false
135+
135136
while(t <= budget)
136137
sol = take!(asracos.result_set)
137138
push!(history, sol.value)

src/ZOOclient/parameter.jl

Lines changed: 1 addition & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,7 @@ type Parameter
3333
# result
3434
positive_data
3535
negative_data
36+
3637
function Parameter(; algorithm="asracos", budget=0, init_sample=Nullable(),
3738
time_limit=Nullable{Int64}(), precision=Nullable(),
3839
uncertain_bits=Nullable{Int64}(), train_size=0, positive_size=0, negative_size=0,
@@ -84,19 +85,3 @@ function get_negative_data(parameter)
8485
result = take!(parameter.negative_data)
8586
return result
8687
end
87-
88-
function write_population(parameter, file)
89-
f = open(file, "w")
90-
positive_data = get_positive_data(parameter)
91-
negative_data = get_negative_data(parameter)
92-
write(f, "########################################\n")
93-
write(f, "positive_data: \n")
94-
for sol in positive_data
95-
sol_write(sol, f)
96-
end
97-
write(f, "########################################\n")
98-
write(f, "negative_data: \n")
99-
for sol in negative_data
100-
sol_write(sol, f)
101-
end
102-
end

src/ZOOclient/solution.jl

Lines changed: 16 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -63,7 +63,22 @@ function sol_print(sol)
6363
zoolog("x: $(sol.x)")
6464
end
6565

66-
function sol_write(sol, f)
66+
function sol_write(f, sol)
6767
write(f, "value=$(sol.value)\n")
6868
write(f, "x=$(sol.x)\n")
69+
end
70+
71+
function write_population(filename, positive_data, negative_data)
72+
f = open(filename, "w")
73+
write(f, "########################################\n")
74+
write(f, "positive_data: \n")
75+
for sol in positive_data
76+
sol_write(f, sol)
77+
end
78+
write(f, "########################################\n")
79+
write(f, "negative_data: \n")
80+
for sol in negative_data
81+
sol_write(f, sol)
82+
end
83+
close(f)
6984
end

0 commit comments

Comments
 (0)