// -----------------------------------------------------------------------------
// Place some text (called from another add-on)
// -----------------------------------------------------------------------------
GSErrCode __ACENV_CALL	CreateTextCommandHandler (GSHandle parHdl, GSPtr resultData, bool silentMode)
{
UNUSED_PARAMETER (resultData);

	TextParams		params;
	TextParamsInd	parHdlInd;
	bool			ok;
	GSErrCode		err = NoError;

	// setup command parameters
	DefaultParams (&params);
	ProcessParams (&params, &parHdlInd, parHdl);
	if (!silentMode) {
		ok = InputParams (&params, &parHdlInd);
		if (!ok)
			return NoError;

		// return parameters modified in the dialog
		ModifyParams (&params, &parHdlInd, parHdl);
	}

	// do the job
	err = CreateAText (&params);

	return err;
}	// CreateTextCommandHandler
static void		Do_CreateAText ()
{
	bool			okHit;
	TextParams		textPars;
	Int32			version = 0;
	GSSize			nBytes = 0;
	unsigned short	platformSign = GS::Act_Platform_Sign;

	BNZeroMemory (&textPars, sizeof (TextParams));

	ACAPI_GetPreferences_Platform (&version, &nBytes, NULL, NULL);
	if (version == 1 && nBytes == sizeof (TextParams)) {
		ACAPI_GetPreferences_Platform (&version, &nBytes, &textPars, &platformSign);
		if (platformSign != GS::Act_Platform_Sign) {
			GS::PlatformSign	inplatform = (GS::PlatformSign) platformSign;
			IVShort (inplatform, &textPars.pen);
			IVShort (inplatform, &textPars.filler_1);
			IVLong (inplatform, &textPars.filler_2);
			IVDouble (inplatform, &textPars.size);
			// char		content [256];
		}
	} else
		DefaultParams (&textPars);


	okHit = InputParams (&textPars, NULL);
	if (okHit) {
		ACAPI_SetPreferences (1, sizeof (TextParams), &textPars);
		CreateAText (&textPars);
	}

	return;
}		// Do_CreateAText
Ejemplo n.º 3
0
bool GenAlgo::Run(const int func_no)
{

	int nPopu,
		totGen,
		indx_f = 0,				//Index of one parent.	
		indx_m = 0;				//Index of another parent.
	bool rslt;		

	func_num = func_no;

	/*INPUT PARAMETERS FROM USER*/
	rslt = InputParams();

	totGen = nGEN;
	Fitness_Calculations = 0;	//Setting the fittness calculations count to 0.

	/*INITIALIZE THE 0TH GEN POPULATION*/
	Initialize(); 
	Fitness_Calculations += nPOPU;

	do
	{		
		CHILDREN child1, child2;	//This are used to store the children temporaryly
		nPopu = nPOPU;	

		//ShowPopu();

		if (Fitness_Calculations > MaxFitness_Calculations)	break;		//Maximum number of fittness calculations has occured.

		while ((nPopu -= 2) >= 0)
		{
			/*allocation memory*/
			child1.fChromo = new char[lenChromo_tot];
			child2.fChromo = new char[lenChromo_tot];
			child1.fFitness = child2.fFitness = NULL;


			/*SELECT PARENTS*/
			GetParents(&indx_f, &indx_m);

			/*DO CROSSOVER*/
			CreateChildren(child1, child2, &indx_f, &indx_m);

			/*MUTATES THE CHILDREN*/
			MutateChildren(child1);
			MutateChildren(child2);

			/*CALCULATE FITNESS OF OFFSPRINGS*/
			child1.fFitness = CalculateFitness(child1);	
			child2.fFitness = CalculateFitness(child2);
			Fitness_Calculations += 2;

			/*IDENTIFY GOOD CHILDS AND STORE THEM*/
			IdentifyChilds(child1, child2, indx_f, indx_m, nPOPU - nPopu - 2);


			/*cleaning up*/
			indx_f = indx_m;
			delete[] child1.fChromo;
			delete[] child2.fChromo;
			child1.fFitness = child2.fFitness = NULL;
		}

		/*UPDATE NEW GEN POPULATION*/
		CopyPopulation(nGEN - totGen);

		std::cout << "\nGen no :: " << nGEN - totGen << std::endl;
		std::cout << "**************" << std::endl;
		ShowDude();

	} while (--totGen);

	ShowStatistics();

	ShowDude();		

return true;
}