📄 net.java
字号:
package Hopfield;
public class Net {
private int class_number;
private Student[] students;
private Course[] courses;
private int[][] weight_A;
private double A,B,C,D;
public double[][] LayerU;
private double delta_t;
private int[][] weight_B;
//private int[] time;
//here c[student][course]
public Net(int n,int s,double a,double b,double c,double d,double t){
this.class_number = n;
this.delta_t = t;
this.students = new Student[s];
for(int i = 0; i<s; i++){
this.students[i] = new Student();
}
this.courses = new Course[n];
for(int i = 0; i<n; i++){
this.courses[i] = new Course();
}
this.A = a;
this.B = b;
this.C = c;
this.D = d;
for(int i = 0; i<n; i++){
this.courses[i].setNumber(i,n);
//this.time[i]=0;
}
for(int i = 0; i<s; i++){
this.students[i].setNumber(i);
}
this.weight_A = new int[n][n];
this.weight_B = new int[n][n];
this.LayerU = new double[n][n];
for(int i = 0; i<class_number; i++){
for(int j=0; j<class_number; j++){
this.weight_A[i][j] = 0;
this.weight_B[i][j] = 0;
this.LayerU[i][j] = 0;
}
}
}
public void setCourse(int s,int [] c){
this.students[s].setCourse(c);
}
public void generateAMartix(){
for(int i =0; i<this.students.length; i++){
int [] c_temp = this.students[i].getCourse();
if(c_temp[0]!=0 && c_temp[1]!=0){
this.weight_A[c_temp[0]][c_temp[1]]=1;
this.weight_A[c_temp[1]][c_temp[0]]=1;
}
}
for(int i = 0; i<this.class_number; i++){
this.weight_A[i][i] = 0;
}
for(int i = 0; i<this.class_number;i++){
for(int j = 0;j<this.class_number;j++){
if(this.weight_A[i][j]==1){
this.weight_B[i][j]=0;
}else{
this.weight_B[i][j]=1;
}
}
}
}
public int[][] getWeight(){
return this.weight_A;
}
public int[][] getWeightB(){
return this.weight_B;
}
public double calculateU(int v,int r){
int [] time_temp = new int[class_number];
double term1 = 0;
time_temp = this.courses[v].getTime();
int term1_temp = 0;
for(int i = 0; i<time_temp.length; i++){
term1_temp = term1_temp + time_temp[i];
}
term1 = -this.A*(term1_temp-1);//*time_temp[r]; // A term This corresponds to the assignment
// of one register to each variable.
double term2 = 0;
double term2_temp = 0;
int [] time_temp2 = new int[class_number];
for(int i = 0 ; i< time_temp2.length; i++){
time_temp2 = this.courses[i].getTime();
term2_temp = term2_temp + time_temp2[r]*this.weight_A[i][v];
}
term2 = -this.B*term2_temp;//*time_temp[r]; // B term if all of the variables which are
// active simultaneously are not assigned to
// the same register
double term3 = 0; // C term if all of the variables are assigned to
term3 = -this.C*(r-1);///class_number;
//term3 = -this.C*(r-class_number)/class_number;//register #l.
double term4 = 0; // hill climb
int g = this.gFunction(v);
double m_temp = 0;
for(int i = 1; i < this.class_number; i++){
m_temp = m_temp + this.weight_A[v][i];
}
term4 = this.D*g*m_temp;
double term5 = 0;
int [] time_temp5 = new int[class_number];
time_temp5 = this.courses[v].getTime();
term5 = -this.C*((r-1)/this.class_number+1-time_temp5[r]);
//term5 = term3*t5;
double u =0;
u = term1 + term2 + term3;// + term4;//+term5;// + term4;
u = u*this.delta_t;
//System.out.print(term1 +" +");System.out.print(term2 +" +");
//System.out.print(term3 +" +");System.out.print(term4 +" =");
return u;
}
public int gFunction(int v){
int [] temp = this.courses[v].getTime();
int time = 0;
for(int i = 0; i<this.class_number; i++){
time = time + temp[i];
}
int g;
if(time == 0){
g = 1;
}else{
g = 0;
}
return g;
}
public double calculateE(){
double E = 0;
double term1 = 0;
double term2 = 0;
double term3 = 0;
double sum = 0;
double term1_temp = 0;
double term1_temp1 = 0;
for(int i = 1; i<this.class_number; i++){
sum = 0;
int [] temp = this.courses[i].getTime();
for(int j = 0; j<temp.length; j++){
sum = sum + temp[j];
}
sum--;
term1_temp = sum*sum;
term1_temp1 = term1_temp1 + term1_temp;
}
//term1 = term1 + term1_temp1;
term1 = this.A/2*term1_temp1;
//double term2 = 0;
double sum1 = 0;
double sum2 = 0;
double sum3 = 0;
for(int i = 0; i<this.class_number; i++){
sum2 = 0;
for(int j = 1; j<this.class_number; j++){
sum1 = 0;
for(int k = 1; k<this.class_number; k++){
int [] t_temp = this.courses[j].getTime();
int [] t_temp1 = this.courses[k].getTime();
sum1 = sum1 + t_temp[i]*t_temp1[i]*this.weight_A[k][j];
}
sum2 = sum2 + sum1;
}
sum3 = sum3 + sum2;
}
term2 = sum3*this.B;
//double term3 = 0;
double temp3 = 0;
double temp33=0;
for(int i = 1; i<this.class_number; i++){
int [] t_temp = this.courses[i].getTime();
temp3 = 0;
for(int j =0; j<this.class_number; j++){
temp3 = temp3 + t_temp[j]*(j-1)/this.class_number;
}
temp33 += temp3;
}
term3 = temp33*this.C;//
//System.out.print(term1 +" +");
//System.out.print(term2 +" +");System.out.print(term3 +" =");
E = term1 + term2 + term3;
return E;
}
public double generateOutput(double uu){
double u = 1/(1+Math.exp(-uu));
return u;
}
public int neuralModel(double u){
int v = 0;
if(u<=0){
v = 0;
}else{
v = 1;
}
return v;
}
public void setTime(int c,int set_t){
this.courses[c].setTime(set_t);
}
public void erTime(int c,int set_t){
this.courses[c].erTime(set_t);
}
public int[] getTiem(int c){
int [] temp = this.courses[c].getTime();
return temp;
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -