关于Python版本是否支持strengthWeightFactoryClass规划变量配置的问询
OptaPlanner Python版本对变量强度权重工厂的支持
在OptaPlanner的Python版本中,完全支持Java版本里@PlanningVariable(strengthWeightFactoryClass = ...)对应的变量强度权重工厂功能,通过@planning_variable装饰器的strength_weight_factory参数来配置。
Python示例(项目作业调度问题)
首先定义强度权重工厂类,需要实现StrengthWeightFactory接口:
from optapy import PlanningVariableStrengthWeightFactory class ExecutionModeStrengthWeightFactory(PlanningVariableStrengthWeightFactory): def create_strength_weight(self, solution, entity): # 根据业务逻辑计算并返回ExecutionMode的强度权重值 # 示例:假设ExecutionMode有priority属性,权重取其优先级值 return entity.execution_mode.priority
然后在规划实体的变量上配置该工厂:
from optapy import planning_entity, planning_variable @planning_entity class Task: def __init__(self, execution_mode=None): self.execution_mode = execution_mode @planning_variable( value_range_provider_refs=["execution_mode_range"], strength_weight_factory=ExecutionModeStrengthWeightFactory() ) def get_execution_mode(self): return self.execution_mode def set_execution_mode(self, execution_mode): self.execution_mode = execution_mode
对应的Java示例
@PlanningVariable(strengthWeightFactoryClass = ExecutionModeStrengthWeightFactory.class) public ExecutionMode getExecutionMode() { return executionMode; }
内容的提问来源于stack exchange,提问作者Eason Con
相关产品推荐
相关产品推荐

