使用贝尔曼福特来检测产品超过阈值的循环

编程入门 行业动态 更新时间:2024-10-21 18:31:07
本文介绍了使用贝尔曼福特来检测产品超过阈值的循环的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述

Bellman Ford 用于检测图中的负加权循环。我想知道如何使用它来检测超过某个阈值的周期。

示例:

--------- > ^ | 1 0.5 | < ------ v 1 -----------> 2 ^ | | 4 | 1 | 2 v 4 <------------ 3

该图有2个周期。一个产品= 1,另一个产品= 4。如果阈值= 1,算法应该输出为真,因为有一个产品> 1的周期。

解决方案

我假设你想检测一个重量超过某个阈值的简单周期(否则,你可以重复任何正面权重>超过任何肯定的阈值)。

不幸的是,这个问题是 NP-Hard 。

从 G =(V,E)哈密尔顿周期问题,保持同样的图 G ,其中 w(e)= 2 边缘,然后将它发送到阈值 2 ^ | V | -1 的问题。 如果任何周期的权重大于 2 ^ | V | -1,那么它的边数多于 | V | -1`所以这个循环是哈密尔顿算子,如果有一个哈密尔顿循环,算法会发现有一个重量为2 * 2 * ... * 2> 2 ^ | V | -1的循环。

由于哈密尔顿周期是Np-完全的,并且我们找到了这个问题的多项式约化,所以这个问题是NP-Hard,并且没有已知的多项式解。

tl; dr:使用Bellman Ford来解决这个问题远不是微不足道的,如果可能的话,需要修改图形为指数(假设P!= NP)

Bellman Ford is used to detect negative weighted cycles in a graph. I would like to know how I can use it to detect cycles which exceeds a certain threshold instead.

Example:

---------> ^ |1 0.5 | <------v 1 -----------> 2 ^ | |4 |1 | 2 v 4<------------3

This graph has 2 cycles. One with the product = 1 and the other with the product = 4. If the threshold = 1, the algorithm should output true, since there is 1 cycle with a product > 1.

解决方案

I assume you want to detect a simple cycle with weight that exceeds some threshold (otherwise, you can repeat any positive weight>1 cycle enough times to exceed any positive threshold).

Unfortunately, that problem is NP-Hard.

A simple reduction from the Hamiltonian cycle problem:

Given an instance G=(V,E) of Hamiltonian cycle problem, keep the same graph G, with w(e) = 2 for any edge, and send it to the problem with threshold 2^|V|-1. If there is any cycle with weight bigger than 2^|V|-1, then it has more than|V|-1` edges, so this cycle is hamiltonian, and if there is a hamiltonian cycle, the algorithm will find that there is a cycle of weight 2*2*...*2> 2^|V|-1.

Since Hamiltonian Cycle is Np-Complete, and we found polynomial reduction from it to this problem, this problem is NP-Hard, and there is no known polynomial solution to it.

tl;dr: to use Bellman Ford to solve this problem, is far from trivial, and if possible, will require modifying the graph to be exponential in size of the original graph (Assuming P!=NP)

更多推荐

使用贝尔曼福特来检测产品超过阈值的循环

本文发布于:2023-11-30 20:56:18,感谢您对本站的认可!
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:贝尔   福特   阈值   产品

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!