dimanche 20 janvier 2019

My annotations does not work correctly, calculations results are wrong

I have a model model in which the values are marked BIND annotation. The annotation should allow:

  • assigning values to the input variables of the model before performing calculations

  • downloading the values of variables calculated in the model (after calculations have been carried out).

I read the data from the file and transfers their values to the variables in the model class by reflection. My problem is that the annotation does not change anything. I have wrong calculation results.

import java.lang.annotation.*;

@Target(ElementType.FIELD)
@Retention(RetentionPolicy.RUNTIME)
public @interface Bind {

}  

public class Model1 {
@Bind private int LL;
@Bind private  double[] twKI;
@Bind private  double[] twKS;
@Bind private  double[] twINW;
@Bind private  double[] twEKS;
@Bind private  double[] twIMP;
@Bind private double[] KI;
@Bind private double[] KS;
@Bind private double[] INW;
@Bind private double[] EKS;
@Bind private double[] IMP;
@Bind private double[] PKB;

public Model1() {}

public void run() {
 PKB = new double[LL];
 PKB[0] = KI[0] + KS[0] + INW[0] + EKS[0] - IMP[0];
 for (int t=1; t < LL; t++) {
  KI[t] = twKI[t]* KI[t-1];
  KS[t] = twKS[t]* KS[t-1];
  INW[t] = twINW[t]* INW[t-1];
  EKS[t] = twEKS[t]* EKS[t-1];
  IMP[t] = twIMP[t]* IMP[t-1];
  PKB[t] = KI[t] + KS[t] + INW[t] + EKS[t] - IMP[t];
 }
}
}

So it gives value in the mod class from another class

Field fieldLL = class1.getDeclaredField("LL");
        fieldLL.setAccessible(true);
        fieldLL.setInt(modelName, LL);

        Field fieldtkWI  = class1.getDeclaredField("twKI");
        fieldtkWI.setAccessible(true);
        fieldtkWI.set(modelName, twKI);

        Field fieldtwKS = class1.getDeclaredField("twKS");
        fieldtwKS.setAccessible(true);
        fieldtwKS.set(modelName, twKS); 

etc.

And call the run method

Method method = class1.getDeclaredMethod("run");
        method.invoke(modelName);

            Field fieldPKB = class1.getDeclaredField("PKB");
            fieldPKB.setAccessible(true);
            PKB = (double[]) fieldPKB.get(modelName);

And for example, the value pf pkb from my code is :

PKB     1714273.4   1893950.2719999999  2115659.0986     
2362962.8638815996    2638886.923654132

And it should be

 PKB    1714273.4   1815516.032 1944672.4554000003   
 2083203.6166496002     2231733.528866293  

Only first value is correct





Aucun commentaire:

Enregistrer un commentaire