@@ -91,7 +91,7 @@ def add_vessel(tree, **kwargs):
9191 nonconvex_sampling = kwargs .pop ('nonconvex_sampling' , 10 )
9292 homogeneous = kwargs .pop ('homogeneous' , True )
9393 use_brute = kwargs .pop ('use_brute' , False )
94- max_iter = kwargs .pop ('max_iter' , 10 )
94+ max_iter = kwargs .pop ('max_iter' , 100 )
9595 return_cost = kwargs .pop ('return_cost' , False )
9696 #defualt_threshold = ((tree.domain.mesh.volume ** (1/3)) /
9797 # (tree.n_terminals ** threshold_exponent)) + tree.data[0, 21]*2.0
@@ -218,8 +218,8 @@ def callback(xk):
218218 #plt.colorbar(label='Function values')
219219 #plt.show()
220220 cons = [{"type" : "ineq" , "fun" : lambda a : 1 - a [0 ] - a [1 ]}]
221- result = minimize (cost , x0 , bounds = [(0 , 1.0 ), (0 , 1.0 )], callback = callback ,
222- options = {'maxiter' :max_iter })
221+ result = minimize (cost , x0 , bounds = [(0.05 , 0.95 ), (0.05 , 0.95 )], callback = callback ,
222+ options = {'maxiter' :max_iter }, constraints = cons , method = "COBYLA" )
223223 #print('SOLUTION: {}'.format(result.x))
224224 #print('SOLUTION FUN: {}'.format(result.fun))
225225 bifurcation_point = triad (result .x )
@@ -1901,10 +1901,10 @@ def cost(x, func=tree_cost_2, d_min=d_min, terminal=terminal,
19011901 scale = tree_scale ,connectivity = tree .connectivity ):
19021902 x = triad (x )
19031903 #dists = close_exact_point(lines, x)
1904- # dists = numpy.array([numpy.linalg.norm(lines[0, 0:3] - x),
1905- # numpy.linalg.norm(lines[0, 3:6] - x),
1906- # numpy.linalg.norm(lines[1, 3:6] - x)])
1907- # triad_penalty = numpy.max([0.0, -1.0 * numpy.min(dists - d_min)])/d_min * penalty
1904+ dists = numpy .array ([numpy .linalg .norm (lines [0 , 0 :3 ] - x ),
1905+ numpy .linalg .norm (lines [0 , 3 :6 ] - x ),
1906+ numpy .linalg .norm (lines [1 , 3 :6 ] - x )])
1907+ triad_penalty = numpy .max ([0.0 , - 1.0 * numpy .min (dists - d_min )])/ d_min * penalty
19081908 #[TODO] angle penalty
19091909 #[TODO] require that resulting parent vessel is at least a certain length? remove buffer region around triad
19101910 # points
@@ -1924,7 +1924,7 @@ def cost(x, func=tree_cost_2, d_min=d_min, terminal=terminal,
19241924 #assert results > tree_scale, '{} results < {} tree_scale'.format(results, tree_scale)
19251925 #return (((np.clip(numpy.nan_to_num(results - scale, nan=2*scale+penalty), 0, 2*scale+penalty) + triad_penalty))/(scale+penalty))# + 1.0
19261926 #return -1/np.clip(numpy.nan_to_num(results - scale, nan=2*scale+penalty), 0, 2*scale+penalty)
1927- return - 1 / np .clip (numpy .nan_to_num (results , nan = 2 * scale + penalty ), 0 , 2 * scale + penalty )
1927+ return - 1 / np .clip (numpy .nan_to_num (results + triad_penalty , nan = 2 * scale + penalty ), 0 , 2 * scale + penalty )
19281928 #return results
19291929 #return results
19301930 #return value
0 commit comments