ECOS__C使用说明

简单记录ECOS_BB使用方法

ECOS_BB适用于,包含整数型变量和bool型变量的凸优化问题,整体上是在ecos上进行扩展,ecos使用方法有时间进行补充

	ecos_bb_pwork* prob = ECOS_BB_setup(
		n,//变量个数       n
		m,//不等式约束个数  m
		0,//等式约束个数    p
		m,//线性不等式个数  l
		0,//二阶锥个数      ncones
		NULL,			// 二阶锥大小数组  q
		0,				//显示结果
		feas_Gx,feas_Gp,feas_Gi,//不等式矩阵//列信息//行信息
		NULL, NULL, NULL,//等式约束矩阵
		feas_c,		//c*x‘性能指标
		feas_h,		//不等式约束常数项
		NULL,			//等式约束常数项
		1, bool_idx,	//bool变量个数//bool变量索引
		0 , NULL,		//整数型个数及索引 
		NULL);

实例程序

                                       min(\begin{bmatrix} -1.1 & -1 \end{bmatrix} \begin{bmatrix} x1\\x2 \end{bmatrix} )

                                       sub.\begin{bmatrix} 2&1 \\ 3&4 \end{bmatrix} \begin{bmatrix} x1\\x2 \end{bmatrix} \leq \begin{bmatrix} 4\\12 \end{bmatrix}

                                               x1 is bool

idxint n = 2;
	idxint m = 2;
	pfloat feas_Gx[4] = {2.0, 3.0, 1.0, 4.0};
	idxint feas_Gp[3] = {0, 2, 4};
	idxint feas_Gi[4] = {0, 1, 0, 1};

	pfloat feas_c[2] = {-1.1, -1.};
	pfloat feas_h[2] = {4., 12.};

	idxint bool_idx[1] = {0};

	/* Answer: */
	pfloat x[2] = {1.0, 2.0};

	idxint i, ret_code, pass;
	
	ecos_bb_pwork* prob = ECOS_BB_setup(
		n,//变量个数       n
		m,//不等式约束个数  m
		0,//等式约束个数    p
		m,//线性不等式个数  l
		0,//二阶锥个数      ncones
		NULL,			// 二阶锥大小数组  q
		0,				//显示结果
		feas_Gx,feas_Gp,feas_Gi,//不等式矩阵//列信息//行信息
		NULL, NULL, NULL,//等式约束矩阵
		feas_c,		//c*x‘性能指标
		feas_h,		//不等式约束常数项
		NULL,			//等式约束常数项
		1, bool_idx,	//bool变量个数//bool变量索引
		0 , NULL,		//整数型个数及索引 
		NULL);
	
	printf("Passed setup \n");

	prob->stgs->verbose = 0;
	ret_code = ECOS_BB_solve(prob);
	
	pass = 1;

	printf("Soln:");
	for (i=0; i<n; ++i){
		pass &= float_eqls(x[i] ,prob->x[i], prob->stgs->integer_tol );
		printf("%f ", prob->x[i]);
	}
	ECOS_BB_cleanup(prob, 0);

第一次用,,,相信会越写越好的。。。有人看的话,,先将就吧,,没人看,就当记录自己

猜你喜欢

转载自blog.csdn.net/weixin_40393069/article/details/90081137