📄 tcnn.cpp
字号:
#include <time.h>
#include <stdlib.h>
#include <math.h>
#include "TCNN.h"
TCNN::TCNN(int n, int m, int** machine/* = NULL */, int** protime/* = NULL */, int mcost/* = -1 */)
:HNN(n, m, machine, protime), mincost(mcost)
{
srand(time(0));
}
void TCNN::setTCPara(double k, double a, double b, double I0, double z0)
{
this->k = k;
this->a = a;
this->b = b;
this->I0 = I0;
this->z0 = z0;
}
bool TCNN::run()
{
//初始化神经网络
cout.close();
cout.open("result.txt");
cout<<"Initial state:"<<endl;
initI();
printI();
initNeros();
printNeroInputs();
printNeroOutputs();
z = z0;
cout<<"\n\nStart to run..."<<endl;
int num = 0;
//运行神经网络
double starttime = GetTickCount();
for(int t = 0; t <1000; t++)
{
cout<<"\nTime "<<t+1<<":"<<endl;
//解神经元运动方程: u(t+1) = k*u(t)+a*M-z(t)(v(t)-I0)
solveMotionEqu();
printNeroInputs();
//计算神经元输出
neroOutputs();
printNeroOutputs();
//判断神经网络是否已经收敛
double pE = E;
countE();
cout<<"E: "<<E<<endl;
if (fabs(E-pE)<0.00001) num++;
else num = 0;
if (num > 15 && fabs(E)<0.00001) break;
}
double endtime = GetTickCount();
double runtime = (endtime - starttime)/1000.0;
formatTime(runtime);
//处理所得调度结果
chart->setMatrix(v);
chart->constructGantt();
cost = chart->getMaxTime();
return chart->isValid();
}
void TCNN::solveMotionEqu()
{
//累计w*v,得神经运动方程项M
countM();
//计算自反馈连接权z
z = z*(1-b);
//解基于退火策略的混沌动力学方程
for(int i = 0; i < N; i++)
{
for(int j = 0; j < N+1; j++)
{
u[i][j] = k*u[i][j]+a*M[i][j]-z*(v[i][j]-I0);
}
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -