自托管服务客户端 API 参考#

客户端#

服务客户端#

class cuopt_sh_client.CuOptServiceSelfHostClient(
ip: str = '0.0.0.0',
port: str = '5000',
use_https: bool = False,
self_signed_cert='',
polling_interval=1,
request_excess_timeout=None,
only_validate=False,
polling_timeout=600,
timeout_exception=True,
)#

此版本的 CuOptServiceClient 是与 cuOpt 核心服务的自托管版本交互的接口。此客户端允许用户在特定的 IP 地址和端口上调用 cuOpt 服务的自托管实例。

它与托管服务客户端的接口非常相似,但它没有实现与 NVIDIA 云函数交互所需的大多数托管服务特定功能。

参数:
  • ip (str) – cuOpt 服务的 IP 地址。默认为 0.0.0.0

  • port (str) – cuOpt 服务的端口。默认为 5000。

  • use_https (boolean) – 使用 HTTPS 以安全方式与服务器通信。

  • self_signed_cert (str) – 自签名证书的完整路径。如果是标准证书,则无需提供任何内容。

  • polling_interval (int) – 连续轮询尝试之间的持续时间(秒)。默认为 1。

  • request_excess_timeout (int) – 注意:已弃用,请改用 polling_timeout

  • only_validate (boolean) – 仅验证输入。默认为 False。

  • polling_timeout (int) – 客户端在退出并返回请求 ID 之前轮询结果的时间(秒)。可以在调用 repoll() 时再次轮询请求 ID。如果设置为 None,客户端将永远不会超时,并将无限期地轮询。默认为 600。

  • timeout_exception (boolean) – 如果为 True,则如果在 polling_timeout 秒过去后仍未返回解决方案,客户端将返回 TimeoutError 异常。异常的值包含 JSON,其中提供了请求 ID,以便可以调用 repoll() 再次轮询结果。如果为 False,客户端将返回一个包含 repoll 信息的字典,而不会引发异常。默认为 True。

delete(
id,
running=None,
queued=None,
cached=None,
)#

按 ID 删除缓存的条目或按 ID 中止作业。

参数:
  • id (str) – 标识要删除的缓存条目或作业的 uuid。通配符 ID ‘*’ 将匹配所有 uuid(按 ‘running’、‘queued’ 和 ‘cached’ 筛选)。

  • running (bool) – 如果设置为 True,且 ‘id’ 是当前正在运行的作业,则请求将被中止。如果 ‘id’ 是特定的 uuid 且 ‘queued’ 和 ‘cached’ 均未指定,则默认为 True,否则为 False。

  • queued (bool) – 如果设置为 True,且 ‘id’ 是当前已排队的作业,则请求将被中止。如果 ‘id’ 是特定的 uuid 且 ‘running’ 和 ‘cached’ 均未指定,则默认为 True,否则为 False。

  • cached (bool) – 如果设置为 True,且 ‘id’ 是缓存的数据条目,则请求将被中止。如果 ‘id’ 是特定的 uuid 且 ‘running’ 和 ‘queued’ 均未指定,则默认为 True,否则为 False。

get_LP_solve(
cuopt_data_models,
solver_config=<solver_settings.solver_settings.SolverSettings object>,
cache=False,
response_type='obj',
filepath=False,
output='',
)#

获取给定问题的线性规划解决方案。

参数:
  • cuopt_data_models

    注意 - 批处理模式仅在 LP 中受支持,在 MILP 中不受支持

    mps 或 json/dict/DataModel 的文件路径,由 cuopt_mps_parser/list[mps 文件路径]/list[dict]/list[DataModel] 返回。

    对于单个问题,输入应为 mps/json 文件路径、/DataModel(由 cuopt_mps_parser 返回)/ json 文件路径/ 字典。

    对于批处理问题,输入应为 mps 文件路径列表/ DataModel 列表(由 cuopt_mps_parser 返回)/ 字典列表。

    要使用缓存的 cuopt 问题数据,输入应为标识缓存数据 reqId 的 uuid。

  • solver_config (SolverSettings objectDict) – 包含求解器设置,包括公差值。有关求解器设置的详细信息,请参阅 LP 文档。

  • response_type (str) – 如果响应应作为字典返回,请选择 “dict”,如果响应应作为 Solution 对象返回,请选择 “obj”。默认为 “obj”

  • filepath (boolean) – 指示 cuopt_problem_json_data 是服务器数据目录下 cuopt 数据文件的相对路径。数据目录在服务器启动时指定(有关更多详细信息,请参阅服务器文档)。默认为 False。

  • output (str) – 结果文件的可选名称。如果服务器已配置为将结果写入文件,并且结果的大小大于配置的限制,则服务器会将结果写入服务器结果目录下具有此名称的文件中(有关更多详细信息,请参阅服务器文档)。如果 ‘filepath’ 为 True,则默认为基于路径的名称;如果 ‘filepath’ 为 False,则默认为 uuid。

  • Returns (dictSolution object.)

get_optimized_routes(
cuopt_problem_json_data,
filepath=False,
cache=False,
output='',
)#

获取给定问题的优化路径规划解决方案。

参数:
  • cuopt_problem_json_data (dictstr) – 这是问题数据(字典形式),或包含问题数据的 JSON 文件的路径,或缓存的 cuopt 问题数据的 reqId。有关此字典的结构,请参阅服务器文档。

  • filepath (boolean) – 指示 cuopt_problem_json_data 是服务器数据目录下 cuopt 数据文件的相对路径。数据目录在服务器启动时指定(有关更多详细信息,请参阅服务器文档)。默认为 False。

  • output (str) – 结果文件的可选名称。如果服务器已配置为将结果写入文件,并且结果的大小大于配置的限制,则服务器会将结果写入服务器结果目录下具有此名称的文件中(有关更多详细信息,请参阅服务器文档)。如果 ‘filepath’ 为 True,则默认为基于路径的名称;如果 ‘filepath’ 为 False,则默认为 uuid。

repoll(data, response_type='obj')#

当之前的命令导致超时时,轮询结果。请求 ID 在原始调用的结果中以 JSON 形式返回。

参数:
  • data (str) – 标识原始请求的 uuid。为了向后兼容,data 也可以是一个字典,其中包含键 ‘reqId’,值为 uuid。

  • response_type (str) – 对于 LP 问题,如果响应应作为字典返回,请选择 “dict”,如果响应应作为 Solution 对象返回,请选择 “obj”。默认为 “obj”。对于 VRP 问题,response_type 将被忽略,并且始终返回 dict。

LP 支持类#

class data_model.DataModel(*args: Any, **kwargs: Any)#

初始化 DataModel,它表示线性规划。

标准形式表示遵循此处维基文章中的描述:https://en.wikipedia.org/wiki/Linear_programming#Standard_form。换句话说,此结构存储用于表示以下 LP 方程的所有信息:最小化

dot(c, x)

约束条件

matmul(A, x) (= 或 >= 或)<= b

其中

x : 决策变量

c : 目标系数

A : 约束矩阵

b : 约束界限

其中

n = 变量数

m = 约束数

x = n 维向量

c = n 维向量

A = mxn 维稀疏矩阵

b = m 维向量

注释

默认情况下,这假定为目标最小化。目前,我们不支持最大化,如果需要,请提出问题。

目标值可以相应地缩放和偏移:objective_scaling_factor * (dot(c, x) + objective_offset),请参阅 set_objective_scaling_factor()set_objective_offset() 方法。

示例

最小化

cost = 0.2 * VAR1 + 0.1 * VAR2

约束条件

3 * VAR1 + 4 * VAR2 <= 5.4

2.7 * VAR1 + 10.1 * VAR2 <= 4.9

0 <= VAR1 <= 2

0 <= VAR2 <= inf

>>> from cuopt import linear_programming
>>>
>>> import numpy as np
>>>
>>> data_model = linear_programming.DataModel()
>>>
>>> # Set the CSR matrix representation, for more information about CSR
>>> # checkout:
>>> # https://docs.nvda.net.cn/cuda/cusparse/index.html#compressed-sparse-row-csr # noqa
>>>
>>> # Define the different np.array for the CSR representation
>>> # The 4 values of the constraint matrix (A)
>>> A_values = np.array([3.0, 4.0, 2.7, 10.1], dtype=np.float64)
>>>
>>> # The CSR index vector
>>> # Here we associate each value in the A_values to its variable index
>>> # First value correspond to the first variable
>>> # (3.0 -> variable[*0*], constraint[0])
>>> # Second value correspond to the second variable
>>> # (4.0 -> variable[*1*], constraint[0])
>>> # Third value correspond to the first variable
>>> # (2.7 -> variable[*0*], constraint[1])
>>> # Fourth value correspond to the second variable
>>> # (10.1 -> variable[*1*], constraint[1])
>>> A_indices = np.array([0, 1, 0, 1], dtype=np.int32)
>>>
>>> # The CSR offset vector
>>> # Here we specify the range of values for each constraint
>>> # [0, 2) corresponds to the range of values for the first constraints,
>>> # here [0:3.0, 1:4.0]
>>> # [2, 4) corresponds to the range of values for the second constraint,
>>> # here [1:2.7, 2:10.1]
>>> A_offsets = np.array([0, 2, 4], dtype=np.int32)
>>>
>>> data_model.set_csr_constraint_matrix(A_values, A_indices, A_offsets)
>>>
>>> # Set the constraint bounds (b / right-hand side) array
>>> b = np.array([5.4, 4.9], dtype=np.float64)
>>> data_model.set_constraint_bounds(b)
>>>
>>> # Set the objective coefficient (c) array.
>>> c = np.array([0.2, 0.1], dtype=np.float64)
>>> data_model.set_objective_coefficients(c)
>>>
>>> # Set the constraints/rows equalities, either using the row_type format
>>> # or by directly setting the bounds
>>>
>>> # Method 0: constraints/rows type
>>> # Set both constraints/rows to less-than (<=)
>>> row_types = np.array(['L', 'L'])
>>> data_model.set_row_types(row_types)
>>>
>>> # Method 1: directly set bounds
>>> # Set lower bounds to -infinity and upper bounds to b
>>> constraint_lower_bounds = np.array([np.NINF, np.NINF],
>>>                                       dtype=np.float64)
>>> constraint_upper_bounds = np.array(b, dtype=np.float64)
>>> data_model.set_constraint_lower_bounds(constraint_lower_bounds)
>>> data_model.set_constraint_upper_bounds(constraint_upper_bounds)
>>>
>>>
>>> # Set variable lower and upper bounds
>>> variable_lower_bounds = np.array([0.0, 0.0], dtype=np.float64)
>>> variable_upper_bounds = np.array([2.0, np.PINF], dtype=np.float64)
>>> data_model.set_variable_lower_bounds(variable_lower_bounds)
>>> data_model.set_variable_upper_bounds(variable_upper_bounds)
get_ascii_row_types()#

获取转换为 numpy.array(int8 类型(ASCII 值))的每行(约束)的类型。

get_constraint_bounds()#

以 float64 类型 numpy.array 形式获取约束界限(b / 右侧)。

get_constraint_lower_bounds()#

以 float64 类型 numpy.array 形式获取约束下界。

get_constraint_matrix_indices()#

以 int 类型 numpy.array 形式获取约束矩阵的 CSR 表示的索引。

get_constraint_matrix_offsets()#

以 int 类型 numpy.array 形式获取约束矩阵的 CSR 表示的索引。

get_constraint_matrix_values()#

以 float64 类型 numpy.array 形式获取约束矩阵的 CSR 表示的值。

get_constraint_upper_bounds()#

以 float64 类型 numpy.array 形式获取约束上界。

get_initial_dual_solution()#

以 float64 类型 numpy.array 形式获取初始对偶解。

get_initial_primal_solution()#

以 float64 类型 numpy.array 形式获取初始原始解。

get_objective_coefficients()#

以 float64 类型 numpy.array 形式获取 objective_coefficients (c)。

get_objective_offset()#

以 float64 形式获取目标函数的偏移量。

get_objective_scaling_factor()#

以 float64 形式获取目标函数的缩放因子。

get_row_names()#

以字符串类型 numpy.array 形式获取行名称。

get_row_types()#

以 char8 类型 numpy.array 形式获取每行(约束)的类型。

get_sense()#

以布尔值形式获取优化方向。True 表示最大化目标函数,False 表示最小化。

get_variable_lower_bounds()#

以 float64 类型 numpy.array 形式获取变量 (x) 下界。

get_variable_names()#

以字符串类型 numpy.array 形式获取变量名称。

get_variable_types()#

以 char 类型 numpy.array 形式获取变量类型。

get_variable_upper_bounds()#

以 float64 类型 numpy.array 形式获取变量 (x) 上界。

set_constraint_bounds(b)#

设置约束界限(b / 右侧)数组。

参数:

b (np.array dtype - float64) – 设备浮点数组。

注释

必须在调用求解器之前进行设置。

set_constraint_lower_bounds(constraint_lower_bounds)#

设置约束下界。

参数:

constraint_lower_bounds (np.array dtype - float64) – 设备浮点数组。

注释

如果您设置了行类型,则在调用求解器之前进行设置是可选的,否则,它与上界一起是强制性的。

set_constraint_upper_bounds(constraint_upper_bounds)#

设置约束上界。

参数:

constraint_upper_bounds (np.array dtype - float64) – 设备浮点数组。

注释

如果您设置了行类型,则在调用求解器之前进行设置是可选的,否则,它与下界一起是强制性的。

set_csr_constraint_matrix(A_values, A_indices, A_offsets)#

以 CSR 格式设置约束矩阵 (A)。有关 CSR 的更多信息,请查看:https://docs.nvda.net.cn/cuda/cusparse/index.html#compressed-sparse-row-csr # noqa

参数:
  • A_values (np.array dtype - float64) – 作为设备浮点数组的约束矩阵的 CSR 表示的值。

  • A_indices (np.array dtype - int32) – 作为设备整数数组的约束矩阵的 CSR 表示的索引。

  • A_offsets (np.array dtype - int32) – 作为设备整数数组的约束矩阵的 CSR 表示的偏移量。

注释

必须在调用求解器之前进行设置。

set_initial_dual_solution(initial_dual_solution)#

设置初始对偶解。

参数:

initial_dual_solution (np.array dtype - float64) – 设备浮点数组。

注释

在调用求解器之前进行设置是可选的。

set_initial_primal_solution(initial_primal_solution)#

设置初始原始解。

参数:

initial_primal_solution (np.array dtype - float64) – 设备浮点数组。

注释

在调用求解器之前进行设置是可选的。

set_maximize(maximize)#

将优化方向设置为最大化。

参数:

maximize (bool) – True 表示最大化目标函数,否则为最小化。

注释

在调用求解器之前进行设置是可选的,默认值为 false(最小化)。

set_objective_coefficients(c)#

设置目标系数 (c) 数组。

参数:

c (np.array dtype - float64) – 设备浮点数组。

注释

必须在调用求解器之前进行设置。

set_objective_offset(objective_offset)#

设置目标函数的偏移量 (objective_offset + objective_value)。

参数:

objective_offset (float64) – 要添加的常量 objective_offset。

注释

在调用求解器之前进行设置是可选的。

set_objective_scaling_factor(objective_scaling_factor)#

设置目标函数的缩放因子 (scaling_factor * objective_value)。

参数:

objective_scaling_factor (float64) – 要应用的缩放因子。

注释

在调用求解器之前进行设置是可选的。

set_row_names(row_names)#

设置行名称。

参数:

row_names (np.array dtype - unicode string) – 主机字符串数组。

注释

在调用求解器之前进行设置是可选的。值仅用于生成解决方案的文件。

set_row_types(row_types)#

设置每行(约束)的类型。可能的值为:‘E’ 表示相等 (=):下界和上界约束等于 b;‘L’ 表示小于等于 ( <= ):下界约束等于 -infinity,上界约束等于 b;‘G’ 表示大于等于 ( >= ):下界约束等于 b,上界约束等于 +infinity

参数:

row_types (np.array dtype - unicode string (<U1)) – 主机字符数组。

注释

如果您设置了约束下界和上界,则在调用求解器之前进行设置是可选的,否则是强制性的。如果两者都设置,则优先级转到 set_constraint_lower/upper_bounds。

示例

>>> row_types = np.array(['L', 'L'])
>>> data_model.set_row_types(row_types)
set_variable_lower_bounds(variable_lower_bounds)#

设置变量 (x) 下界。

参数:

variable_lower_bounds (np.array dtype - float64) – 设备浮点数组。

注释

在调用求解器之前进行设置是可选的,所有变量的默认值为 0。

set_variable_names(variables_names)#

设置变量名称。

参数:

variables_names (np.array dtype - unicode string) – 主机字符串数组。

注释

在调用求解器之前进行设置是可选的。值仅用于生成解决方案的文件。

set_variable_types(variable_types)#

设置变量类型。

参数:

variables_types (np.array dtype - unicode string (<U1)) – 主机字符数组。

set_variable_upper_bounds(variable_upper_bounds)#

设置变量 (x) 上界。

参数:

variable_upper_bounds (np.array dtype - float64) – 设备浮点数组。

注释

在调用求解器之前进行设置是可选的,所有变量的默认值为 +infinity。

class solver_settings.SolverSettings#
get_absolute_dual_tolerance()#

获取绝对对偶公差。有关最优公差的更多详细信息,请参阅 set_optimality_tolerance 方法。

返回值:

绝对对偶公差。

返回类型:

float64

get_absolute_gap_tolerance()#

获取绝对间隙公差。有关间隙公差的更多详细信息,请参阅 set_optimality_tolerance 方法。

返回值:

绝对间隙公差。

返回类型:

float64

get_absolute_primal_tolerance()#

获取绝对原始公差。有关最优公差的更多详细信息,请参阅 set_optimality_tolerance 方法。

返回值:

绝对原始公差。

返回类型:

float64

get_dual_infeasible_tolerance()#

获取对偶不可行公差。

返回值:

对偶不可行公差。

返回类型:

float64

get_infeasibility_detection()#

获取检测不可行状态。

返回值:

检测不可行状态。

返回类型:

bool

get_iteration_limit()#

获取迭代限制,如果没有设置,则返回 None。

返回值:

迭代限制。

返回类型:

int 或 None

get_primal_infeasible_tolerance()#

获取原始不可行公差。

返回值:

原始不可行公差。

返回类型:

float64

get_relative_dual_tolerance()#

获取相对对偶公差。有关最优公差的更多详细信息,请参阅 set_optimality_tolerance 方法。

返回值:

相对对偶公差。

返回类型:

float64

get_relative_gap_tolerance()#

获取相对间隙公差。有关间隙公差的更多详细信息,请参阅 set_optimality_tolerance 方法。

返回值:

相对间隙公差。

返回类型:

float64

get_relative_primal_tolerance()#

获取相对原始公差。有关最优公差的更多详细信息,请参阅 set_optimality_tolerance 方法。

返回值:

相对原始公差。

返回类型:

float64

get_solver_mode()#

获取求解器模式。有关求解器模式的更多详细信息,请参阅 set_solver_mode 方法。

返回值:

求解器模式。

返回类型:

Int

get_time_limit()#

获取时间限制(秒),如果没有设置,则返回 None。

返回值:

时间限制。

返回类型:

float 或 None

set_absolute_dual_tolerance(absolute_dual_tolerance)#

设置绝对对偶容差。

参数:

absolute_dual_tolerance (float64) – 绝对对偶容差

注释

有关最优性容差的更多详细信息,请参阅 set_optimality_tolerance 方法。默认值为 1e-4。

set_absolute_gap_tolerance(absolute_gap_tolerance)#

设置绝对间隙容差。

参数:

absolute_gap_tolerance (float64) – 绝对间隙容差

注释

有关间隙容差的更多详细信息,请参阅 set_optimality_tolerance 方法。默认值为 1e-4。

set_absolute_primal_tolerance(
absolute_primal_tolerance,
)#

设置绝对原始容差。

参数:

absolute_primal_tolerance (float64) – 绝对原始容差

注释

有关最优性容差的更多详细信息,请参阅 set_optimality_tolerance 方法。默认值为 1e-4。

set_dual_infeasible_tolerance(
dual_infeasible_tolerance,
)#

设置对偶不可行容差。

参数:

dual_infeasible_tolerance (float64) – 对偶不可行容差。

注释

默认值为 1e-8。较高的值将更快地检测到不可行性,但可能会触发误报。

set_infeasibility_detection(detect)#

如果检测到问题不可行,求解器将检测并退出。

参数:

detect (bool) – True 表示检测不可行性,false 表示忽略它。

注释

默认情况下,求解器检测不可行性。一些被检测为不可行的问题可能会在不同的容差因子下收敛。

set_iteration_limit(iteration_limit)#

设置迭代限制,超过此限制后,求解器将停止并返回当前解。

参数:

iteration_limit (int) – 要设置的迭代限制。

注释

默认情况下,没有迭代限制。出于性能原因,cuOpt 不会持续检查迭代限制,因此,求解器可能会在超过限制的情况下多运行几次迭代。如果与时间限制一起设置,则首先达到的限制将退出。

set_optimality_tolerance(eps_optimal)#

设置原始可行性、对偶可行性和间隙的绝对容差和相对容差。更改此值对精度和运行时间有重大影响。

最优性计算如下

对偶可行性 < absolute_dual_tolerance + relative_dual_tolerance
  • norm_objective_coefficient (l2_norm(c))

原始可行性 < absolute_primal_tolerance
  • relative_primal_tolerance * norm_constraint_bounds (l2_norm(b))

对偶间隙 < absolute_gap_tolerance + relative_gap_tolerance
  • (abs(原始目标) + abs(对偶目标))

如果所有三个条件都成立,则达到最优性。

参数:

eps_optimal (float64) – 最优性容差

注释

默认值为 1e-4。要设置每个绝对容差和相对容差,请使用提供的 setter。

set_primal_infeasible_tolerance(
primal_infeasible_tolerance,
)#

设置原始不可行容差。

参数:

primal_infeasible_tolerance (float64) – 原始不可行容差。

注释

默认值为 1e-8。较高的值将更快地检测到不可行性,但可能会触发误报。

set_relative_dual_tolerance(relative_dual_tolerance)#

设置相对对偶容差。

参数:

relative_dual_tolerance (float64) – 相对对偶容差

注释

有关最优性容差的更多详细信息,请参阅 set_optimality_tolerance 方法。默认值为 1e-4。

set_relative_gap_tolerance(relative_gap_tolerance)#

设置相对间隙容差。

参数:

relative_gap_tolerance (float64) – 相对间隙容差

注释

有关间隙容差的更多详细信息,请参阅 set_optimality_tolerance 方法。默认值为 1e-4。

set_relative_primal_tolerance(
relative_primal_tolerance,
)#

设置相对原始容差。

参数:

relative_primal_tolerance (float64) – 相对原始容差

注释

有关最优性容差的更多详细信息,请参阅 set_optimality_tolerance 方法。默认值为 1e-4。

set_solver_mode(solver_mode)#

设置求解器应在何种模式下运行。该模式将改变求解器内部优化问题的方式。模式选择会极大地影响特定问题的求解速度。鼓励用户测试不同的模式,以查看哪种模式最适合他们的问题。默认情况下,求解器使用 SolverMode.Stable1,这是我们实验中总体最佳的模式。目前,只有三种模式可用:[Stable1、Methodical1、Fast1]

参数:

solver_mode (SolverMode) – 要设置的求解器模式。唯一可能的值为:- SolverMode.Stable1 - SolverMode.Methodical1 - SolverMode.Fast1

注释

目前,我们不提供任何机制来预先知道哪种求解器模式对于特定问题是最佳的。模式描述:Stable1:收敛成功率和速度之间的最佳折衷(对应于之前的 solver_mode 0)Methodical1:通常会导致较慢的单个步骤,但收敛所需的步骤更少(对应于之前的 solver_mode 1)。Fast1:收敛成功率较低,但通常产生最高的速速(新模式,取代之前的 solver_mode 2)。

set_time_limit(time_limit)#

设置时间限制(秒),超过此限制后,求解器将停止并返回当前解。如果与迭代限制一起设置,则首先达到的限制将退出。

参数:

time_limit (float64) – 要设置的时间限制,以秒为单位。

注释

默认情况下,没有时间限制。出于性能原因,cuOpt 不会持续检查时间限制,因此,求解器可能会在超过限制的情况下多运行几毫秒。

class solution.Solution(
primal_solution,
dual_solution,
reduced_cost,
termination_reason,
primal_residual,
dual_residual,
primal_objective,
dual_objective,
gap,
solve_time,
vars,
)#

LP 求解器输出的容器

参数:
  • primal_solution (numpy.array) – LP 问题的原始解

  • dual_solution (numpy.array) – LP 问题的对偶解

  • reduced_cost (numpy.array) – 约简成本。它包含线性约束的对偶乘子。

  • termination_reason (Integer) – 终止原因值。

  • primal_residual (Float64) – 原始残差的 L2 范数:原始不可行性的度量

  • dual_residual (Float64) – 对偶残差的 L2 范数:对偶不可行性的度量

  • primal_objective (Float64) – 原始目标值

  • dual_objective (Float64) – 对偶目标值

  • gap (Float64) – 原始目标和对偶目标之间的差异

  • solve_time (Float64) – 求解时间,以毫秒为单位

  • vars (Dict[str, float64]) – 将每个变量(名称)映射到其值的字典。

get_dual_objective()#

以 float64 形式返回对偶目标。

get_dual_solution()#

以 numpy.array 形式返回对偶解,类型为 float64。

get_lp_stats()#

以字典形式返回收敛统计信息

“primal_residual”: float64

原始不可行性的度量。此量会被减少,直到满足原始容差(请参阅 SolverSettings 原始容差)。

“dual_residual”: float64,

对偶不可行性的度量。此量会被减少,直到满足对偶容差(请参阅 SolverSettings 对偶容差)。

“gap”: float64

原始目标和对偶目标之间的差异。此量会被减少,直到满足间隙容差(请参阅 SolverSettings 间隙容差)。

“reduced_cost”: np.array float64

约简成本,包含线性约束的对偶乘子。

get_primal_objective()#

以 float64 形式返回原始目标。

get_primal_solution()#

以 numpy.array 形式返回原始解,类型为 float64。

get_solve_time()#

以 float64 形式返回引擎求解时间(毫秒)。

get_termination_reason()#

根据 TerminationReason 返回终止原因。

get_vars()#

返回将每个变量(名称)映射到其值的字典。

服务 CLI#

 1usage: cuopt_sh [-h] [-ca] [-f] [-d] [-r] [-q] [-t TYPE] [-ss SOLVER_SETTINGS]
 2                [-o OUTPUT] [-pt POLL_TIMEOUT] [-i IP] [-p PORT] [-s]
 3                [-c SELF_SIGNED_CERT] [-l {critical,error,warning,info,debug}]
 4                [-ov] [-v]
 5                [data ...]
 6
 7Solve a cuOpt problem using a self-hosted service client.
 8
 9positional arguments:
10  data                  Filename, or JSON string containing a request id. Data
11                        may be a cuopt problem or a request id as displayed in
12                        the output from a previous request which timed out. A
13                        cuopt problem must be in a file, but a request id may
14                        be passed in a file or as a JSON string. For VRP:A
15                        single problem file is expected or file_name. For LP:
16                        A single problem file in mps/json format or
17                        file_name.Batch mode is supported in case of mps files
18                        only for LP andnot for MILP, where a list of mpsfiles
19                        can be shared to be solved in parallel.
20
21options:
22  -h, --help            show this help message and exit
23  -ca, --cache          Indicates that the DATA needs to be cached. This does
24                        not solve the problem but stores the problem data and
25                        returns the reqId. The reqId can be used later to
26                        solve the problem. This flag also may be used
27                        alongside the delete argument to delete a cached
28                        entry.(see the server documentation for more detail).
29  -f, --filepath        Indicates that the DATA argument is the relative path
30                        of a cuopt data file under the server's data
31                        directory. The data directory is specified when the
32                        server is started (see the server documentation for
33                        more detail).
34  -d, --delete          Deletes cached data or aborts jobs on the cuOpt
35                        server. The DATA argument may be the specific reqId of
36                        cached data or a job, or it may be the wildcard '*'
37                        which will match any request. If a specific reqId is
38                        given and the -r, -q, and -ca flags are all
39                        unspecified, the reqId will always be deleted if it
40                        exists. If any of the -r, -q, or -ca flags are
41                        specified, a specific reqId will only be deleted if it
42                        matches the specified flags. If the wildard reqId '*'
43                        is given, the -r, -q and/or -ca flags must always be
44                        set explicitly. To flush the job queue, give '*' as
45                        the reqId and specify the -q flag. To delete all
46                        currently running jobs, give '*' as the reqId and
47                        specify the -r flag. To clear the job data cache, give
48                        '*' as the reqId and specify the -ca flag.
49  -r, --running         Aborts a job only if it is running. Should be used
50                        alongside delete argument
51  -q, --queued          Aborts a job only if it is queued. Should be used
52                        alongside delete argument
53  -t TYPE, --type TYPE  The type of problem to solve. Supported options are
54                        VRP and LP (defaults to VRP)
55  -ss SOLVER_SETTINGS, --solver-settings SOLVER_SETTINGS
56                        Filename or JSON string containing solver settings for
57                        LP problem type
58  -o OUTPUT, --output OUTPUT
59                        Optional name of the result file. If the server has
60                        been configured to write results to files and the size
61                        of the result is greater than the configured limit,
62                        the server will write the result to a file with this
63                        name under the server's result directory (see the
64                        server documentation for more detail). A default name
65                        will be used if this is not specified.
66  -pt POLL_TIMEOUT, --poll-timeout POLL_TIMEOUT
67                        Number of seconds to poll for a result before timing
68                        out and returning a request id to re-query (defaults
69                        to 120)
70  -i IP, --ip IP        Host address for the cuOpt server (default 0.0.0.0)
71  -p PORT, --port PORT  Port for the cuOpt server (default 5000)
72  -s, --ssl             Not currently implemented. Use https scheme (default
73                        is http)
74  -c SELF_SIGNED_CERT, --self-signed-cert SELF_SIGNED_CERT
75                        Path to self signed certificates only, skip for
76                        standard certificates
77  -l {critical,error,warning,info,debug}, --log-level {critical,error,warning,info,debug}
78                        Log level
79  -ov, --only-validation
80                        If set, only validates input
81  -v, --version         Print client version and exit.