图1

图2

图1是线性规划问题转化后的标准形式,图2是对图1的另一种形式(即单纯形表),具体编程按图2格式编写。

具体步骤如下:

第一步:作单纯形表.

(1)将原线性规划问题化为标准形式;

(2) 找出初始可行基,通常取约束方程组系数矩阵中的单位矩阵;

(3) 目标函数非基化;

(4) 作初始单纯形表.

简单讲就是将一个线性规划问题转换成图2的格式!

第二步:最优解的判定.

(1)

若所有检验数都是非正数,即在图2里面可以看到Z=Z0+rTXN

,这里rT 向量里面系数都是非正数的话,那么此时线性规划问题已取得最优解.

(2)

若存在某个检验数是正数并且其系数都为非负数的话无最优解。例如:在Z=Z0+rTXN

中xi的系数为正并且在图2中QXN里对应于xi的系数都为非负数,则些线性规划问题无最优解.

如果以上两条都不满足,则进行下一步.

第三步:换基迭代.

(1)找到最大正检验数(在rT中),设为u并确定u 所在列的非基变量

xu为进基变量.

(2)对最大正检验数u所在列实施最小比值法,确定出主元.主元是最大正检验数 u所在列,用常数项

pi与进基变量xu 所对应的列向量中负分量的比值最小者;

下面两张图是解释为什么这么做的!

(3)换基:用进基变量 xu替换出基变量xv

,从而得到新的基变量.也就是主元所在列的非基变量进基,所在行的基变量出基;

(4)更新:更新其它存在xu的行,将其用非基本变量表示。因此Q,p, Z0,

rT相应更新。

(5)矩阵重新排列保证像x1,x3,x4这样有序排列的,而不是像x3,x4,x1

从而得到新的单纯形表;

(5)回到第二步,继续判定最优解是否存在,然后进行新一轮换基迭代,直到问题得到解决为止.

具体题目:

Question 1 Pivoting.

Write, in a programming language of your choice available in the

Faculty Linux Labs (but not in an LP solver) code that given a

simplex tableau and indices of variables to leave and enter the

basis, performs the corresponding pivot.

Input format

Input is whitespace delimited integers

u is the entering column, v is the leaving column.

m is the number of rows, n is the number of columns of the A

matrix in equational form.

B1 to Bm are the indices of the

basic columns.

Output format

Same as input format, without the first line specifying leaving

and entering variables.

Question 2 Ratio Testing.

Write a function or method that given a simplex tableau, chooses

entering and leaving variables, or reports the tableau as

infeasible or unbounded.

Input format

Same as input format for question 1, without the first line

specifying leaving and entering columns

Output format

Same as input format for question 1, unless the tableau is

optimal or unbounded. In this case print the single word "OPTIMAL"

or "UNBOUNDED" on a line by itself.

Question 3 Integration.

Write a main loop that integrates your code from the first two

questions and solves a linear program. Your code may assume that

the initial tableau is feasible.

Input format

Same as input format for question 1, without the first line

specifying leaving and entering variables.

Output format

Same as input format (although typically not the same

tableau!).

问题3代码如下:

#include

#include

double *p;

double **q;

double **A;

int *B;

double *R;

double *r;

double z;

int cmp(const void*a,const void*b)

{

return *(int *)a-*(int *)b;

}

int match(int t)

{ int k=1;

while(B[k]!=0)

{

if(t==B[k])

return 1;

k++;

}

return 0;

}

void transform(int m,int n)

{ int i,j,f;

for(i=1;i<=m;i++)

{ f=1;

for(j=1;j<=n;j++)

{

if(match(j)==1)

A[i][j]=0;

else

A[i][j]=q[i][f++];

}

}//put all the non-basic data into A[][];

f=1;

for(j=1;j<=n;j++)

{

if(match(j)==1)

R[j]=0;

else

R[j]=r[f++];

}//put all the non-basic data into R;

}

void pivot(int a,int b,int row,int col)//a is the entering column,b

is the leaving column

{

int k=1;int i,j;

while(B[k]!=0)

{

if(B[k]==b)

break;

k++;

};//get k as the row of the leaving

variable

B[k]=a;//a is the enter column;

for(j=1;j<=col;j++)

{

if(j==b)

A[k][j]=1/A[k][a];//A[k][a] is the coefficient of the entering

variable in this row

else

if(j!=a)

A[k][j]=-A[k][j]/A[k][a];

}

p[k]=-p[k]/A[k][a];//change

the p[k] after a enter the basis

z+=R[a]*p[k];//update z

for(j=1;j<=col;j++)

{

if(match(j)==0)

R[j]+=R[a]*A[k][j];

}

//update r

R[a]=0;

A[k][a]=0;

for( i=1;i<=row;i++)

{

if(i!=k)

if(A[i][a]!=0)

{

for(j=1;j<=col;j++)

{ if(match(j)==0)

A[i][j]+=A[i][a]*A[k][j];

}

p[i]+=A[i][a]*p[k]; A[i][a]=0;

}

}

}

void output(int u,int v,int row,int col)

{ int i,j;

printf("%d %d\n",row,col);

for(i=1;i<=row;i++)

printf("%d ",B[i]);

printf("\n");

for(i=1;i<=row;i++)

{ printf("%.0lf ",p[i]);

for(j=1;j<=col;j++)

{

if(match(j)==0)

printf("%.0lf ",A[i][j]);

}

printf("\n");

}

printf("%.0lf ",z);

for(j=1;j<=col;j++)

{

if(match(j)==0)

printf("%.0lf ",R[j]);

}

printf("\n"); }

int check_Opt(int m,int n)

{

int j;

for(j=1;j<=n;j++)

if(R[j]>0)

return 0;

return 1;

}

int check_Unbounded(int m,int n, int u)

{

int i;

for(i=1;i<=m;i++)

{

if(A[i][u]<0)

return 0;

}

return

1;

}

int decide_enter(int m,int n)

{ int max=1,j;

for(j=2;j<=n;j++)

if(R[j]>R[max])

max=j;

return max;

}

int decide_leave(int m,int n,int u)

{ int i=1,t,min;

while(i!=m)

{

if(A[i][u]<0)

break;

i++;

}

min=i;

for(t=i+1;t<=m;t++)

{

if((A[t][u]<0)&&(-p[t]/A[t][u]

min=t;

}

return

min;

}

int find(m,n,u)

{int i;

for(i=1;i<=m;i++)

if(B[i]==u)

return i;

}

void adjust(int leave_row,int correct_row,int n)

{ double temp;int i,j,t;

if(leave_row>correct_row)

{

t=leave_row-correct_row;

for(i=1;i<=t;i++)

{ for(j=1;j<=n;j++)

{

temp=A[leave_row][j];

A[leave_row][j]=A[leave_row-1][j];

A[leave_row-1][j]=temp;

}

temp=p[leave_row];

p[leave_row]=p[leave_row-1];

p[leave_row-1]=temp;

leave_row-=1;

单纯形法表格法例题详解_Linear programing–simplex method(单纯形法) 解题步骤相关推荐

  1. 单纯形法表格法例题详解_优化 |运筹学线性规划单纯形法之求解

    文章申明 文章作者:臧永森 臧永森:清华大学工业工程系在读博士,研究方向:运筹优化算法的设计与应用.数据统计分析.大数据技术与应用,戚铭尧老师团队 责任编辑:阎泳楠 文章由『运筹OR帷幄』原创发布,如 ...

  2. 单纯形法表格法例题详解_第二章 线性规划与单纯形法(补充例题123页开始).ppt...

    您所在位置:网站首页 > 海量文档 &nbsp>&nbsp高等教育&nbsp>&nbsp微积分 第二章 线性规划与单纯形法(补充例题123页开始).p ...

  3. 单纯形法表格法例题详解_最优化单纯形法例题讲解.doc

    最优化单纯形法例题讲解.doc 例1 用单纯形法解下列问题: 解:将原问题化成标准形: x4与添加的松弛变量x,x在约束方程组中其系数正好构成一个3阶单位阵,它们可以作为初始基变量,初始基可行解为X= ...

  4. 单纯形法表格法例题详解_【精品】最优化单纯形法例题讲解.doc

    例1 用单纯形法解下列问题: 解:将原问题化成标准形: x4与添加的松弛变量x5,x6在约束方程组中其系数列正好构成一个3阶单位阵,它们可以作为初始基变量,初始基可行解为X=(0, 0, 0,10, ...

  5. 单纯形法表格法例题详解_最优化单纯形法例题讲解

    9787.0)(618.02=-+=a b a x ,0199.0)(22-==x f f : 因为ε=<=-5.0438.0a b ,所以算法停止,得到 927.02 146 .1708.02 ...

  6. dijkstra标号法表格_标号法求最短路径例题详解.ppt

    标号法求最短路径例题详解 r * 最短路径 带权图G=, 其中w:E?R. ?e?E, w(e)称作e的权. e=(vi,vj), 记w(e)=wij . 若vi,vj不 相邻, 记wij =?. 设 ...

  7. DID会固定年份吗_倍分法DID详解 (二):多时点 DID (渐进DID)

    作者:王昆仑 (天津大学) Stata连享会 计量专题  || 公众号合集 2020寒假Stata现场班 (北京, 1月8-17日,连玉君-江艇主讲) 「+助教招聘」 2020寒假Stata现场班 文 ...

  8. nacl溶解度_科普下氯化钠溶解度(含例题详解)

    关于到现在氯化钠溶解度(含例题详解)这个话题,相信很多小伙伴都是非常有兴趣了解的吧,因为这个话题也是近期非常火热的,那么既然现在大家都想要知道氯化钠溶解度(含例题详解),小编也是到网上收集了一些与氯化 ...

  9. DID会固定年份吗_倍分法DID详解 (三):多时点 DID (渐进DID) 的进一步分析

    作者:王昆仑 (天津大学) E-mail: shawn0513@163.com 连享会专题课程:DSGE 模型及应用 连享会 DSGE 专题课程 这是连享会「倍分法(DID)专题推文」系列的第三篇文章 ...

最新文章

  1. Linux的文件权限
  2. Jmeter_前端RSA加密下的登陆模拟_引用js文件实现(转)
  3. CentOS快捷键总结
  4. Makedown 本地图片问题
  5. 浅谈opencl之错误码
  6. django 1.8 官方文档翻译: 1-3-1 高级教程:如何编写可重用的应用
  7. Facebook 的 PHP 性能与扩展性
  8. 建立索引为什么能加快查询速度 【转】
  9. 如何使用C#调用REST api?
  10. Debian Linux安装Android ABD工具
  11. 数据结构与算法分析:C语言描述(原书第2版) PDF+源代码+习题答案
  12. Python学习笔记(五)——读写文件
  13. 醋醋SEO基础入门教程_seo入门基础知识
  14. linux if 判断文件,shell中的逻辑判断,if 判断文件、目录属性,if判断的一些特殊用法...
  15. Fluke 726 高精度多功能过程校准器具体参数
  16. oracle vm virtualbox 64位,virtualbox
  17. 淘宝接入微信,并将支持微信支付
  18. PDF图片文字如何编辑?ORC图文识别一招搞定
  19. JS实现国家、省、市
  20. 声光控延时开关设计原理

热门文章

  1. 在高频交易领域中,为什么我们选择 Java 开发外汇算法交易系统?
  2. 渗透测试学习总体概括
  3. HTML转义特殊字符字符
  4. 软件版本alpha、Beta、RC、GA、DMR等含义
  5. md文件转html文件
  6. immutable.js中文文档
  7. AE489 4K卡通水火焰手绘烟雾漫画泡泡文字闪光特效元素包带Alpha透明通道ae模板
  8. 如何解决问题并给出解决方案
  9. 各大高校研究生录取通知书争奇斗艳美到哭,我也想要!
  10. 小程序时间轴和地区列表的实现,js+css实现时间轴效果