Beispiel #1
0
int
main (int argc, char ** argv) {
	// Creating the instatnce of new machine.
	engine = new StateMachine (matchingHandler);
	IEvent* event = NULL;

	// Creating two sequences to monitor.
	Sequence seqOne = Sequence((int *)SequenceOne, 6, "FIRST");
	Sequence seqTwo = Sequence((int *)SequenceTwo, 4, "ANY");
	// Adding these two sequences to the engine.
	engine->AddSequence(seqOne);
	engine->AddSequence(seqTwo);

	// Handaling the user kill application signal, for clean application close.
	signal(SIGINT, sig_handler);
	// Main loop.
	while (amWorking) {
		switch (TEST[TEST_INDEX]) {
			case STATE_A:
				CreateA (&event);
			break;
			case STATE_B:
				CreateB (&event);
			break;
			case STATE_C:
				CreateC (&event);
			break;
			default:
			break;
		}
		
		if (event != NULL) {
			// Announcing the event.
			engine->SetEvent (event);
		}
		
		// Round test.
		if ((++TEST_INDEX) == 20) {
			TEST_INDEX = 0;
		}
		
		// Fetching event from test repo each one second.
		usleep (1000000 * 1);
	}

	// Resource free.
	delete engine;
	
	std::cout << "Exit 'state-test'" << std::endl;
	return 0;
}
Beispiel #2
0
DWORD WINAPI ThreadFunA(LPVOID pM)  
{  
	CreateA();
	printf("子线程的线程ID号为:%d\n子线程输出Hello World\n", GetCurrentThreadId());  
	return 0;  
}
Beispiel #3
0
void ADMMCut::MakeLayers()
{
	// Initial Cutting Edge Setting
	InitState();

	debug_ = false;
	int cut_count = 0;
	vector<double> cut_energy;
	vector<double> res_energy;
	do
	{
		/* Recreate dual graph at the beginning of each cut */
		SetStartingPoints(cut_count);
		CreateA();

		ptr_stiff_->CalculateD(D_, x_, 0, 0, cut_count);

		///* for rendering */
		//if (cut_count == 0)
		//{
		//	WriteWeight();
		//	WriteStiffness("offset1.txt", "rotation1.txt");
		//	getchar();
		//}
		//if (cut_count == 4)
		//{
		//	WriteStiffness("offset2.txt", "rotation2.txt");
		//	getchar();
		//}
		//if (cut_count == 6)
		//{
		//	WriteStiffness("offset3.txt", "rotation3.txt");
		//	getchar();
		//}

		/* set x for intial cut setting */
		SetBoundary();

		/*
		* energy specify:
		* cut		 energy : | A * x |
		* defomation energy : norm(K D - F)
		*/
		ptr_stiff_->CreateGlobalK(x_);
		ptr_stiff_->CreateF(x_);
		SpMat K_init = *(ptr_stiff_->WeightedK());
		VX	  F_init = *(ptr_stiff_->WeightedF());


		double icut_energy = 0;
		VX V_Cut = A_ * x_;
		for (int i = 0; i < Md_; i++)
		{
			icut_energy += abs(V_Cut[i]);
		}
		double ideform_energy = (K_init * D_ - F_init).norm();

		cout << "****************************************" << endl;
		cout << "ADMMCut Round : " << cut_count << endl;
		cout << "Initial cut energy before entering ADMM: " << icut_energy << endl;
		cout << "Initial Lagrangian energy before entering ADMM: " << ideform_energy << endl;
		cout << "---------------------------------" << endl;

		int rew_count = 0;
		VX x_prev;
		VX D_prev;

		/* Output energy list for reweighting process in a single
		graph cut problem, energy.size() = number of reweighting
		process performed.
		cut energy = |A_ * x_| = sum_{e_ij} w_ij * |x_i - x_j|
		res energy = (K(x)D - F(x)).norm()
		*/

		cut_energy.clear();
		res_energy.clear();

		cut_energy.push_back(icut_energy);
		res_energy.push_back(ideform_energy);

		do
		{
			/* Reweighting loop for cut */

			int ADMM_count = 0;
			x_prev = x_;
			CreateC(cut_count, rew_count);

			do
			{
				cout << "ADMMCut Round: " << cut_count << ", reweight iteration:" << rew_count
					<< ", ADMM " << ADMM_count << " iteration." << endl;

				/*-------------------ADMM loop-------------------*/
				CalculateX();

				D_prev = D_;
				CalculateD();

				UpdateLambda();

				/*-------------------Residual Calculation-------------------*/
				SpMat Q_prev;
				SpMat Q_new;
				CalculateQ(D_prev, Q_prev);
				CalculateQ(D_, Q_new);

				/* Update K reweighted by new x */
				ptr_stiff_->CreateGlobalK(x_);
				ptr_stiff_->CreateF(x_);
				SpMat K_new = *(ptr_stiff_->WeightedK());
				VX    F_new = *(ptr_stiff_->WeightedF());

				dual_res_ = penalty_ * (D_prev - D_).transpose() * K_new.transpose() * Q_prev
					+ lambda_.transpose() * (Q_prev - Q_new);
				primal_res_ = K_new * D_ - F_new;

				/*-------------------Screenplay-------------------*/
				double new_cut_energy = x_.dot(H1_ * x_);

				cout << "new quadratic func value record: " << new_cut_energy << endl;
				cout << "dual_residual : " << dual_res_.norm() << endl;
				cout << "primal_residual(KD-F) : " << primal_res_.norm() << endl;

				cout << "---------------------" << endl;
				ADMM_count++;
			} while (!TerminationCriteria(ADMM_count));

			/* One reweighting process ended! */
			/* Output energy and residual */

			double energy = 0;
			VX V_Cut = A_ * x_;
			for (int i = 0; i < Md_; i++)
			{
				energy += ptr_dualgraph_->Weight(i) * abs(V_Cut[i]);
			}

			/*-------------------Screenplay-------------------*/
			double res_tmp = primal_res_.norm();
			cout << "Cut " << cut_count << " Reweight " << rew_count << " completed." << endl;
			cout << "Cut Energy :" << energy << endl;
			cout << "Res Energy :" << res_tmp << endl;
			cout << "<-<-<-<-<-<-<-<-<-<-<-<-<-<-<-<-<-" << endl;

			cut_energy.push_back(energy);
			res_energy.push_back(res_tmp);

			/* write x distribution to a file */
			string str_x = "Cut_" + to_string(cut_count) + "_Rew_" + to_string(rew_count) + "_x";
			Statistics tmp_x(str_x, x_);
			tmp_x.GenerateVectorFile();

			rew_count++;
		} while (!UpdateR(x_prev, rew_count));

		/* Output reweighting energy history for last cut process */
		string str_eC = "Cut_" + to_string(cut_count) + "_Cut_Energy";
		Statistics s_eC(str_eC, cut_energy);
		s_eC.GenerateStdVecFile();

		string str_eR = "Cut_" + to_string(cut_count) + "_Res_Energy";
		Statistics s_eR(str_eR, res_energy);
		s_eR.GenerateStdVecFile();

		/* Update New Cut information to Rendering (layer_label_) */

		UpdateCut();

		fprintf(stdout, "ADMMCut No.%d process is Finished!\n", cut_count);
		cut_count++;

	} while (!CheckLabel(cut_count));

	fprintf(stdout, "All done!\n");
}