Exemplo n.º 1
0
bool oslom_net_global::fusion_with_empty_A(int_matrix & its_submodules, DI & A, double & bs) {
	
	/*  
		its_submodules are the modules to check. the question is if to take its_submodules or the union of them 
		the function returns true if it's the union, grc1 is the union cleaned and bs the score
	 */
		
	DI group;
	from_int_matrix_and_deque_to_deque(its_submodules, A, group);

	//cout<<"trying a module of "<<group.size()<<" nodes"<<endl;

	bs=CUP_check(group, A);
	
	if(A.size()<=paras.coverage_percentage_fusion_left * group.size()) {
		A.clear();
		bs=1;
		return false;
	}
	
	
	bool fus= fusion_module_its_subs(A, its_submodules);
	

		
	if(fus==false)
		return false;
	else 
		return true;
	
	
	

}
Exemplo n.º 2
0
int KSGDevice::ExecuteTask(DeviceNodeType* node,Task* task)
{
	// 检查是否支持指令
	DI * devintr = FindDevInterface(task->GetTaskCode());
	if(!devintr)
	{
		throw TaskNotSupportedException();
	}
	//
	int ret;
	ACE_HANDLE handler;
	ret = find_handler(node,&handler);
	if(ret)
	{
		ACE_DEBUG((LM_ERROR,"连接指定设备失败!"));
		return TASK_ERR_CONNECT;
	}
	// 执行指令
	try
	{
		task->_handle = handler;
		ret = devintr->ExecuteTask(node,task);
	}
	catch(...)
	{
		// ignore
	}
	// 如果指令执行超时,关闭连接
	if(release_handler(node,&handler,ret != TASK_SUCCESS))
	{
		ACE_DEBUG((LM_ERROR,"释放连接失败"));
	}
	return ret;
}
Exemplo n.º 3
0
//////////////////////////////////////////////////////////////////////////
// KSGDevice
int KSGDevice::ExecuteTask(DeviceNodeType* node,Task* task)
{
	// 检查是否支持指令
	DI * devintr = FindDevInterface(task->GetTaskCode());
	if(!devintr)
	{
		throw TaskNotSupportedException();
	}
	//
	int ret;
	ACE_HANDLE handler;
	// 先检查 handler 是否可用
	if(node->GetState() == KSGDeviceNode::dsOffline)
	{
		ret = create_handler(node,&handler);
	}
	else if((ret = find_handler(node,&handler)))
	{
		// 尝试连接
		ret = create_handler(node,&handler);
		if(ret)
		{
			// 连接失败
			node->SetState(KSGDeviceNode::dsOffline);
		}
	}
	if(ret)
	{
		return TASK_ERR_CONNECT;
	}
	
	// 执行指令
	ret = devintr->ExecuteTask(node,task);
	if(ret)
	{
		// 如果指令执行超时
		if(ret == TASK_ERR_TIMEOUT)
		{
			// 尝试重新连接
			if(create_handler(node,&handler))
			{
				// 重连失败
				node->SetState(KSGDeviceNode::dsError);
			}
		}
	}
	return ret;
}
Exemplo n.º 4
0
int KSGDevice::ExecuteTask(DeviceNodeType* node,Task* task)
{
	// 检查是否支持指令
	bool free_conn = false;
	DI devintr = FindDevInterface(task->GetTaskCode());
	if(!devintr)
	{
		throw TaskNotSupportedException();
	}
	//
	int ret;
	ACE_HANDLE handler;
	ret = find_handler(node,&handler);
	if(ret)
	{
		ACE_DEBUG((LM_ERROR,"连接指定设备失败!"));
		return TASK_ERR_CONNECT;
	}
	// 执行指令
	try
	{
		task->_handle = handler;
		ret = devintr->ExecuteTask(node,task);
	}
	catch(...)
	{
		// ignore
	}
	// 如果指令执行超时,关闭连接
	if(node->connect_module() == KSGDeviceNode::cm_short_conn
		|| ret != TASK_SUCCESS)
	{
		free_conn = true;
	}
	try
	{
		if(release_handler(node,&handler,free_conn))
		{
			ACE_DEBUG((LM_ERROR,"释放连接失败"));
		}
	}
	catch (...)
	{
		ACE_DEBUG((LM_ERROR,"关闭连接异常!"));
	}
	return ret;
}
Exemplo n.º 5
0
void from_int_matrix_and_deque_to_deque(int_matrix & its_submodules, const DI & A, DI & group) {
	
	// it merges A and its_submodules in group
	
	set<int> all_the_groups;
	for(UI i=0; i<its_submodules.size(); i++) {
		
		
		for(UI j=0; j<its_submodules[i].size(); j++)
			all_the_groups.insert(its_submodules[i][j]);
		
	}
	
	for(UI i=0; i<A.size(); i++)
		all_the_groups.insert(A[i]);
	
	
	set_to_deque(all_the_groups, group);
	


}
Exemplo n.º 6
0
int KSGDevice::ExecuteTask(DeviceNodeType* node,Task* task)
{
	// 检查是否支持指令
	bool free_conn = false;
	DI devintr = FindDevInterface(task->GetTaskCode());
	if(!devintr)
	{
		ACE_DEBUG((LM_ERROR,"设备不支持该指令..."));
		throw TaskNotSupportedException();
	}
	//
	int ret;
	ACE_HANDLE handler;
	ret = find_handler(node,&handler);
	if(ret)
	{
		ACE_DEBUG((LM_ERROR,"连接指定设备失败!"));
		return TASK_ERR_CONNECT;
	}
	// 执行指令
	try
	{
		task->_handle = handler;
		ret = devintr->ExecuteTask(node,task);
	}
	catch(...)
	{
		// ignore
	}

	if(node->connect_module() == KSGDeviceNode::cm_short_conn)
	{
		free_conn = true;
	}
	// 如果指令执行不成功
	else
	{
		//
		if(ret != TASK_SUCCESS)
		{
			if(ret == TASK_ERR_TIMEOUT)
				free_conn = true;
			else
			{
				ACE_Time_Value tv(1);
				int res = ACE::handle_exception_ready(task->_handle,&tv);
				if(res >0)
				{
					// 如果发生异常,则重连
					free_conn = true;
				}
				else if(res == 0) // 超时
				{
					free_conn = true;
				}
				else // 返回错误
				{

				}
			}
		}
	}
	
	try
	{
		if(release_handler(node,&handler,free_conn))
		{
			ACE_DEBUG((LM_ERROR,"释放连接失败"));
		}
	}
	catch (...)
	{
		ACE_DEBUG((LM_ERROR,"关闭连接异常!"));
	}
	return ret;
}
int main() {
    
    int n, val, a = 1, result = 0;
    cin >> n;
    DI deq;
    for (int i = 0; i < n; i++) {
        cin >> val;
        deq.push_back(val);
    }
    while (deq.size() > 0) {
        if (deq.front() < deq.back()) {
            result += a * deq.front();
            deq.pop_front();
        }
        else {
            if (deq.back() < deq.front()) {
                result += a * deq.back();
                deq.pop_back();
            }
            else {
                int i = 0, j = deq.size() - 1;
                while ((i < j) && deq[i] == deq[j]) {
                    i++;
                    j--;
                }
                if (deq[i] < deq[j]) {
                    result += a * deq.front();
                    deq.pop_front();
                }
                else {
                    result += a * deq.back();
                    deq.pop_back();
                }
            }
        }
        a++;
    }
    cout << result << endl;
    return 0;
}
Exemplo n.º 8
0
void oslom_net_global::check_existing_unions(module_collection & mall) {
	
	/* this function is to check unions of existing modules*/
	
	/* sorting from the biggest to the smallest module */
	/*cout<<"before check_existing_unions"<<endl;
	print_modules(false, cout, mall);*/
	
	deque<int> sm;
	mall.sort_modules(sm);
	
	/*cout<<"sm"<<endl;
	prints(sm);*/
	
	
	deque<bool> still_good;
	for(UI i=0; i<sm.size(); i++)
		still_good.push_back(true);
	
	set<int> modules_to_erase;
	for(UI i=0; i<sm.size(); i++) {
	
		/* for each module I check if it's better to take it or its submodules */

		
		DI smaller;
		mall.almost_equal(sm[i], smaller);
		int_matrix its_submodules;
		for(UI j=0; j<smaller.size(); j++) if(still_good[smaller[j]])
			its_submodules.push_back(mall.modules[smaller[j]]);
		
		
		/*cout<<"************************** module to check "<<sm[i]<<" size: "<<mall.modules[sm[i]].size()<<endl;
		print_id(mall.modules[sm[i]], cout);
		cout<<"its_submodules"<<endl;
		print_id(its_submodules, cout);*/
		
		if(fusion_module_its_subs(mall.modules[sm[i]], its_submodules)) {
			deque_to_set_app(smaller, modules_to_erase);
			for(UI j=0; j<smaller.size(); j++)
				still_good[smaller[j]]=false;
				
		} else {
			modules_to_erase.insert(sm[i]);
			still_good[sm[i]]=false;
		
		}
				
		
	
	}
	
	for(set<int>:: iterator its= modules_to_erase.begin(); its!=modules_to_erase.end(); its++)
		mall.erase(*its);
	
	
	
	mall.compact();
	/*cout<<"after check_existing_unions --------------------------------------------------------"<<endl;
	print_modules(false, cout, mall);*/
	

}
Exemplo n.º 9
0
 void testIntermediate() {
   DI d;
   d.setX();
   clang_analyzer_eval(d.getX() == 42); // expected-warning{{TRUE}}
 }