package org.cloudbus.cloudsim.codes.arima;

import java.io.*;
import java.nio.file.Path;
import java.nio.file.Paths;
import java.util.ArrayList;

public class Main
{
	public static void main(String args[])
	{

			double[] data=new double[]{1.59,1.61,1.64,1.66,1.67,1.75,1.92,2.02,2.21,2.89,3.2,3.93};
			ARIMAModel arima = new ARIMAModel(data);

			ArrayList<int []> list = new ArrayList<>();
			int period =1;
			int modelCnt = 5, cnt = 0;			//通过多次预测的平均值作为预测值
			double[] oldlist=new double[modelCnt];
			double [] tmpPredict = new double [modelCnt];
			for (int k = 0; k < modelCnt; ++k)			//控制通过多少组参数进行计算最终的结果
			{
				int [] bestModel = arima.getARIMAModel(period, list, k != 0);
				if (bestModel.length == 0)
				{
					tmpPredict[k] = data[data.length - period];
					cnt++;
					break;
				}
				else
				{
					double predictDiff = arima.predictValue(bestModel[0], bestModel[1], period);
					tmpPredict[k] = arima.aftDeal(predictDiff, period);


					//System.out.println("预测值为：" + tmpPredict[k]);
					oldlist[k]=tmpPredict[k];
					cnt++;
				}

				System.out.println("BestModel is " + bestModel[0] + " " + bestModel[1]);
				list.add(bestModel);

			}
			double sumPredict = 0.0;
			for (int k = 0; k < cnt; ++k)
			{
				sumPredict += tmpPredict[k] / (double)cnt;
			}
			System.out.println("Predict value="+sumPredict);

			}
	}

