当前位置:网站首页>Difference Constraint - Graph Theory
Difference Constraint - Graph Theory
2022-08-09 07:05:00 【swust_fang】
Differential Constraint System
I. What is a differential constraint system:
A system of difference constraints is a method of solving a special set of inequalities with respect to a set of variables.If a system consists of n variables and m constraints, each of which has the form xj-xi<=bk(i,j∈[1,n],k∈[1,m]), then it is calledis a system of difference constraints.That is, a differential constraint system is a method of solving a special set of inequalities with respect to a set of variables.
In layman's terms, a differential constraint system is a group of inequalities, and our goal is to find the maximum or minimum value or whether the differential constraint system has a solution through a given set of constraint inequalities.
For example:
Second, the solution of the differential constraint system:
The differential constraint system can be converted into graph theory to solve, corresponding to the above inequality group, if the maximum value of x3-x0 is required, the superposition inequality can be deduced that x3-x0<=7, the maximum value is 7,We can build a graph with 6 vertices, and for each xj-xi<=bk, create a directed edge from i to j with a weight of bk.By finding the shortest path from x0 to x3 of this graph, we can know that it is also 7. Is this a coincidence?Not really.
The reason why the differentially constrained system can be solved by the shortest path of graph theory is because xj-xi<=bk, it will be found that it is similar to the triangular inequality d[v] <=d[u]+w[ in the shortest pathu,v], that is, d[v]-d[u]<=w[u,v].The process of finding the maximum value is similar to the relaxation process in the shortest path algorithm.
Triangular inequality: (quote Daniel's blog here)
B - A <= c (1)
C - B <= a (2)
C - A <= b (3)
If the maximum value of C-A is required, you can know that max(C-A) = min(b, a+c), which corresponds to the shortest path from C to A in the figure below.
Therefore, to generalize the triangle inequality, there are n variables and m inequalities, and the maximum value of xn-x1 is required, which is to find the shortest path after the map is constructed.
Similarly, if it is required to take the minimum value of xn-x1 in the differential constraint system, it is to find the longest path after mapping.The longest path can be found by spfa, just change the direction of relaxation, ie if(d[v] < d[u] + dist(u,v)) d[v] = d[u] + dist(u, v).Of course, we can negate all edge weights in the graph to find the shortest path, and the two are equivalent.
The longest path solution algorithm is proved as follows:
http://www.cnblogs.com/g0feng/archive/2012/09/13/2683880.html
Finally, there may not be the shortest/longest path after the map is built, because there may be negative/positive loops that decrease/increase infinitely, and the questions generally correspond to different outputs.It is enough to judge whether the differential constraint system has a solution general loop.
3. Application of differential constraint system
Differential constraint systems are widely used and all have a certain background. We only need to construct a differential constraint system according to the meaning of the problem, and then solve it according to the requirements of the problem.
There are three situations in general questions: (1), finding the shortest path (2), finding the longest path (3), judging whether the solution of the differential constraint system exists
Of course these three may also be combined with each other.
The solution of the differentially constrained system is as follows:
1. According to the conditions, express the meaning of the question through the variable group to obtain the inequality group. Pay attention to discover the implicit inequality, such as the implicit inequality relationship between the two variables before and after.
2. Make a map:
First, standardize the inequality group according to the requirements of the title.
(1) If the minimum value is required, then the longest path is found, then all the inequalities are converted into the form of xi – xj >= k, so that the edge of j->i is established, and the weight is kIf there is xi – xj > k in the inequality group, because the general problem is a constraint on the integer variable, it can be transformed into xi – xj >= k+1. If xi – xj=k, then it can be changed toThe following two: xi – xj >= k, xi – xj <= k, further change to xj – xi>= -k, just create two edges.
(2) If the maximum value is obtained, then the shortest path is obtained, and all the inequalities are converted into the form of xi – xj <= k, so that the edge of j->i is established, and the weight is k, if it is like the above two cases, then the same normalization will do.
(3) If you want to judge whether there is a solution in the differential constrained system, it is generally a judgment loop. You can choose to find the shortest path or the longest path, but the inequality standardization is different.Spfa is enough. If the same point is enqueued more than n times among n points, then there is a ring.
It is worth noting that the created graph may not be connected, we only need to add a super source point, for example, if the graph is not connected when finding the longest path, we only need to add a point S, rightEach other point establishes an edge graph with a weight of 0 to be connected, and then starts from the S point to perform the spfa judgment ring.The shortest path is similar.
3. After the graph is built, it can be solved directly by spfa or bellman-ford. The dijstra algorithm cannot be used, because there are generally negative edges, so pay attention to the initialization problem.
边栏推荐
- makefile记录
- 线程池总结
- 错误:为 repo ‘oracle_linux_repo‘ 下载元数据失败 : Cannot download repomd.xml: Cannot download repodata/repomd.
- postgresql Window Functions
- 半导体新能源智能装备整机软件系统方案设计
- jvm线程状态
- 【烂笔头】各厂商手机手动抓log
- 2017.10.26模拟 b energy
- Unity first lesson
- 【MySQL】update mysql.user set authentication_string=password(“123456“) where User=‘root‘; 报错
猜你喜欢
The JVM thread state
Unity first lesson
ByteDance Written Exam 2020 (Douyin E-commerce)
2022 年全球十大最佳自动化测试工具
SAP ALV data export many of the bugs
细谈VR全景:数字营销时代的宠儿
当酷雷曼VR直播遇上视频号,会摩擦出怎样的火花?
unity第一课
Altium designer software commonly used the most complete package library, including schematic library, PCB library and 3D model library
【nuxt】服务器部署步骤
随机推荐
搭载开源鸿蒙系统的嵌入式XM-RK3568工业互联方案
MVN 中配置flyway mysq
差分约束-图论
Quectel EC20 4G module dial related
什么是分布式事务
The maximum validity period of an SSL certificate is 13 months. Is it necessary to apply for multiple years at a time?
【ROS2原理8】节点到参与者的重映射
The division principle summary within the collection
leetcode:55. 跳跃游戏
2022年7月小结
vlucas/phpdotenv phpdotenv获取变量内容偶尔出现返回false
leetcode 之 零移位
Leetcode 70 stairs issues (Fibonacci number)
Sklearn data preprocessing
RK3568商显版开源鸿蒙板卡产品解决方案
字节跳动笔试题2020 (抖音电商)
SIGINT,SIGKILL,SIGTERM信号区别,各类信号总结
【烂笔头】各厂商手机手动抓log
XxlJobConfig distributed timer task management XxlJob configuration class, replace
半导体新能源智能装备整机软件系统方案设计