【发布时间】:2017-08-02 10:02:42
【问题描述】:
我正在使用优先级队列来订购名为 TreeNodeWithCostAndHeuristic 的案例类
case class TreeNodeWithCostAndHeuristic[S,A](parent:Option[TreeNodeWithCostAndHeuristic[S,A]],
action: Option[A],
state: S,
cost: Double,
estimatedRemainingCost: Double)
这个优先级队列是在一个函数内部创建的,该函数使用它的参数来设置初始状态,而其他值必须保持为 None 或 0
def HeuristicGraphSearch[S,A](problem: ProblemWithCostAndHeuristic[S,A]) = {
val root = TreeNodeWithCostAndHeuristic(parent = None,action=None,state=problem.initialState,cost = 0.0, estimatedRemainingCost = 0.0)
val frontier : mutable.PriorityQueue[TreeNodeWithCostAndHeuristic[S,A]] = mutable.PriorityQueue.empty[TreeNodeWithCostAndHeuristic[S,A]]
frontier.enqueue(root)
但是,由于没有父项和操作,我得到预期类型 TreeNodeWithCostAndHeuristic[S,A] 与我尝试排队的 TreeNodeWithCostAndHeuristic[S,Nothing] 之间的不匹配。
据我所知,Nothing 是 Option 的子类型,在我的案例类中,父类和操作都是选项。为什么会出现不匹配的情况?
【问题讨论】:
标签: scala functional-programming