我是netgraph的作者和维护者,netgraph 是一个用于创建网络可视化的 Python 库。N我目前正在尝试优化一个例程,该例程计算每条边都有定义长度的网络的一组节点位置。可以在此处找到示例。
该例程的核心是scipy.optimize.minimize计算使节点之间的总距离最大化的位置:
def cost_function(positions):
return 1. / np.sum((pdist(positions.reshape((-1, 2))))**power)
result = minimize(cost_function, initial_positions.flatten(), method='SLSQP',
jac="2-point", constraints=[nonlinear_constraint])
Run Code Online (Sandbox Code Playgroud)
positions是 (x, y) 元组的(已解开的)numpy 数组。power是一个较小的数字,限制了大距离的影响(以鼓励紧凑的节点布局),但出于本问题的目的,可以假设为 1。pdist是 中的成对距离函数scipy.spatial。最小化(/最大化)使用以下非线性约束进行约束:
lower_bounds = ... # (squareform of an) (N, N) distance matrix of the sum of node sizes (i.e. nodes should not overlap)
upper_bounds = ... # (squareform of an) (N, N) distance matrix constructed from the given …Run Code Online (Sandbox Code Playgroud) 我正在尝试按照此处概述的步骤在我的计算机上安装 Python 3 中的 osmnx 包https://geoffboeing.com/2017/02/python-getting-started/。步骤是:
C:\Anaconda。由于我使用的是大学计算机,因此我无法执行此操作。但是,Anaconda 已安装在这些计算机上,路径为C:\Program Files \Anaconda3.conda update -n base conda。然而,这并没有成功,因为我没有“对目标环境的写权限”( C:\Program Files \Anaconda3)。conda config --prepend channels conda-forge跑得很好。conda create -n ox -c conda-forge osmnx jupyterlab并conda activate ox运行良好。OSMnx 和 jupyterlab 在 Anaconda Navigator>Environments>ox>installed 中列出。jupyter lab,但这给出了以下错误。我对这个巨大的引用感到抱歉,但我不知道如何解释其中的任何一个:(ox) C:\Users\bm17652>jupyter lab
[I 15:47:48.265 LabApp] Writing notebook server cookie secret to C:\Users\bm17652\AppData\Roaming\jupyter\runtime\notebook_cookie_secret
Traceback (most recent call …Run Code Online (Sandbox Code Playgroud)