struct Network_Result* calculate_performacnce() { struct Graph *graph1, *graph2; int total_graph_pairs = 0, total_vertex_pairs = 0, vertex1, vertex2, count = 0; struct Network_Result *results = malloc( sizeof(struct Network_Result) * TOTAL_RESULTS); if (results == NULL) { PRINT_TEXT("MEM ALLOCATION FAILED"); exit(EXIT_FAILURE); } while (total_graph_pairs++ < GRAPH_PAIRS) { graph1 = generate_graph_type_1(); graph2 = generate_graph_type_2(); total_vertex_pairs = 0; while (total_vertex_pairs < VERTEX_PAIRS) { vertex1 = rand() % MAX_VERTICES; do { vertex2 = rand() % MAX_VERTICES; } while (vertex1 == vertex2); generate_path(graph1, vertex1, vertex2); generate_path(graph2, vertex1, vertex2); generate_results(results, count++, GRAPH_TYPE_1, graph1, vertex1, vertex2); generate_results(results, count++, GRAPH_TYPE_2, graph2, vertex1, vertex2); total_vertex_pairs++; } } return results; }
EFI_STATUS simple_file_open(EFI_HANDLE image, CHAR16 *name, EFI_FILE **file, UINT64 mode) { EFI_STATUS efi_status; EFI_HANDLE device; EFI_LOADED_IMAGE *li; EFI_DEVICE_PATH *loadpath = NULL; CHAR16 *PathName = NULL; efi_status = uefi_call_wrapper(BS->HandleProtocol, 3, image, &IMAGE_PROTOCOL, &li); if (efi_status != EFI_SUCCESS) return simple_file_open_by_handle(image, name, file, mode); efi_status = generate_path(name, li, &loadpath, &PathName); if (efi_status != EFI_SUCCESS) { Print(L"Unable to generate load path for %s\n", name); return efi_status; } device = li->DeviceHandle; efi_status = simple_file_open_by_handle(device, PathName, file, mode); FreePool(PathName); FreePool(loadpath); return efi_status; }
EFI_STATUS execute(EFI_HANDLE image, CHAR16 *name) { EFI_STATUS status; EFI_HANDLE h; EFI_LOADED_IMAGE *li; EFI_DEVICE_PATH *devpath; CHAR16 *PathName; status = uefi_call_wrapper(BS->HandleProtocol, 3, image, &IMAGE_PROTOCOL, (void **)&li); if (status != EFI_SUCCESS) return status; status = generate_path(name, li, &devpath, &PathName); if (status != EFI_SUCCESS) return status; status = uefi_call_wrapper(BS->LoadImage, 6, FALSE, image, devpath, NULL, 0, &h); if (status != EFI_SUCCESS) goto out; status = uefi_call_wrapper(BS->StartImage, 3, h, NULL, NULL); uefi_call_wrapper(BS->UnloadImage, 1, h); out: FreePool(PathName); FreePool(devpath); return status; }
void PathManager::setup_path(int num){ set_num(num); set_size(50); set_path_width(0.1); calculate_column_row(num); generate_position(); generate_path(); }
const Output* solve( const Input* in, Output* out ) { POS_NONE.get_row() = -1; POS_NONE.get_col() = -1; for ( auto& path : out->paths ) path.clear(); out->K = in->K; auto search = Search::create(in); search->search(); Int len = 0; Int cnt = 0; for ( auto i = in->K - 1; i >= 0; -- i ) { len += generate_path(search->prev, search->visit_order[i], out->paths[cnt]); ++ cnt; } out->min_penalty = len; return out; }
bool svg_renderer<OutputIterator>::process(rule::symbolizers const& syms, mapnik::feature_impl & feature, proj_transform const& prj_trans) { // svg renderer supports processing of multiple symbolizers. using path_type = transform_path_adapter<view_transform, geometry_type>; bool process_path = false; // process each symbolizer to collect its (path) information. // path information (attributes from line_ and polygon_ symbolizers) // is collected with the path_attributes_ data member. for (auto const& sym : syms) { if (is_path_based(sym)) { process_path = true; } util::apply_visitor(symbolizer_dispatch<svg_renderer<OutputIterator>>(*this, feature, prj_trans), sym); } if (process_path) { // generate path output for each geometry of the current feature. for (auto & geom : feature.paths()) { if(geom.size() > 0) { path_type path(common_.t_, geom, prj_trans); generate_path(generator_.output_iterator_, path, path_attributes_); } } // set the previously collected values back to their defaults // for the feature that will be processed next. path_attributes_.reset(); } return true; }
int main() { connect_to_robot(); initialize_robot(); set_origin(); printf("Ghandy-Bot activated, destroy!!!\n"); //Set front IR sensors to to face left and right set_ir_angle(LEFT, -45); set_ir_angle(RIGHT, 45); init_map(); print_map(); robot.map[1][1].walls[0] = 1; robot.map[1][2].walls[2] = 1; robot.map[1][1].walls[1] = 1; robot.map[2][1].walls[3] = 1; robot.map[1][3].walls[2] = 1; robot.map[1][2].walls[0] = 1; robot.map[0][4].walls[2] = 1; robot.map[0][3].walls[0] = 1; robot.map[3][4].walls[3] = 1; robot.map[2][4].walls[1] = 1; robot.map[3][2].walls[2] = 1; robot.map[3][1].walls[0] = 1; robot.map[3][2].walls[3] = 1; robot.map[2][2].walls[1] = 1; int i; for(i=1;i<=4;i++) robot.map[0][i].walls[3] = 1; for(i=1;i<=4;i++) robot.map[i][1].walls[2] = 1; for(i=1;i<=4;i++) robot.map[3][i].walls[1] = 1; print_map(); /* Phase 1 */ //Perform depth first search on maze //dfs(0, 0, M_PI / 2); /* Phase 2 */ lee(0,1); //Update matrix with Lee costs from node [0,1] /* Generate shortest path to node [3,4] (finish line) */ generate_path(3,4); follow_path(); //Follow the generated path to finish //Phew, did we win??? printf("Ghandy-Bot deactivated!\n"); return 0; }
int store_packet(void *config, const struct ipfix_message *ipfix_msg, const struct ipfix_template_mgr *template_mgr) { (void) template_mgr; std::map<uint16_t, template_table*>::iterator table; struct fastbit_config *conf = (struct fastbit_config *) config; std::map<uint16_t, template_table*> *templates = NULL; std::map<uint16_t, template_table*> *old_templates = NULL; /* Templates to be removed */ std::map<std::string, std::map<uint32_t, od_info>*> *od_infos = conf->od_infos; std::map<std::string, std::map<uint32_t, od_info>*>::iterator exporter_it; std::map<uint32_t, od_info>::iterator odid_it; static int rcnt = 0; uint16_t template_id; uint32_t odid = ntohl(ipfix_msg->pkt_header->observation_domain_id); struct input_info_network *input = (struct input_info_network *) ipfix_msg->input_info; int rc_flows = 0; uint64_t rc_flows_sum = 0; char exporter_ip_addr_tmp[INET6_ADDRSTRLEN]; if (input->l3_proto == 6) { /* IPv6 */ ipv6_addr_non_canonical(exporter_ip_addr_tmp, &(input->src_addr.ipv6)); } else { /* IPv4 */ inet_ntop(AF_INET, &(input->src_addr.ipv4.s_addr), exporter_ip_addr_tmp, INET_ADDRSTRLEN); } /* Convert to C++ string for use in `od_infos` data structure */ std::string exporter_ip_addr (exporter_ip_addr_tmp); /* Find exporter in od_infos data structure */ if ((exporter_it = od_infos->find(exporter_ip_addr)) == od_infos->end()) { MSG_INFO(msg_module, "Received data for new exporter: %s", exporter_ip_addr.c_str()); /* Add new exporter to data structure */ std::map<uint32_t, od_info> *new_exporter = new std::map<uint32_t, od_info>; od_infos->insert(std::make_pair(exporter_ip_addr, new_exporter)); exporter_it = od_infos->find(exporter_ip_addr); } /* Find ODID in template_info data structure (under exporter) */ if ((odid_it = exporter_it->second->find(odid)) == exporter_it->second->end()) { MSG_INFO(msg_module, "Received new ODID for exporter %s: %u", exporter_ip_addr.c_str(), odid); /* Add new ODID to data structure (under exporter) */ od_info new_odid; new_odid.exporter_ip_addr = exporter_ip_addr; new_odid.path = generate_path(conf, exporter_ip_addr, odid); exporter_it->second->insert(std::make_pair(odid, new_odid)); odid_it = exporter_it->second->find(odid); } templates = &(odid_it->second.template_info); /* Process all datasets in message */ int i; for (i = 0 ; i < MSG_MAX_DATA_COUPLES && ipfix_msg->data_couple[i].data_set; i++) { if (ipfix_msg->data_couple[i].data_template == NULL) { /* Skip data couples without templates */ continue; } template_id = ipfix_msg->data_couple[i].data_template->template_id; /* If template (ID) is unknown, add it to the template map */ if ((table = templates->find(template_id)) == templates->end()) { MSG_DEBUG(msg_module, "Received new template: %hu", template_id); template_table *table_tmp = new template_table(template_id, conf->buff_size); if (table_tmp->parse_template(ipfix_msg->data_couple[i].data_template, conf) != 0) { /* Template cannot be parsed, skip data set */ delete table_tmp; continue; } templates->insert(std::pair<uint16_t, template_table*>(template_id, table_tmp)); table = templates->find(template_id); } else { /* Check template time. On reception of a new template it is crucial to rewrite the old one. */ if (ipfix_msg->data_couple[i].data_template->first_transmission > table->second->get_first_transmission()) { MSG_DEBUG(msg_module, "Received new template with already used template ID: %hu", template_id); /* Init map for old template if necessary */ if (old_templates == NULL) { old_templates = new std::map<uint16_t,template_table*>; } /* Store old template */ old_templates->insert(std::pair<uint16_t, template_table*>(table->first, table->second)); /* Flush data */ flush_data(conf, exporter_ip_addr, odid, old_templates); /* Remove rewritten template */ delete table->second; delete old_templates; old_templates = NULL; /* Remove old template from current list */ templates->erase(table); /* Add the new template */ template_table *table_tmp = new template_table(template_id, conf->buff_size); if (table_tmp->parse_template(ipfix_msg->data_couple[i].data_template, conf) != 0) { /* Template cannot be parsed; skip data set */ delete table_tmp; continue; } templates->insert(std::pair<uint16_t, template_table*>(template_id, table_tmp)); table = templates->find(template_id); /* New template was created; create new directory if necessary */ } } /* Check whether data has to be flushed before storing data record */ bool flush_records = conf->records_window > 0 && rcnt > conf->records_window; bool flush_time = false; time_t now; if (conf->time_window > 0) { time(&now); flush_time = difftime(now, conf->last_flush) > conf->time_window; } if (flush_records || flush_time) { /* Flush data for all exporters and ODIDs */ flush_all_data(conf); /* Time management differs between flush policies (records vs. time) */ if (flush_records) { time(&(conf->last_flush)); } else if (flush_time) { while (difftime(now, conf->last_flush) > conf->time_window) { conf->last_flush = conf->last_flush + conf->time_window; } } /* Update window name and path */ update_window_name(conf); odid_it->second.path = generate_path(conf, exporter_ip_addr, (*odid_it).first); rcnt = 0; conf->new_dir = true; } /* Store this data record */ rc_flows = (*table).second->store(ipfix_msg->data_couple[i].data_set, odid_it->second.path, conf->new_dir); if (rc_flows >= 0) { rc_flows_sum += rc_flows; rcnt += rc_flows; } else { /* No need for showing error message here, since it is already done * by store() in case of an error */ // MSG_ERROR(msg_module, "An error occurred during FastBit table store; no records were stored"); } } /* We've told all tables that the directory has changed */ conf->new_dir = false; if (rc_flows_sum) { odid_it->second.flow_watch.add_flows(rc_flows_sum); } odid_it->second.flow_watch.update_seq_no(ntohl(ipfix_msg->pkt_header->sequence_number)); return 0; }