线性规划之单纯形法【超详解+图解】

您所在的位置:网站首页 目标函数的形式 线性规划之单纯形法【超详解+图解】

线性规划之单纯形法【超详解+图解】

2023-11-21 19:38| 来源: 网络整理| 查看: 265

使用单纯型法来求解线性规划,输入单纯型法的松弛形式,是一个大矩阵,第一行为目标函数的系数,且最后一个数字为当前轴值下的 z 值。下面每一行代表一个约束,数字代表系数每行最后一个数字代表 b 值。

算法和使用单纯性表求解线性规划相同。

对于线性规划问题:

Max      x1 + 14* x2 + 6*x3 

s . t .  x1 + x2 + x3 17 B.push_back(Matrix[i][cn-1]); 18 } 19 20 for( size_t i = 0 ; i 24 cmax = C[i]; 25 y = i; 26 } 27 } 28 if( cmax 36 double tmp = B[i]/Matrix[i][y]; 37 if( Matrix[i][y] != 0 && bmin > tmp ) 38 { 39 bmin = tmp; 40 x = i; 41 } 42 } 43 44 p = make_pair(x, y); 45 46 for( set::iterator it = P.begin() ; it != P.end() ; it++) 47 { 48 if( Matrix[x][*it] != 0 ) 49 { 50 //cout 64 for( size_t j = 0 ; j 75 size_t x = p.first; 76 size_t y = p.second; 77 double norm = Matrix[x][y]; 78 for( size_t i = 0 ; i 84 if( Matrix[i][y] != 0) 85 { 86 double tmpnorm = Matrix[i][y]; 87 for( size_t j = 0 ; j 97 pair t; 98 while(1) 99 { 100 101 pnt(); 102 if( Pivot(t) == 0 ) 103 { 104 return; 105 } 106 cout 118 //ifstream fin; 119 //fin.open("./test"); 120 cin>>cn>>bn; 121 for( size_t i = 0 ; i 126 double tmp = 0; 127 cin>>tmp; 128 vectmp.push_back(tmp); 129 } 130 Matrix.push_back(vectmp); 131 } 132 133 for( size_t i = 0 ; i 11 char c=getchar();int x=0,f=1; 12 while(c'9'){if(c=='-')f=-1; c=getchar();} 13 while(c>='0'&&c 20 b[l]/=a[l][e]; 21 for(int j=1;j 38 while(true){ 39 int e=0,l=0; 40 for(e=1;eeps) break; 41 if(e==n+1) return v; 42 double mn=INF; 43 for(int i=1;ieps&&mn>b[i]/a[i][e]) mn=b[i]/a[i][e],l=i; 45 if(mn==INF) return INF;//unbounded 46 pivot(l,e); 47 } 48 } 49 50 int main(){ 51 n=read();m=read(); 52 for(int i=1;i 11 char c=getchar();int x=0,f=1; 12 while(c'9'){if(c=='-')f=-1; c=getchar();} 13 while(c>='0'&&c 21 swap(id[n+l],id[e]); 22 double t=a[l][e]; a[l][e]=1; 23 for(int j=0;j 30 while(true){ 31 int e=0,l=0; 32 for(int i=1;i 41 while(true){ 42 int l=0,e=0; double mn=INF; 43 for(int j=1;jeps) {e=j;break;} 45 if(!e) break; 46 for(int i=1;ieps && a[i][0]/a[i][e] 54 freopen("in","r",stdin); 55 srand(317); 56 n=read();m=read();type=read(); 57 for(int i=1;i 64 printf("%.8lf\n",-a[0][0]); 65 if(type){ 66 for(int i=1;i



【本文地址】


今日新闻


推荐新闻


CopyRight 2018-2019 办公设备维修网 版权所有 豫ICP备15022753号-3