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

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. Java_Servlet 中文乱码问题及解决方案剖析

    一.常识了解 1.GBK包含GB2312,即如果通过GB2312编码后可以通过GBK解码,反之可能不成立; 2.java.nio.charset.Charset.defaultCharset() 获得 ...

  2. JS中常遇到的浏览器兼容问题和解决方法【转】

    今天整理了一下浏览器对JS的兼容问题,希望能给你们带来帮助,我没想到的地方请留言给我,我再加上: 常遇到的关于浏览器的宽高问题: //以下均可console.log()实验 var winW=docu ...

  3. Android studio 签名使用转

    来自http://www.cnblogs.com/xiwix/archive/2012/04/15/2447910.html 本文主要讲解Android应用程序签名相关的理论知识,包括:什么是签名.为 ...

  4. javascript 时间操作

    javascript时间函数 javascript提供了Date对象来进行时间和日期的计算.Date对象有多种构造函数: 1.dateObj=new Date() //当前时间 2.dateObj=n ...

  5. python 之select

    服务端源码 #!/usr/bin/env python3 # -*- coding: utf-8 -*- """ @author: zengchunyun "& ...

  6. 【Go语言】集合与文件操作

    本文目录 1.数据集合的主要操作 1_1.字典的声明 1_2.字典的初始化和创建 1_3.字典的访问和操作 1_4.其他类型的数据集 2.文件操作 2_1.文件操作概述os包和path包 2_2.文件 ...

  7. 油田 Oil Deposits

    油田 题目链接:http://acm.hust.edu.cn/vjudge/contest/view.action?cid=84562#problem/L 题意: 输入一个m行n列的字符矩形,统计字符 ...

  8. 高性能MySQL第1章知识点梳理

    1. MySQL的逻辑架构 最上面不是MySQL特有的,所有基于网络的C/S的网络应用程序都应该包括连接处理.认证.安全管理等. 中间层是MySQL的核心,包括查询解析.分析.优化和缓存等.同时它还提 ...

  9. JSOUP选择器语法说明

    jsoup 是一款基于Java 的HTML解析器,可直接解析某个URL地址或HTML文本内容.它提供了一套非常省力的API,可通过DOM,CSS以及类似于jQuery的操作方法来取出和操作数据.jso ...

  10. HDU1443 模拟(难)

    Joseph Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others)Total Subm ...