--
You received this message because you are subscribed to the Google Groups "pulp-or-discuss" group.
To unsubscribe from this group and stop receiving emails from it, send an email to pulp-or-discuss+unsubscribe@googlegroups.com.
To post to this group, send email to pulp-or-discuss@googlegroups.com.
Visit this group at http://groups.google.com/group/pulp-or-discuss.
For more options, visit https://groups.google.com/d/optout.
To unsubscribe from this group and stop receiving emails from it, send an email to pulp-or-discu...@googlegroups.com.
To post to this group, send email to pulp-or...@googlegroups.com.
Visit this group at http://groups.google.com/group/pulp-or-discuss.
For more options, visit https://groups.google.com/d/optout.
--
Stuart MitchellPhD Engineering ScienceExtraordinary Freelance Programmer and Optimisation Guru
--
You received this message because you are subscribed to the Google Groups "pulp-or-discuss" group.
To unsubscribe from this group and stop receiving emails from it, send an email to pulp-or-discu...@googlegroups.com.
To post to this group, send email to pulp-or...@googlegroups.com.
To unsubscribe from this group and stop receiving emails from it, send an email to pulp-or-discuss+unsubscribe@googlegroups.com.
To post to this group, send email to pulp-or-discuss@googlegroups.com.
Visit this group at https://groups.google.com/group/pulp-or-discuss.
To unsubscribe from this group and stop receiving emails from it, send an email to pulp-or-discuss+unsubscribe@googlegroups.com.
To post to this group, send email to pulp-or-discuss@googlegroups.com.
Visit this group at https://groups.google.com/group/pulp-or-discuss.
For more options, visit https://groups.google.com/d/optout.
# each constraint is: |pixel-expected-value - pixel-actual-value| < allowed_diff_between_targe_pixel_and_result
# which translates to 2 constraints:
# 1) sum(lines coefficients through pixel) < pixel-expected-value + allowed_diff_between_targe_pixel_and_result
# 2) sum(lines coefficients through pixel) < pixel-expected-value - allowed_diff_between_targe_pixel_and_result
for pixel_low_res_ind in range(num_of_low_res_pixels):
print("setting constraint for low res pixel # ", pixel_low_res_ind, " out of ", num_of_low_res_pixels)
pixel_low_res_x, pixel_low_res_y = ind2sub(image_low_res.shape, pixel_low_res_ind)
constraint_1_name = "Constraint 1 for pixel " + str(pixel_low_res_ind)
constraint_2_name = "Constraint 2 for pixel " + str(pixel_low_res_ind)
#TODO this should be done for only the lines that pass through the pixel. how shall I know which ones?
constraint_predicate_1 = lpSum([line_variables[str(j)] * lines_to_low_res_matrix[j][pixel_low_res_ind] for j in range(num_of_lines)]) \
<= image_low_res[pixel_low_res_x][pixel_low_res_y] + allowed_diff_between_targe_pixel_and_result
# constraint_predicate_2 = lpSum([line_variables["line " + str(j)] * lines_to_low_res_matrix[j][pixel_low_res_ind] for j in range(num_of_lines)
# >= image_low_res[pixel_low_res_x][pixel_low_res_y] - allowed_diff_between_targe_pixel_and_result
problem += constraint_predicate_1, constraint_1_name
"Constraint 1 for pixel " + str(pixel_low_res_ind)
"Constraint 1 for pixel {0}".format(pixel_low_res_ind)
--
You received this message because you are subscribed to a topic in the Google Groups "pulp-or-discuss" group.
To unsubscribe from this topic, visit https://groups.google.com/d/topic/pulp-or-discuss/p1N2fkVtYyM/unsubscribe.
To unsubscribe from this group and all its topics, send an email to pulp-or-discuss+unsubscribe@googlegroups.com.
To post to this group, send email to pulp-or-discuss@googlegroups.com.
Visit this group at https://groups.google.com/group/pulp-or-discuss.
For more options, visit https://groups.google.com/d/optout.
for v in V:
prob += lpSum([x[(v1, v2)] for (v1, v2) in A if v2 == v]) - lpSum([x[(v2, v1)] for (v2, v1) in A if v2 == v]) == 0
 I'd be glad if you could help me, thanks a lot.Â
To unsubscribe from this group and stop receiving emails from it, send an email to pulp-or...@googlegroups.com.
To post to this group, send email to pulp-or...@googlegroups.com.
Visit this group at https://groups.google.com/group/pulp-or-discuss.
For more options, visit https://groups.google.com/d/optout.
--
Hello Daniela,
This is more of a python performance issue.
In every iteration, you’re running two list comprehensions.
What you should do is first prepare your data that lets you do less iterations inside the loop (i.e., none).
For example:
# A_index_v1 => all arcs that start in node v
# A_index_v2 => all arcs that finish in node v
A = [(2, 3), (2, 6), (1, 2), (1, 3), (2, 5), (2, 7)]
A_index_v1 = {}
A_index_v2 = {}
for (v1, v2) in A:
if v1 not in A_index_v1:
A_index_v1[v1] = []
if v2 not in A_index_v2:
A_index_v2[v2] = []
A_index_v1[v1].append((v1, v2))
A_index_v2[v2].append((v1, v2))
for v in V:
prob += lpSum([x[_tup] _tup in A_index_v2[v]]) - lpSum([x[_tup] _tup in A_index_v1[v]) == 0
Alternative using the pytups
library:
import pytups as pt
A_index_v1 = pt.TupList(A).to_dict(result_col=[0, 1], indices=[0])
A_index_v2 = pt.TupList(A).to_dict(result_col=[0, 1], indices=[1])
for v in V:
prob += lpSum([x[_tup] _tup in A_index_v2[v]]) - lpSum([x[_tup] _tup in A_index_v1[v]) == 0
Franco