<>/*
Name: NetWorkSimplex.h
Copyright: Knight-Studio
Author: Ran NI
Date: 05-07-04 15:19
Description: The Declaration of the NetWorkSimplex Class
*/</P>
<>#include <vector>
#include <fstream>
#include <math.h>
#include <complex>
#ifndef _NETWORKSIMPLEX_H_
#define _NETWORKSIMPLEX_H_</P>
<>using namespace std;</P>
<P>class NetWorkSimplex
{
public:
NetWorkSimplex(vector<double> aa,vector<double> bb,vector<vector<bool> > bbb,vector<vector<double> > cc,vector<vector<double> > uu,vector<vector<double> > ll):a(aa),b(bb),C(cc),U(uu),L(ll),B(bbb),Potential(aa.size()+bb.size()+2,0),DepthFirstSerchSeries(aa.size()+bb.size()+2,0),Pred(aa.size()+bb.size()+2,0),Depth(aa.size()+bb.size()+2,0),Thread(aa.size()+bb.size()+2,0),CostPotential(1)
{
if(Cost.size()!=0)
{
Cost.clear();
}
if(Connect.size()!=0)
{
Connect.clear();
}
if(Bound.size()!=0)
{
Bound.clear();
}
if(Length.size()!=0)
{
Length.clear();
}
if(SpanningTree.size()!=0)
{
SpanningTree.clear();
}
if(x.size()!=0)
{
x.clear();
}
for(int i=0;i<(int)(a.size()+b.size()+2);++i)
{
vector<double> zz(a.size()+b.size()+2,0);
vector<bool> c(a.size()+b.size()+2,false);
Connect.push_back(c);
Cost.push_back(zz);
x.push_back(zz);
Length.push_back(zz);
Bound.push_back(zz);
}
for(int i=0;i<(int)B.size();++i)
{
for(int j=0;j<(int)B.size();++j)
{
if(B[j]==true)
{
Cost[i+1][j+a.size()+1]=C[j];
Length[i+1][j+a.size()+1]=L[j];
Bound[i+1][j+a.size()+1]=U[j];
Connect[i+1][j+a.size()+1]=true;
}
}
}
for(int i=0;i<(int)a.size()+1;++i)
{
if(i>0)
{
Connect[0]=true;
Bound[0]=a[i-1];
}
}
for(int i=(int)Connect.size()-1;i>(int)Connect.size()-b.size()-2;--i)
{
if(i<(int)Connect.size()-1)
{
Connect[Connect.size()-1]=true;
Bound[(int)Connect.size()-1]=b[(int)b.size()-((int)Connect.size()-i-1)];
}
}
Change=0;
}
void InitialSpanningTree();
double LowestCost(int &c);
vector<int> FindLine(int s,int t);
int FindLeaf(vector<vector<bool> >);
void ComputeNodePotential();
complex<int> LeavingArc(complex<int>);
bool Judge(int ,int,bool);
void ComputeArcFlow();
complex<int> EnteringArc();
void DepthFirstSearch();
bool Judge(complex<int> c);
void ComputePotantial();
void Update(complex<int>,complex<int>);
vector<vector<double> > GetOptimalSolution()
{
return Solution;
}
protected:
vector<double> a;
vector<double> b;
vector<vector<bool> > B;
vector<vector<double> > C;
vector<vector<double> > U;
vector<vector<double> > L;
vector<vector<bool> > Connect;
vector<vector<double> > Cost;
vector<vector<double> > Bound;
vector<vector<double> > Length;
vector<vector<bool> > SpanningTree;
vector<double> Potential;
vector<vector<double> > x;
vector<vector<double> > Solution;
vector<int> DepthFirstSerchSeries;
vector<int> Pred;
vector<int> Depth;
vector<int> Thread;
vector<vector<double> > CostPotential;
int Change;
};
#endif
</P> |