⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 global.cpp

📁 这是一个求解线性规划问题的程序
💻 CPP
字号:
//---------------------------------------------------------------------------
#include <vcl\vcl.h>
#pragma hdrstop

#include "Grids.hpp"
#include "global.h"
#include "Matrix.h"
#include "Vector.h"
//---------------------------------------------------------------------------

void glb_UserInfo(AnsiString sInfo)
{
    MessageBox(GetActiveWindow(),sInfo.c_str(),"提示",MB_OK|MB_ICONWARNING);
}
//---------------------------------------------------------------------------
//根据数据矩阵设置字符串珊格
void glb_SetGrid(TMatrix* aMatA,TStringGrid* aSg)
{
   int i,j;

   aSg->RowCount = aMatA->GetRowCount() + 1;
   aSg->ColCount = aMatA->GetColCount() + 1;
   aSg->Cells[0][0] = "("+IntToStr(aMatA->GetRowCount())+"*"+IntToStr(aMatA->GetColCount())+")";
   for (i=1;i<aSg->RowCount;i++)
      aSg->Cells[0][i] = IntToStr(i);
   for (j=1;j<aSg->ColCount;j++)
      aSg->Cells[j][0] = IntToStr(j);
   for (i=1;i<aSg->RowCount;i++) {
      for (j=1;j<aSg->ColCount;j++) {
         aSg->Cells[j][i] = (*aMatA)(i,j);
      }
   }
}
//---------------------------------------------------------------------------
//根据字符串珊格得到数据
bool glb_GetData(TMatrix* aMatA,TStringGrid* aSg,AnsiString s)
{
   int i,j;

   for (i=1;i<aSg->RowCount;i++) {
      for (j=1;j<aSg->ColCount;j++) {
         try {
            (*aMatA)(i,j) = aSg->Cells[j][i];
         }
         catch(...) {
            glb_UserInfo("矩阵"+s+"的数据元素"+s+"["+IntToStr(i)+","+IntToStr(j)+"]不合法!");
            return false;
         }
      }
   }
   return true;
}
//---------------------------------------------------------------------------
//根据数据向量设置字符串珊格
void glb_SetCVetGrid(TCVector* aVet,TStringGrid* aSg,bool aCol)
{
   int i;

   if (aCol) { //如果是列珊格
      aSg->RowCount = aVet->GetDimCount() + 1;
      aSg->ColCount = 2;
      aSg->Cells[0][0] = "("+IntToStr(aVet->GetDimCount())+")";
      for (i=1;i<aSg->RowCount;i++) {
         aSg->Cells[0][i] = IntToStr(i);
         aSg->Cells[1][i] = (*aVet)(i);
      }
   }
   else{   //如果是行珊格
      aSg->RowCount = 2;
      aSg->ColCount = aVet->GetDimCount() + 1;
      aSg->Cells[0][0] = "("+IntToStr(aVet->GetDimCount())+")";
      for (i=1;i<aSg->ColCount;i++) {
         aSg->Cells[i][0] = IntToStr(i);
         aSg->Cells[i][1] = (*aVet)(i);
      }   
   }
}
//---------------------------------------------------------------------------
//根据字符串珊格得到向量数据
bool glb_GetCVetData(TCVector* aVet,TStringGrid* aSg,bool aCol,AnsiString s)
{
   int i;

   if (aCol) {
      for (i=1;i<aSg->RowCount;i++) {
         try {
            (*aVet)(i) = aSg->Cells[1][i];
         }
         catch(...) {
            glb_UserInfo("向量"+s+"的数据元素"+s+"["+IntToStr(i)+"]不合法!");
            return false;
         }
      }
   }
   else {
      for (i=1;i<aSg->ColCount;i++) {
         try {
            (*aVet)(i) = aSg->Cells[i][1];
         }
         catch(...) {
            glb_UserInfo("向量"+s+"的数据元素"+s+"["+IntToStr(i)+"]不合法!");
            return false;
         }
      }
   }

   return true;
}
//---------------------------------------------------------------------------

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -