- android - 多次调用 OnPrimaryClipChangedListener
- android - 无法更新 RecyclerView 中的 TextView 字段
- android.database.CursorIndexOutOfBoundsException : Index 0 requested, 光标大小为 0
- android - 使用 AppCompat 时,我们是否需要明确指定其 UI 组件(Spinner、EditText)颜色
最近,我在 plotly 上遇到了很多困难,似乎我驯服了它来满足我的需求,直到这个问题出现。我正在使用 or-tools 求解器解决作业车间问题,并使用plotly 创建交互式甘特图。一切都很顺利,但还有一件事让它变得完美。我不想简单地绘制这个数学问题的最终结果,还想绘制中间步骤,这意味着求解器在找到最佳解决方案之前找到的所有解决方案。 Or-Tools 在其网站上提供了解决方案打印机的代码,这满足了我的要求:它打印找到的中间解决方案。我面临的唯一问题是:我无法用plotly 绘制中间解决方案。
下面你可以看到Or-Tools提供的代码,我针对我的问题修改了它,它工作得很好。它打印中间解决方案。一旦求解器找到最佳解决方案,它就会继续执行我的绘图函数并绘制甘特图。我尝试将绘图函数放在 VarArraySolutionPrinter 类的 on_soltuion_callback 函数中。发生了什么,它绘制找到的第一个解决方案并停止代码的执行。有没有一种方法可以绘制我的求解器在实现最优的过程中找到的所有解决方案?
这是来自 or-tools 的代码:来源:https://developers.google.com/optimization/cp/cp_solver
from __future__ import absolute_import
from __future__ import division
from __future__ import print_function
from ortools.sat.python import cp_model
class VarArraySolutionPrinter(cp_model.CpSolverSolutionCallback):
"""Print intermediate solutions."""
def __init__(self, variables):
cp_model.CpSolverSolutionCallback.__init__(self)
self.__variables = variables
self.__solution_count = 0
def on_solution_callback(self):
self.__solution_count += 1
for v in self.__variables:
print('%s=%i' % (v, self.Value(v)), end=' ')
print()
def solution_count(self):
return self.__solution_count
def SearchForAllSolutionsSampleSat():
"""Showcases calling the solver to search for all solutions."""
# Creates the model.
model = cp_model.CpModel()
# Creates the variables.
num_vals = 3
x = model.NewIntVar(0, num_vals - 1, 'x')
y = model.NewIntVar(0, num_vals - 1, 'y')
z = model.NewIntVar(0, num_vals - 1, 'z')
# Create the constraints.
model.Add(x != y)
# Create a solver and solve.
solver = cp_model.CpSolver()
solution_printer = VarArraySolutionPrinter([x, y, z])
status = solver.SearchForAllSolutions(model, solution_printer)
print('Status = %s' % solver.StatusName(status))
print('Number of solutions found: %i' %solution_printer.solution_count())
SearchForAllSolutionsSampleSat()
最佳答案
我终于明白了。我只是深度复制了我的对象并绘制了对象的深度复制版本。
关于python - 如何用plotly绘制or-tools的中间解,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/58429875/
我想使用 Google OR-Tools 解决车辆路径问题 (vrp),但使用与提供的元启发式不同的元启发式,它们是:贪婪下降、引导局部搜索、模拟退火、禁忌搜索和目标禁忌搜索。这就是此处文档中的解释:
对于 or-tools 中的 VRP,有没有办法让车辆从某些固定位置开始,但允许任意结束位置? 文档 https://developers.google.com/optimization/routin
我创建了新文件“Makefile.local”,并将“WINDOWS_SCIP_DIR=c:/Program Files/SCIPOptSuite”添加到文件中。 SCIP也编译成功,文件路径正确。
这个问题在这里已经有了答案: What are the Android SDK build-tools, platform-tools and tools? And which version sh
我正在尝试在 OR-TOOLS RL VRPTW 问题中强制执行位移长度约束。类次时长是车辆在服务中的总时间(运输 + 等待 + 服务),从到达第一个位置到离开最后一个位置。 它看起来像一个 Time
我正在尝试在 OR-TOOLS RL VRPTW 问题中强制执行位移长度约束。类次时长是车辆在服务中的总时间(运输 + 等待 + 服务),从到达第一个位置到离开最后一个位置。 它看起来像一个 Time
命令后: go build 显示错误: go tool: no such tool "link" 详细信息:我的系统是 windows 10 -> 64 位 go version: 1.11.5
我已经在我的 Ubuntu 桌面上安装了 go,在我关闭计算机之前它运行良好。 现在,当我启动我的机器并继续我的项目工作时,我明白了 $ go build go tool: no such tool
我正在为 Job-Shop 问题实现一个类似的解决方案,但有一个区别:我不知道必须执行每项任务的机器。解决这个问题也是问题的一部分。事实上,我们可以说,我正在尝试解决护士问题和工作车间问题的组合。 更
我知道Spring Tool Suite是为Spring开发而优化的,而Groovy / Grails是为Groovy / Grails开发的而优化的。 Groovy / Grails开发人员是否愿意
在 Chrome Dev Tools 中,我可以 Shift+单击检查器中的颜色来更改格式(Hex -> RGB -> HSL)。我可以在 Firefox Dev Tools 中做到这一点吗?我可以在
我目前正在评估谷歌或工具,只是注意到它本身并不是真正的求解器,而主要是与其他求解器的接口(interface)。我想知道的是这个框架使用哪些求解器来解决约束和路由问题。 我已经看透了https://d
我正在尝试使用命令 firebase init 初始化 Firebase 项目,但我收到消息 Error: Command requires authentication, please run fi
是什么决定了工具进入特定目录?例如,adb 位于 tools/但已移至 platform-tools/。为什么他们不能在同一个目录中? 最佳答案 platform-tools/ 主要包含从 Windo
我刚刚将 Android Studio 更新到了 2.3 版(金丝雀版)和最后的构建工具 'com.android.tools.build:gradle:2.3.0-alpha1' 以及当我打开布局并
我一直在使用 SQL Server 项目来管理数据库的结构。 首先我创建了项目,然后导入了一个数据库。 然后,当我需要更改架构时,比如更改字段名称,我会在 SQL Server 项目中进行,然后使用架
我正在尝试使用 Google OR-Tools 的 CP-Solver 解决问题。是否可以添加这样的约束:x1 异或 x2 异或 x3 == 0提前致谢。 最佳答案 AddBoolXOr of n 个
我需要为此获取源代码,但不幸的是,我无法在 jquerytools.org 上找到它的链接。该站点上的论坛也已关闭。有谁知道我可以从哪里获得这个来源或取消缩小它? 谢谢,罗布 最佳答案 你有没有试过继
我需要为此获取源代码,但不幸的是,我无法在 jquerytools.org 上找到它的链接。该站点上的论坛也已关闭。有谁知道我可以从哪里获得这个来源或取消缩小它? 谢谢,罗布 最佳答案 你有没有试过继
我正在使用Spring Tool Suite: 版本:3.9.0.RELEASE 建立编号:201707061903 平台:Eclipse Neon.3(4.6.3) 并安装了Gradle插件: Bu
我是一名优秀的程序员,十分优秀!