void BinaryConstraint::permute(EnumeratedVariable* xin, Value a, Value b) { EnumeratedVariable* yin = y; if (xin != x) yin = x; vector<Cost> aux; for (EnumeratedVariable::iterator ity = yin->begin(); ity != yin->end(); ++ity) aux.push_back(getCost(xin, yin, a, *ity)); for (EnumeratedVariable::iterator ity = yin->begin(); ity != yin->end(); ++ity) setcost(xin, yin, a, *ity, getCost(xin, yin, b, *ity)); vector<Cost>::iterator itc = aux.begin(); for (EnumeratedVariable::iterator ity = yin->begin(); ity != yin->end(); ++ity) { setcost(xin, yin, b, *ity, *itc); ++itc; } }
int main(){ HWND hwnd = GetConsoleWindow(); ShowWindow(hwnd,SW_MAXIMIZE); console_settings(); console_resize(3); login=fopen("save\\logins.dat","rb"); if(login==NULL) admin_settings_signup(); else admin_settings_signin(); main_menu(); start_socket(); start_server(); handleAccept = (HANDLE) _beginthread(thd_accept_connections,0,0); handleMessages = (HANDLE) _beginthread(thd_program_messages,0,0); //clientHandle = (HANDLE) _beginthread( thd_receive_data,0,0); while(1){ // The interface part switch(getch()){ case '1': if(flag_menu==0) requests(); else if(flag_menu==2) services(); else if(flag_menu==21) add_services(); else if(flag_menu==22) setcost(); else if(flag_menu==24) change_password(); break; case '2': if(flag_menu==0) settings(); else if(flag_menu==2) cost(); else if(flag_menu==22) viewcost(); else if(flag_menu==21) view_services(); break; case '3': if(flag_menu==0){ saveMessagesToFile(); exit(0); } else if(flag_menu==2) member_settings_signup(); else if(flag_menu==21) edit_services(); break; case '4': if(flag_menu==21) search_services(); else if(flag_menu==2) admin_settings(); break; case '5': if(flag_menu==21) delete_services(); break; case 'r': if(flag_menu == 0) flag_reset = true; main_menu(); break; case 27: if(flag_menu==2 || flag_menu==1 ) main_menu(); else if(flag_menu==21) settings(); else if( flag_menu==22) settings(); else if(flag_menu==23) settings(); else if(flag_menu==24) settings(); else if(flag_menu==211) services(); else if(flag_menu==212) services(); else if(flag_menu==213) services(); else if(flag_menu==214) services(); else if(flag_menu==215) services(); else if(flag_menu==221 || flag_menu==222) cost(); break; default: break; } } return 0; }
void BiDirDijkstra::explore(int cur_node, double cur_cost, int dir, std::priority_queue<PDI, std::vector<PDI>, std::greater<PDI> > &que) { int i; // Number of connected edges int con_edge = m_vecNodeVector[cur_node]->Connected_Edges_Index.size(); double edge_cost; for(i = 0; i < con_edge; i++) { int edge_index = m_vecNodeVector[cur_node]->Connected_Edges_Index[i]; // Get the edge from the edge list. GraphEdgeInfo edge = m_vecEdgeVector[edge_index]; // Get the connected node int new_node = m_vecNodeVector[cur_node]->Connected_Nodes[i]; if(cur_node == edge.StartNode) { // Current node is the startnode of the edge. For forward search it should use forward cost, otherwise it should use the reverse cost, // i.e. if the reverse direction is valid then this node may be visited from the end node. if(dir > 0) edge_cost = edge.Cost; else edge_cost = edge.ReverseCost; // Check if the direction is valid for exploration if(edge.Direction == 0 || edge_cost >= 0.0) { // Check if the current edge gives better result if(cur_cost + edge_cost < getcost(new_node, dir)) { // explore the node, and push it in the queue setcost(new_node, dir, cur_cost + edge_cost); setparent(new_node, dir, cur_node, edge.EdgeID); que.push(std::make_pair(cur_cost + edge_cost, new_node)); // Update the minimum cost found so far. if(getcost(new_node, dir) + getcost(new_node, dir * -1) < m_MinCost) { m_MinCost = getcost(new_node, dir) + getcost(new_node, dir * -1); m_MidNode = new_node; } } } } else { // Current node is the endnode of the edge. For forward search it should use reverse cost, otherwise it should use the forward cost, // i.e. if the forward direction is valid then this node may be visited from the start node. if(dir > 0) edge_cost = edge.ReverseCost; else edge_cost = edge.Cost; // Check if the direction is valid for exploration if(edge.Direction == 0 || edge_cost >= 0.0) { // Check if the current edge gives better result if(cur_cost + edge_cost < getcost(new_node, dir)) { setcost(new_node, dir, cur_cost + edge_cost); setparent(new_node, dir, cur_node, edge.EdgeID); que.push(std::make_pair(cur_cost + edge_cost, new_node)); // Update the minimum cost found so far. if(getcost(new_node, dir) + getcost(new_node, dir * -1) < m_MinCost) { m_MinCost = getcost(new_node, dir) + getcost(new_node, dir * -1); m_MidNode = new_node; } } } } } }
//void BiDirAStar::explore(int cur_node, double cur_cost, int dir, std::priority_queue<PDI, std::vector<PDI>, std::greater<PDI> > &que) void BiDirAStar::explore(int cur_node, double cur_cost, int dir, MinHeap &que) { size_t i; // Number of connected edges auto con_edge = m_vecNodeVector[cur_node].Connected_Edges_Index.size(); double edge_cost; for(i = 0; i < con_edge; i++) { auto edge_index = m_vecNodeVector[cur_node].Connected_Edges_Index[i]; // Get the edge from the edge list. GraphEdgeInfo edge = m_vecEdgeVector[edge_index]; // Get the connected node int new_node = m_vecNodeVector[cur_node].Connected_Nodes[i]; #if 0 // mult is set but not used int mult; if(edge.Direction == 0) mult = 1; else mult = dir; #endif if(cur_node == edge.StartNode) { // Current node is the startnode of the edge. For forward search it should use forward cost, otherwise it should use the reverse cost, // i.e. if the reverse direction is valid then this node may be visited from the end node. if(dir > 0) edge_cost = edge.Cost; else edge_cost = edge.ReverseCost; // Check if the direction is valid for exploration if(edge.Direction == 0 || edge_cost >= 0.0) { //edge_cost = edge.Cost * mult; // Check if the current edge gives better result if(cur_cost + edge_cost < getcost(new_node, dir)) { // explore the node, and push it in the queue. the value in the queue will also contain the heuristic cost setcost(new_node, dir, cur_cost + edge_cost); setparent(new_node, dir, cur_node, edge.EdgeID); que.push(std::make_pair(cur_cost + edge_cost + gethcost(new_node, dir), new_node)); // Update the minimum cost found so far. if(getcost(new_node, dir) + getcost(new_node, dir * -1) < m_MinCost) { m_MinCost = getcost(new_node, dir) + getcost(new_node, dir * -1); m_MidNode = new_node; } } } } else { // Current node is the endnode of the edge. For forward search it should use reverse cost, otherwise it should use the forward cost, // i.e. if the forward direction is valid then this node may be visited from the start node. if(dir > 0) edge_cost = edge.ReverseCost; else edge_cost = edge.Cost; // Check if the direction is valid for exploration if(edge.Direction == 0 || edge_cost >= 0.0) { //edge_cost = edge.ReverseCost * mult; // Check if the current edge gives better result if(cur_cost + edge_cost < getcost(new_node, dir)) { // explore the node, and push it in the queue. the value in the queue will also contain the heuristic cost setcost(new_node, dir, cur_cost + edge_cost); setparent(new_node, dir, cur_node, edge.EdgeID); que.push(std::make_pair(cur_cost + edge_cost + gethcost(new_node, dir), new_node)); // Update the minimum cost found so far. if(getcost(new_node, dir) + getcost(new_node, dir * -1) < m_MinCost) { m_MinCost = getcost(new_node, dir) + getcost(new_node, dir * -1); m_MidNode = new_node; } } } } } }
void BiDirDijkstra::explore(int cur_node, double cur_cost, int dir, std::priority_queue<PDI, std::vector<PDI>, std::greater<PDI> > &que) { int i; int con_edge = m_vecNodeVector[cur_node].Connected_Edges_Index.size(); double edge_cost; for(i = 0; i < con_edge; i++) { int edge_index = m_vecNodeVector[cur_node].Connected_Edges_Index[i]; GraphEdgeInfo edge = m_vecEdgeVector[edge_index]; int new_node = m_vecNodeVector[cur_node].Connected_Nodes[i]; int mult; if(edge.Direction == 0) mult = 1; else mult = dir; if(cur_node == edge.StartNode) { if(dir > 0) edge_cost = edge.Cost; else edge_cost = edge.ReverseCost; if(edge.Direction == 0 || edge_cost >= 0.0) { //edge_cost = edge.Cost * mult; if(cur_cost + edge_cost < getcost(new_node, dir)) { setcost(new_node, dir, cur_cost + edge_cost); setparent(new_node, dir, cur_node, edge.EdgeID); que.push(std::make_pair(cur_cost + edge_cost, new_node)); if(getcost(new_node, dir) + getcost(new_node, dir * -1) < m_MinCost) { m_MinCost = getcost(new_node, dir) + getcost(new_node, dir * -1); m_MidNode = new_node; } } } } else { if(dir > 0) edge_cost = edge.ReverseCost; else edge_cost = edge.Cost; if(edge.Direction == 0 || edge_cost >= 0.0) { //edge_cost = edge.ReverseCost * mult; if(cur_cost + edge_cost < getcost(new_node, dir)) { setcost(new_node, dir, cur_cost + edge_cost); setparent(new_node, dir, cur_node, edge.EdgeID); que.push(std::make_pair(cur_cost + edge_cost, new_node)); if(getcost(new_node, dir) + getcost(new_node, dir * -1) < m_MinCost) { m_MinCost = getcost(new_node, dir) + getcost(new_node, dir * -1); m_MidNode = new_node; } } } } } }