Simplex线性规划单纯形算法

本文深入探讨了单纯形算法在解决线性规划问题中的应用,通过详细解释代码实现过程,帮助读者理解这一经典算法的工作原理。
摘要由CSDN通过智能技术生成

simplex是线性规划中十分经典的算法,以下为实现代码

头文件

#ifndef SIMPLEX_H_INCLUDED
#define SIMPLEX_H_INCLUDED
#include <stdio.h>
#include <stdlib.h>
#define MAX_VALUE 1.0e308

int m ,n;
typedef double Elemtype;
typedef struct calcu_node
{
    Elemtype **A;
    Elemtype *B;
    Elemtype *C;
    int *B1;/*基向量对应的位置*/
    Elemtype z;
} calcu_node,*pcalcu_node;

typedef struct result
{
    Elemtype *x;
    Elemtype z;
} result,*presult;

pcalcu_node init_simplex(pcalcu_node calcu_node);
presult simplex(Elemtype **input_A,Elemtype *input_B,Elemtype *input_C);
Elemtype *calculate_x(pcalcu_node calcu_node);
void pivot(pcalcu_node calcu_node,int l,int e);
#endif // SIMPLEX_H_INCLUDED

具体实现

#include "simplex.h"


Elemtype *calculate_x(pcalcu_node calcu_node)
{
    Elemtype *x = (Elemtype*)malloc(n * sizeof(Elemtype));
    int j;
    for(j = 0; j < n; j++)
    {
        if(calcu_node->B1[j] == 0)
            x[j] = 0;
        else
        {
            int i = 0;
            for(i; i < m; i++)
            {
                if(calcu_node->A[i][j] == 1)
                    x[j] = calcu_node->B[i];
            }
        }
    }
    return x;
}

presult simplex(Elemtype **input_A,Elemtype *input_B,Elemtype *input_C)
{
    pcalcu_node calcu_node = (pcalcu_node)malloc(sizeof(calcu_node));
    calcu_node->A = (Elemtype**)malloc(m * (sizeof(Elemtype)));
    calcu_node->B = (Elemtype*)malloc(m * sizeof(Elemtype));
    int i = 0,j = 0;
    for(; i < m; i++)
    {
        calcu_node->B[i] =
评论 2
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值