matlan里graphmaxflow为什么两点间不能有两条边

matlan里graphmaxflow为什么两点间不能有两条边,第1张

matlan里graphmaxflow两点间不能有两条边的原因:

因为Matlab图论工具箱求解最大流的命令graphmaxflow,只能解决权重都为正值,且两个顶点之间不能有两条弧的问题。

您好,这样:

一个实时曲线的例子,看是否能帮到你~

C# code

public partial class FrmMain : Form

{

// 起始时间以毫秒为单位

int tickStart = 0

public FrmMain()

{

InitializeComponent()

}

private void Form1_Load( object sender, EventArgs e )

{

//获取引用

GraphPane myPane = zedGraphControl1.GraphPane

//设置标题

myPane.Title.Text = "实时曲线"

//设置X轴说明文字

myPane.XAxis.Title.Text = "时间"

//设置Y轴说明文字

myPane.YAxis.Title.Text = "温度"

//设置1200个点,假设每50毫秒更新一次,刚好检测1分钟,一旦构造后将不能更改这个值

RollingPointPairList list = new RollingPointPairList( 1200 )

//开始,增加的线是没有数据点的(也就是list为空)

//增加一条名称:Voltage,颜色Color.Bule,无符号,无数据的空线条

LineItem curve = myPane.AddCurve("温度", list, Color.Blue, SymbolType.None)

timeDraw.Interval = 10 //设置timer控件的间隔为50毫秒

timeDraw.Enabled = true //timer可用

timeDraw.Start() //开始

myPane.XAxis.Scale.Min = 0 //X轴最小值0

myPane.XAxis.Scale.Max = 30 //X轴最大30

myPane.XAxis.Scale.MinorStep = 1//X轴小步长1,也就是小间隔

myPane.XAxis.Scale.MajorStep = 5//X轴大步长为5,也就是显示文字的大间隔

//改变轴的刻度

zedGraphControl1.AxisChange()

//保存开始时间

tickStart = Environment.TickCount

}

private void timer1_Tick( object sender, EventArgs e )

{

//确保CurveList不为空

if (zedGraphControl1.GraphPane.CurveList.Count <= 0)

{

return

}

//取Graph第一个曲线,也就是第一步:在GraphPane.CurveList集合中查找CurveItem

LineItem curve = zedGraphControl1.GraphPane.CurveList[0] as LineItem

if (curve == null)

{

return

}

//第二步:在CurveItem中访问PointPairList(或者其它的IPointList),根据自己的需要增加新数据或修改已存在的数据

IPointListEdit list = curve.Points as IPointListEdit

if (list == null)

{

return

}

// 时间用秒表示

double time = ( Environment.TickCount - tickStart ) / 1000.0

// 3秒循环

list.Add( time, Math.Sin( 2.0 * Math.PI * time / 3.0 ) )

Scale xScale = zedGraphControl1.GraphPane.XAxis.Scale

if ( time >xScale.Max - xScale.MajorStep )

{

xScale.Max = time + xScale.MajorStep

xScale.Min = xScale.Max - 30.0

}

//第三步:调用ZedGraphControl.AxisChange()方法更新X和Y轴的范围

zedGraphControl1.AxisChange()

//第四步:调用Form.Invalidate()方法更新图表

zedGraphControl1.Invalidate()

}

private void Form1_Resize( object sender, EventArgs e )

{

SetSize()

}

private void SetSize()

{

// 控制始终是以10像素插入矩形从客户端的形

Rectangle formRect = this.ClientRectangle

formRect.Inflate( -10, -10 )

if ( zedGraphControl1.Size != formRect.Size )

{

zedGraphControl1.Location = formRect.Location

zedGraphControl1.Size = formRect.Size

}

}

楼主你好,下面是源程序!

/*/////////////////////////////////////////////////////////////*/

/* 图的深度优先遍历 */

/*/////////////////////////////////////////////////////////////*/

#include <stdlib.h>

#include <stdio.h>

struct node /* 图顶点结构定义 */

{

int vertex /* 顶点数据信息 */

struct node *nextnode/* 指下一顶点的指标 */

}

typedef struct node *graph /* 图形的结构新型态 */

struct node head[9] /* 图形顶点数组 */

int visited[9] /* 遍历标记数组 */

/********************根据已有的信息建立邻接表********************/

void creategraph(int node[20][2],int num)/*num指的是图的边数*/

{

graph newnode/*指向新节点的指针定义*/

graph ptr

int from /* 边的起点 */

int to /* 边的终点 */

int i

for ( i = 0i <numi++ )/* 读取边线信息,插入邻接表*/

{

from = node[i][0]/*边线的起点*/

to = node[i][1] /* 边线的终点 */

/* 建立新顶点 */

newnode = ( graph ) malloc(sizeof(struct node))

newnode->vertex = to /* 建立顶点内容 */

newnode->nextnode = NULL /* 设定指标初值 */

ptr = &(head[from])/* 顶点位置 */

while ( ptr->nextnode != NULL ) /* 遍历至链表尾 */

ptr = ptr->nextnode/* 下一个顶点 */

ptr->nextnode = newnode /* 插入节点*/

}

}

/********************** 图的深度优先搜寻法********************/

void dfs(int current)

{

graph ptr

visited[current] = 1 /* 记录已遍历过 */

printf("vertex[%d]\n",current) /* 输出遍历顶点值 */

ptr = head[current].nextnode /* 顶点位置 */

while ( ptr != NULL ) /* 遍历至链表尾 */

{

if ( visited[ptr->vertex] == 0 ) /* 如过没遍历过 */

dfs(ptr->vertex) /* 递回遍历呼叫 */

ptr = ptr->nextnode /* 下一个顶点 */

}

}

/****************************** 主程序******************************/

void main()

{

graph ptr

int node[20][2] = { {1, 2}, {2, 1}, /* 边线数组 */

{1, 3}, {3, 1},

{1, 4}, {4, 1},

{2, 5}, {5, 2},

{2, 6}, {6, 2},

{3, 7}, {7, 3},

{4, 7}, {4, 4},

{5, 8}, {8, 5},

{6, 7}, {7, 6},

{7, 8}, {8, 7} }

int i

clrscr()

for ( i = 1i <= 8i++ ) /* 顶点数组初始化 */

{

head[i].vertex = i/*设定顶点值 */

head[i].nextnode = NULL /* 指针为空 */

visited[i] = 0/* 设定遍历初始标志 */

}

creategraph(node,20) /*建立邻接表 */

printf("Content of the gragh's ADlist is:\n")

for ( i = 1i <= 8i++ )

{

printf("vertex%d ->",head[i].vertex)/* 顶点值*/

ptr = head[i].nextnode/* 顶点位置 */

while ( ptr != NULL ) /* 遍历至链表尾 */

{

printf(" %d ",ptr->vertex) /* 印出顶点内容 */

ptr = ptr->nextnode/* 下一个顶点 */

}

printf("\n") /* 换行 */

}

printf("\nThe end of the dfs are:\n")

dfs(1) /* 打印输出遍历过程 */

printf("\n") /* 换行 */

puts(" Press any key to quit...")

getch()

}

/*//////////////////////////////////////////*/

/*图形的广度优先搜寻法 */

/* ///////////////////////////////////////*/

#include <stdlib.h>

#include <stdio.h>

#define MAXQUEUE 10 /* 队列的最大容量 */

struct node /* 图的顶点结构定义 */

{

int vertex

struct node *nextnode

}

typedef struct node *graph /* 图的结构指针*/

struct node head[9] /* 图的顶点数组 */

int visited[9] /* 遍历标记数组 */

int queue[MAXQUEUE] /* 定义序列数组 */

int front = -1 /* 序列前端*/

int rear = -1 /* 序列后端*/

/***********************二维数组向邻接表的转化****************************/

void creategraph(int node[20][2],int num)

{

graph newnode/* 顶点指针 */

graph ptr

int from /* 边起点 */

int to /* 边终点 */

int i

for ( i = 0i <numi++ )/* 第i条边的信息处理*/

{

from = node[i][0] /* 边的起点 */

to = node[i][1] /* 边的终点 */

/* 建立新顶点 */

newnode = ( graph ) malloc(sizeof(struct node))

newnode->vertex = to /*顶点内容 */

newnode->nextnode = NULL /* 设定指针初值 */

ptr = &(head[from]) /* 顶点位置 */

while ( ptr->nextnode != NULL ) /* 遍历至链表尾 */

ptr = ptr->nextnode/* 下一个顶点 */

ptr->nextnode = newnode /* 插入第i个节点的链表尾部 */

}

}

/************************ 数值入队列************************************/

int enqueue(int value)

{

if ( rear >= MAXQUEUE )/* 检查伫列是否全满 */

return -1 /* 无法存入 */

rear++ /* 后端指标往前移 */

queue[rear] = value /* 存入伫列 */

}

/************************* 数值出队列*********************************/

int dequeue()

{

if ( front == rear ) /* 队列是否为空 */

return -1 /* 为空,无法取出 */

front++ /* 前端指标往前移 */

return queue[front] /* 从队列中取出信息 */

}

/*********************** 图形的广度优先遍历************************/

void bfs(int current)

{

graph ptr

/* 处理第一个顶点 */

enqueue(current) /* 将顶点存入队列 */

visited[current] = 1 /* 已遍历过记录标志置疑1*/

printf(" Vertex[%d]\n",current) /* 打印输出遍历顶点值 */

while ( front != rear )/* 队列是否为空 */

{

current = dequeue() /* 将顶点从队列列取出 */

ptr = head[current].nextnode /* 顶点位置 */

while ( ptr != NULL ) /* 遍历至链表尾 */

{

if ( visited[ptr->vertex] == 0 ) /*顶点没有遍历过*/

{

enqueue(ptr->vertex)/* 奖定点放入队列 */

visited[ptr->vertex] = 1/* 置遍历标记为1*/

printf(" Vertex[%d]\n",ptr->vertex)/* 印出遍历顶点值 */

}

ptr = ptr->nextnode/* 下一个顶点 */

}

}

}

/*********************** 主程序 ************************************/

/*********************************************************************/

void main()

{

graph ptr

int node[20][2] = { {1, 2}, {2, 1}, /* 边信息数组 */

{6, 3}, {3, 6},

{2, 4}, {4, 2},

{1, 5}, {5, 1},

{3, 7}, {7, 3},

{1, 7}, {7, 1},

{4, 8}, {8, 4},

{5, 8}, {8, 5},

{2, 8}, {8, 2},

{7, 8}, {8, 7} }

int i

clrscr()

puts("This is an example of Width Preferred Traverse of Gragh.\n")

for ( i = 1i <= 8i++ )/*顶点结构数组初始化*/

{

head[i].vertex = i

head[i].nextnode = NULL

visited[i] = 0

}

creategraph(node,20) /* 图信息转换,邻接表的建立 */

printf("The content of the graph's allist is:\n")

for ( i = 1i <= 8i++ )

{

printf(" vertex%d =>",head[i].vertex)/* 顶点值 */

ptr = head[i].nextnode/* 顶点位置 */

while ( ptr != NULL ) /* 遍历至链表尾 */

{

printf(" %d ",ptr->vertex) /* 打印输出顶点内容 */

ptr = ptr->nextnode/* 下一个顶点 */

}

printf("\n") /* 换行 */

}

printf("The contents of BFS are:\n")

bfs(1) /* 打印输出遍历过程 */

printf("\n") /* 换行 */

puts(" Press any key to quit...")

getch()

}


欢迎分享,转载请注明来源:内存溢出

原文地址:https://54852.com/yw/11248439.html

(0)
打赏 微信扫一扫微信扫一扫 支付宝扫一扫支付宝扫一扫
上一篇 2023-05-14
下一篇2023-05-14

发表评论

登录后才能评论

评论列表(0条)

    保存