⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 loqo2.c

📁 优化算法loqo的算法源代码。Purpose: solves quadratic programming problem for pattern recognition for support vec
💻 C
字号:
/*********************************************************************//***    Copyright (c) Robert J. Vanderbei, 1994                    ***//***    All Rights Reserved                                        ***//*********************************************************************/#include <string.h>#include "Quad/Quad.h"#ifdef __cplusplusextern "C" {#endif#include "loqo.h"int my_st_rule(void *vlp);void my_init(void *vlp);main(	int	argc, 	char	*argv[]){	char	fname[80];	/* solution file name */	LOQO	*lp;	fflush(stdout);	lp = openlp();	if (lp == NULL)	{		my_exit(11,"cannot open another LP problem");	}	argc--;	argv++;	  /* strip ``loqo'' off	from the command line */	readlp(argc,argv,lp);	/***************************************************************	*  Set the stopping rule and initialization rule functions	*  to point to the ones	defined	here.	***************************************************************/	lp->stopping_rule = my_st_rule;	lp->init_vars =	my_init;	/***************************************************************	*  Now solve the lp.	***************************************************************/	solvelp( lp );	inv_clo();	strcpy(fname, lp->name);	strcat(fname, ".out");	writesol(lp,fname);	closelp(lp);	return(0);}int my_st_rule(void *vlp){	LOQO *lp = vlp;	int optflg = -1;      /* anything >= 1 means not optimal 				 0 means optimal,				 -1 means not done yet */	static double old_primal_obj = 1.0e+30;	/***************************************************************	*  Here	is an incredibly stupid	stopping rule but it generally	*  works okay.	optflg = 0 means that an optimal solution has	*  been	found.	***************************************************************/	if ( ABS(lp->primal_obj	- old_primal_obj) < 1.0e-5 ) 		optflg = 0; /* OPTIMAL SOLUTION	FOUND */	/***************************************************************	*  Save	current	primal objective value for next	time around.	***************************************************************/	old_primal_obj = lp->primal_obj;	return optflg;}void my_init(void *vlp){	LOQO *lp = vlp;	int j;	/**************************************************************	*  Since the default init initializes many things, it is best	*  to call it first and	then change what you want.  This way	*  nothing will	be forgotten.	**************************************************************/	deflt_init(lp);	/**************************************************************	*  If you want to set all the primal variables to one, use 	*  something like this.	**************************************************************/	for (j=0; j<lp->n; j++){	    lp->x[j] = 1.0;	}}#ifdef __cplusplus}#endif

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -