扯皮的cplex-感觉时间不对

扯皮的cplex-感觉时间不对
import ilog.cplex.CpxMult;
import ilog.cplex.CpxNumExpr;
import ilog.cplex.IloCplex;
import ilog.concert.*;

public class MyCaculate
{

	// static
	// {
	// System.loadLibrary("cplex1271");
	// }

	static int length = 5000000;

	public static void main(String[] args) throws IloException
	{
		IloCplex cplex = new IloCplex();
		IloRange[] constraint = new IloRange[length];
		IloIntVar[] var = new IloIntVar[length];
		// 变量取值下界
		int[] lb = new int[length];
		for (int i = 0; i < length; i++)
			lb[i] = i;
		// 变量取值上界
		int[] ub = new int[length];
		for (int i = 0; i < length; i++)
			ub[i] = Integer.MAX_VALUE;
		// 变量名
		String[] varname = new String[length];
		for (int i = 0; i < length; i++)
			varname[i] = "x" + (i + 1);
		var = cplex.intVarArray(length, lb, ub, varname);

		// x1 + x2
		for(int i =1; i <= 10000;i++)
		{
			IloNumExpr r1 = cplex.sum(cplex.prod(1, var[0]), cplex.prod(1, var[i]));
			constraint[i] = cplex.addRange(10, r1, 10*i);
		}
//		IloNumExpr r2 = cplex.sum(cplex.prod(1, var[0]), cplex.prod(1, var[2]));
//		IloNumExpr r3 = cplex.sum(cplex.prod(1, var[0]), cplex.prod(1, var[3]));
//		IloNumExpr r4 = cplex.sum(cplex.prod(1, var[1]), cplex.prod(1, var[3]));
//		constraint[1] = cplex.addRange(20, r2, 100000, "c2");
//		constraint[2] = cplex.addRange(300, r3, 100000, "c3");
//		constraint[3] = cplex.addRange(4000, r4, 100000, "c4");

		// 变量前系数
		// y = -x*x
		// 计算y的最大值
		int[] objvals = new int[length];
		for (int i = 0; i < length; i++)
			objvals[i] = 1;
		cplex.addMaximize(cplex.scalProd(var, objvals));
		cplex.exportModel("my.lp");
		long t1 = System.currentTimeMillis();
		double d1 = cplex.getCplexTime();
		if (cplex.solve())
		{
			/*
			cplex.output().println("status = " + cplex.getStatus());
			cplex.output().println("sub status = " + cplex.getCplexSubStatus());
			for (int i = 0; i < var.length; i++)
				cplex.output().println(
						"var x" + (i + 1) + " = " + cplex.getValue(var[i]));
			cplex.output().println("y = " + cplex.getObjValue());
			cplex.output().println("best y = " + cplex.getBestObjValue());
			*/
			System.out.println("best y = " + (int) cplex.getBestObjValue());
			System.out.println("y = " + (int) cplex.getObjValue());

			long t2 = System.currentTimeMillis();
			double d2 = cplex.getCplexTime();
			System.out.println("pTime = "+(t2-t1));
			System.out.println("cpTime = "+(d2-d1));
		}
		else
		{

		}
		t1 = System.nanoTime();
		int j = 0;
		double k = 1;
		for(int i =0; i < Integer.MAX_VALUE;i++)
		{
			j=j+1*10;
		}	
		long t2 = System.nanoTime();
		System.out.println("pTime2 = "+(t2-t1));
		System.out.println(j);
		cplex.end();
	}

}

  

posted on 2017-07-24 18:34 好吧,就是菜菜 阅读( ...) 评论( ...) 编辑 收藏

转载于:https://www.cnblogs.com/shuiyonglewodezzzzz/p/7230402.html

你可能感兴趣的:(扯皮的cplex-感觉时间不对)