利用最大流标号法求解最大流,详见代码:

Version:未加头尾节点版;

缺点:havn't take nodes' pixels into consideration

/************************************************************************/
/* MaxFlow solve graph cut program */
/************************************************************************/
/*
File description:
This program for graph cut based on Ford - Fulkerson Algorithm.
Input:
M(edge number) N(node number)
then M lines input 3 parameters each line:
start_point end_point edge_capacity
e.g 5 4 1 4 40 1 2 20 2 4 10 4 3 30 3 2 10
output:
Line 1:maxflow value
Line2:nodes in Class 1
e.g
MAX Flow is 50
nodes in class S: 1 2
=========================================================================
CreateTime:2011-8-8
Author:@Zhang Ruiqing
*/
#include<iostream>
#include<queue>
using namespace std;
#define N 250//point
#define M 250*250//edge
#define INF 1000000000
#define min(a,b) a<b?a:b int pre[N],map[N][N];
int minlen[N];//minlen[i] represents min length from s to i
int pathmin[N];//min flow in this path from i to t
queue<int>Q; int n,m,s,t; void init(int s)
{
memset(pre,,sizeof(pre));
for(int i=;i<=n;i++)
minlen[i]=pathmin[i]=INF;
minlen[s]=;
} bool bfs(int s,int t)
{
init(s);
//push start node
Q.push(s);
while(!Q.empty())
{
int now=Q.front();
Q.pop();
for(int i=;i<=n;i++)
{
if(map[now][i]!=&&minlen[now]+map[now][i]<minlen[i])
{
minlen[i]=minlen[now]+map[now][i];
pre[i]=now;
pathmin[i]=min(pathmin[now],map[now][i]);
Q.push(i);
}
}
}
if(minlen[n]==INF)
return false;
return true;
} int max_flow(int s,int t)
{
int res=;
while(bfs(s,t))//if can find an augment road
{
int minflow=pathmin[n];//minimal flow in the path
int point=t;//calculate from end point t to start point s
while(point!=s)
{
int prep=pre[point];
map[prep][point]-=minflow;//positive road -= flow
map[point][prep]+=minflow;//nagative road+= flow
point=prep;
}
res+=minflow;
}
return res;
} int main()
{
int i,j;
int a,b,c;
while(scanf("%d%d",&m,&n)!=EOF)
{
memset(map,,sizeof(map));
for(i=;i<m;i++)
{
cin>>a>>b>>c;
map[a][b]+=c;
}
s=;
t=n;
cout<<"MAX Flow is "<<max_flow(s,t)<<endl; cout<<"nodes in class S: 1 ";
for(i=;i<n;i++)
{
if(pathmin[i]!=INF)
cout<<i<<" ";
}
cout<<endl;
}
return ;
}

from: http://blog.csdn.net/abcjennifer/article/details/6668913

图割Graph-Cut的最大流实现的更多相关文章

  1. 图像分割之(二)Graph Cut(图割)

    zouxy09@qq.com http://blog.csdn.net/zouxy09 上一文对主要的分割方法做了一个概述.那下面我们对其中几个比较感兴趣的算法做个学习.下面主要是Graph Cut, ...

  2. GrabCut in One Cut(基于图割算法grabcut的一次快速图像分割的OpenCV实现)----目前效果最好的图割

     One cut in grabcut(grabcut算法的非迭代实现?) 本文针对交互式图像分割中的图割算法,主要想翻译一篇英文文献.不足之处请大家指正. 这是博主近期看到的效果最好,实现最简单 ...

  3. Graph Cut and Its Application in Computer Vision

    Graph Cut and Its Application in Computer Vision 原文出处: http://lincccc.blogspot.tw/2011/04/graph-cut- ...

  4. Graph Cut

    转自:http://blog.csdn.net/zouxy09/article/details/8532111 Graph Cut,下一个博文我们再学习下Grab Cut,两者都是基于图论的分割方法. ...

  5. 图像分割之(三)从Graph Cut到Grab Cut

    zouxy09@qq.com http://blog.csdn.net/zouxy09 上一文对GraphCut做了一个了解,而现在我们聊到的GrabCut是对其的改进版,是迭代的Graph Cut. ...

  6. 基于GraphCuts图割算法的图像分割----OpenCV代码与实现

    转载请注明出处:http://blog.csdn.net/wangyaninglm/article/details/44151213, 来自:shiter编写程序的艺术 1.绪论 图切割算法是组合图论 ...

  7. 看开源代码利器—用Graphviz + CodeViz生成C/C++函数调用图(call graph)

    一.Graphviz + CodeViz简单介绍 CodeViz是<Understanding The Linux Virtual Memory Manager>的作者 Mel Gorma ...

  8. 图数据库(graph database)资料收集和解析 - daily

    Motivation 图数据库中的高科技和高安全性中引用了一个关于图数据库(graph database)的应用前景的乐观估计: 预计到2017年,图数据库产业在数据库市场的份额将从2个百分点增长到2 ...

  9. 分析函数调用关系图(call graph)的几种方法

    绘制函数调用关系图对理解大型程序大有帮助.我想大家都有过一边读源码(并在头脑中维护一个调用栈),一边在纸上画函数调用关系,然后整理成图的经历.如果运气好一点,借助调试器的单步跟踪功能和call sta ...

随机推荐

  1. 【BZOJ】2084: [Poi2010]Antisymmetry

    http://www.lydsy.com/JudgeOnline/problem.php?id=2084 题意:一个01串,求满足字符串0和1取反后,再将整个串反过来和原串一样的子串数目.(n< ...

  2. JS中关于比较运算符的问题(a===b)

    之前也会碰到a===b和a==b的表达式,但都没有仔细的看资料,今天看canvas有关的书中提到了,就mark一下: a == b    说明:a与b相等: a ===b  说明:a与b相同,并且类型 ...

  3. sql:select赋值和set赋值的区别

    1)Set写法 declare @i integer set @i=(select count(*) from test) select @i Select写法 declare @i integer ...

  4. 升级OS X EI Capition 版本导致cocoapods 使用终端上pod: command not found

    1)安装过cocoapods, 那么输入 : sudo gem install -n /usr/local/bin cocoapods 当然 上个步骤解决了我的 难题 2)首先在终端输入 gem so ...

  5. 深入浅出 - Android系统移植与平台开发(二) - 准备Android开发环境

    作者:唐老师,华清远见嵌入式学院讲师. 编译Android源码 关于android系统的编译,Android的官方网站上也给出了详细的说明.http://source.android.com/sour ...

  6. Idea_Intellij Idea 12 生成serialVersionUID的方法

    默认情况下Intellij IDEA是关闭了继承了java.io.Serializable的类生成serialVersionUID的警告.如果需要ide提示生成serialVersionUID,那么需 ...

  7. tomcat配置环境变量

    先把jdk配置好,这里不在赘述. 一.配置Tomcat环境变量 1,新建变量名:CATALINA_BASE,变量值:C:\tomcat2,新建变量名:CATALINA_HOME,变 量值:C:\tom ...

  8. EditText自定义边框

    1.EditText代码如下 (View代替EditText获取焦点): <View android:focusable="true" android:focusableIn ...

  9. Unix NetWork Programming -- 环境搭建(Ubuntu 12.04 x86_64)

    1. 下载源代码:http://www.ituring.com.cn/book/download/60498ad9-ede6-4023-a92b-04d47be23578 2. 解压文件后进入文件根目 ...

  10. PS教程1000例

    http://www.missyuan.com/thread-446934-1-1.html Photoshop绘制逼真头发发丝效果http://www.missyuan.com/thread-446 ...