graph* create_graph (int nodes, double prob) { graph* newMat = (graph*)malloc(sizeof(graph)); newMat->nodes = nodes; newMat->mat = (int*)malloc(nodes * nodes * sizeof(int)); for (int i = 0; i < nodes; i++) { for (int j = 0; j <= i; j++) { if (i == j) { set_distance(newMat, i, j, 0); } else { double r = ((double) rand() / (RAND_MAX)); if (r >= prob) { double r2 = ((double) rand() / (RAND_MAX)) + 1; set_distance(newMat, i, j, 100 * r2); set_distance(newMat, j, i, 100 * r2); } else { set_distance(newMat, i, j, 0); set_distance(newMat, j, i, 0); } } } } return newMat; }
/* Follow bonds recursively to find distances to all atoms from the given start atom */ static void follow_bond(struct mdt_residue_bonds *resbond, int natom, int start_atom, int endpoint1, int endpoint2, int distance) { int other_atom; /* Protect against infinite loops if cycles are present in the structure */ if (distance > natom) { return; } for (other_atom = 0; other_atom < natom; ++other_atom) { /* Don't double back on ourselves */ if (other_atom != start_atom && other_atom != endpoint1 && other_atom != endpoint2) { int dist = get_distance(resbond, endpoint2, other_atom); if (dist == 1) { int old_distance = get_distance(resbond, start_atom, other_atom); /* In case of cycles, take the shortest route */ if (old_distance == -1 || distance + 1 <= old_distance) { set_distance(resbond, start_atom, other_atom, distance + 1); follow_bond(resbond, natom, start_atom, endpoint2, other_atom, distance + 1); } } } } }
void CharacterCamera::_set(const String& p_name, const Variant& p_value) { if (p_name=="type") set_camera_type((CameraType)((int)(p_value))); else if (p_name=="orbit") set_orbit(p_value); else if (p_name=="height") set_height(p_value); else if (p_name=="inclination") set_inclination(p_value); else if (p_name=="max_orbit_x") set_max_orbit_x(p_value); else if (p_name=="min_orbit_x") set_min_orbit_x(p_value); else if (p_name=="max_distance") set_max_distance(p_value); else if (p_name=="min_distance") set_min_distance(p_value); else if (p_name=="distance") set_distance(p_value); else if (p_name=="clip") set_clip(p_value); else if (p_name=="autoturn") set_autoturn(p_value); else if (p_name=="autoturn_tolerance") set_autoturn_tolerance(p_value); else if (p_name=="autoturn_speed") set_autoturn_speed(p_value); }
graph* graph_from_file(char* filename, int nodes) { graph* newMat = (graph*)malloc(sizeof(graph)); newMat->nodes = nodes; newMat->mat = (int*)malloc(nodes * nodes * sizeof(int)); char str[100]; FILE * pFile = fopen (filename , "r"); if (pFile == NULL) { fprintf(stderr, "Error, couldn't open file: %s!", filename); return NULL; } else { int a, b, c; while ( fgets(str, 100, pFile) != NULL ) { sscanf(str, "%d %d %d", &a, &b, &c); set_distance(newMat, a, b, c); } } fclose(pFile); return newMat; }
static void lap_started_event(const tiny_millis_t time, const GeoPoint *sp, const float distance) { pr_debug_int_msg("Starting lap ", ++g_lap); g_at_sf = true; // Timing and predictive timing start_lap_timing(time); startLap(sp, time); reset_elapsed_time(); // Reset the sector logic g_lastSectorTimestamp = time; g_sector = 0; update_sector_geo_circle(g_sector); // Reset distance logic set_distance(distance); /* * Reset our finishGeoTrigger so that we get away from * finish before we re-arm the system. */ resetGeoTrigger(&g_finish_geo_trigger); }
CNearestCentroid::CNearestCentroid(CDistance* d, CLabels* trainlab) : CDistanceMachine() { init(); ASSERT(d); ASSERT(trainlab); set_distance(d); set_labels(trainlab); }
void show_navigation_info_window(const char *destination, uint32_t distance, time_t eta_timestamp) { initialise_ui(); set_destination(destination); set_distance(distance); set_eta(eta_timestamp); window_set_window_handlers(s_window, (WindowHandlers) { .unload = handle_window_unload, });
static void start_bcom(int skfd, char *ifname) { int val = 0; if (bcom_ioctl(skfd, ifname, WLC_GET_MAGIC, &val, sizeof(val)) < 0) return; bcom_ioctl(skfd, ifname, WLC_UP, &val, sizeof(val)); set_wext_ssid(skfd, ifname); set_distance(skfd, ifname); }
void navigate_path(){ int bool; struct timespec wait; wait.tv_sec = 0; wait.tv_nsec = SLEEP_DURATION; reset_timer(); set_direction(¤t); set_distance(¤t); send_direction(¤t.current_destination.angle); send_distance(¤t.current_destination.distance); while(running == 1){//Infinite loop until it reaches point or collision avoidance occurs. printf("%d\n", current.num); update_position(¤t); send_position(¤t.current_point); if(check(current.current_point, current.current_destination) == 1){ if(check(current.current_point, current.ending_point) == 1){ current.path[current.num] = current.current_destination; current.num++; count++; current.path = realloc(current.path, sizeof(position) * (current.num+1)); if(current.path == NULL){ printf("!!!!!\n"); send_stop(); } send_stop(); bool = 0; free(current.path); free(route.path); break; } else{ current.path[current.num] = current.current_destination; current.num++; count++; printf("%d\n", sizeof(position) * (current.num+1)); current.path = realloc(current.path, sizeof(position) * (current.num+1)); if(current.path == NULL){ printf("!!!!!\n"); send_stop(); } current.current_destination = route.path[count]; bool = 1; break; } }
void DMatches::MergeFrom(const DMatches& from) { GOOGLE_CHECK_NE(&from, this); if (from._has_bits_[0 / 32] & (0xffu << (0 % 32))) { if (from.has_queryidx()) { set_queryidx(from.queryidx()); } if (from.has_trainidx()) { set_trainidx(from.trainidx()); } if (from.has_imgidx()) { set_imgidx(from.imgidx()); } if (from.has_distance()) { set_distance(from.distance()); } } mutable_unknown_fields()->MergeFrom(from.unknown_fields()); }
/* Transfer bond information to the atom-atom distance matrix */ static void add_bonds(struct mdt_residue_bonds *resbonds, struct mdt_atom_class_list *bondcl, GHashTable *res_hash) { int icls, ityp; for (icls = 0; icls < bondcl->nclass; ++icls) { struct mdt_atom_class *cls = &bondcl->classes[icls]; for (ityp = 0; ityp < cls->ntypes; ++ityp) { struct mdt_atom_type *typ = &cls->types[ityp]; int res = GPOINTER_TO_INT(g_hash_table_lookup(res_hash, typ->names[0])); if (res && internal_bond(typ->names[1], typ->names[2])) { int at1, at2; at1 = GPOINTER_TO_INT(g_hash_table_lookup(resbonds[res-1].atom_names, typ->names[1])); at2 = GPOINTER_TO_INT(g_hash_table_lookup(resbonds[res-1].atom_names, typ->names[2])); set_distance(&resbonds[res-1], at1, at2, 1); } } } }
trajectory_parabola::trajectory_parabola(int distance) : _max_point(1), _a(-1), _p0(0), _v(0),_reducefactor(1), _initialized(false) { set_distance(distance); }
void start_watchdog(int skfd, char *ifname) { FILE *f; unsigned char buf[8192], wdslist[8192], wbuf[80], *v, *p, *next, *tmp; int i, j, wds = 0, c = 0, restart_wds = 0, wdstimeout = 0, infra; int tsf_attack = 0; unsigned int cur_tsf = 0; if (fork()) return; f = fopen("/var/run/wifi.pid", "w"); fprintf(f, "%d\n", getpid()); fclose(f); infra = strtol(nvram_safe_get(wl_var("infra")), NULL, 0); v = nvram_safe_get(wl_var("wds")); memset(wdslist, 0, 8192); p = wdslist; foreach(wbuf, v, next) { if (ether_atoe(wbuf, p)) { p += 6; wds++; } } for (;;) { sleep(1); /* refresh the distance setting - the driver might change it */ set_distance(skfd, ifname); if (restart_wds) wdstimeout--; if ((c++ < WD_INTERVAL) || ((restart_wds > 0) && (wdstimeout > 0))) continue; else c = 0; /* * In adhoc mode it can be desirable to use a specific BSSID to prevent * accidental cell splitting caused by broken cards/drivers. * When wl0_bssid is set, make sure the current BSSID matches the one * set in nvram. If it doesn't change it and try to overpower the hostile * AP by increasing the upper 32 bit of the TSF by one every time. * * In client mode simply use that variable to connect to a specific AP */ if ((infra < 1) || nvram_match(wl_var("mode"), "sta") || nvram_match(wl_var("mode"), "wet")) { rw_reg_t reg; if (!(tmp = nvram_get(wl_var("bssid")))) continue; if (!ether_atoe(tmp, wbuf)) continue; if ((bcom_ioctl(skfd, ifname, WLC_GET_BSSID, buf, 6) < 0) || (memcmp(buf, "\0\0\0\0\0\0", 6) == 0) || (memcmp(buf, wbuf, 6) != 0)) { if (bcom_ioctl(skfd, ifname, (infra < 1 ? WLC_SET_BSSID : WLC_REASSOC), wbuf, 6) < 0) continue; if (infra < 1) { /* upper 32 bit of the TSF */ memset(®, 0, sizeof(reg)); reg.size = 4; reg.byteoff = 0x184; bcom_ioctl(skfd, ifname, WLC_R_REG, ®, sizeof(reg)); if (reg.val > cur_tsf) cur_tsf = reg.val; cur_tsf |= 1; cur_tsf <<=1; reg.val = (cur_tsf == ~0 ? cur_tsf : cur_tsf + 1); bcom_ioctl(skfd, ifname, WLC_W_REG, ®, sizeof(reg)); /* set the lower 32 bit as well */ reg.byteoff = 0x180; bcom_ioctl(skfd, ifname, WLC_W_REG, ®, sizeof(reg)); /* set the bssid again, just in case.. */ bcom_ioctl(skfd, ifname, WLC_SET_BSSID, wbuf, 6); /* reached the maximum, next time wrap around to (1 << 16) * instead of 0 */ if (cur_tsf == ~0) cur_tsf = (1 << 16); } } } if (infra < 1) continue; if (nvram_match(wl_var("mode"), "sta") || nvram_match(wl_var("mode"), "wet")) { i = 0; if (bcom_ioctl(skfd, ifname, WLC_GET_BSSID, buf, 6) < 0) i = 1; if (memcmp(buf, "\0\0\0\0\0\0", 6) == 0) i = 1; memset(buf, 0, 8192); strcpy(buf, "sta_info"); bcom_ioctl(skfd, ifname, WLC_GET_BSSID, buf + strlen(buf) + 1, 6); if (bcom_ioctl(skfd, ifname, WLC_GET_VAR, buf, 8192) < 0) { i = 1; } else { sta_info_t *sta = (sta_info_t *) (buf + 4); if ((sta->flags & 0x18) != 0x18) i = 1; if (sta->idle > WD_CLIENT_IDLE) i = 1; } if (i) set_wext_ssid(skfd, ifname); } /* wds */ p = wdslist; restart_wds = 0; if (wdstimeout == 0) wdstimeout = strtol(nvram_safe_get(wl_var("wdstimeout")),NULL,0); for (i = 0; (i < wds) && !restart_wds; i++, p += 6) { memset(buf, 0, 8192); strcpy(buf, "sta_info"); memcpy(buf + strlen(buf) + 1, p, 6); if (!(bcom_ioctl(skfd, ifname, WLC_GET_VAR, buf, 8192) < 0)) { sta_info_t *sta = (sta_info_t *) (buf + 4); if ((sta->flags & 0x40) == 0x40) /* this is a wds link */ { if (sta->idle > wdstimeout) restart_wds = 1; /* if not authorized after WD_AUTH_IDLE seconds idletime */ if (((sta->flags & WL_STA_AUTHO) != WL_STA_AUTHO) && (sta->idle > WD_AUTH_IDLE)) restart_wds = 1; } } } if (restart_wds && (wdstimeout > 0)) { setup_bcom_wds(skfd, ifname); } } }
void lapstats_reset_distance() { set_distance(0); }
void start_watchdog(int skfd, char *ifname) { FILE *f; unsigned char buf[8192], wdslist[8192], wbuf[80], *v, *p, *next, *tmp; int i, j, wds = 0, c = 0, restart_wds = 0, wdstimeout = 0, infra; if (fork()) return; f = fopen("/var/run/wifi.pid", "w"); fprintf(f, "%d\n", getpid()); fclose(f); infra = strtol(nvram_safe_get(wl_var("infra")), NULL, 0); v = nvram_safe_get(wl_var("wds")); memset(wdslist, 0, 8192); p = wdslist; foreach(wbuf, v, next) { if (ether_atoe(wbuf, p)) { p += 6; wds++; } } for (;;) { sleep(1); /* refresh the distance setting - the driver might change it */ set_distance(skfd, ifname); if (restart_wds) wdstimeout--; if ((c++ < WD_INTERVAL) || ((restart_wds > 0) && (wdstimeout > 0))) continue; else c = 0; if (infra != 1) continue; if (nvram_match(wl_var("mode"), "sta") || nvram_match(wl_var("mode"), "wet")) { i = 0; if (bcom_ioctl(skfd, ifname, WLC_GET_BSSID, buf, 6) < 0) i = 1; if (memcmp(buf, "\0\0\0\0\0\0", 6) == 0) i = 1; memset(buf, 0, 8192); strcpy(buf, "sta_info"); bcom_ioctl(skfd, ifname, WLC_GET_BSSID, buf + strlen(buf) + 1, 6); if (bcom_ioctl(skfd, ifname, WLC_GET_VAR, buf, 8192) < 0) { i = 1; } else { sta_info_t *sta = (sta_info_t *) (buf + 4); if ((sta->flags & 0x18) != 0x18) i = 1; if (sta->idle > WD_CLIENT_IDLE) i = 1; } if (i) set_wext_ssid(skfd, ifname); } /* wds */ p = wdslist; restart_wds = 0; if (wdstimeout == 0) wdstimeout = strtol(nvram_safe_get(wl_var("wdstimeout")),NULL,0); for (i = 0; (i < wds) && !restart_wds; i++, p += 6) { memset(buf, 0, 8192); strcpy(buf, "sta_info"); memcpy(buf + strlen(buf) + 1, p, 6); if (!(bcom_ioctl(skfd, ifname, WLC_GET_VAR, buf, 8192) < 0)) { sta_info_t *sta = (sta_info_t *) (buf + 4); if ((sta->flags & 0x40) == 0x40) /* this is a wds link */ { if (sta->idle > wdstimeout) restart_wds = 1; /* if not authorized after WD_AUTH_IDLE seconds idletime */ if (((sta->flags & WL_STA_AUTHO) != WL_STA_AUTHO) && (sta->idle > WD_AUTH_IDLE)) restart_wds = 1; } } } if (restart_wds && (wdstimeout > 0)) { setup_bcom_wds(skfd, ifname); } } }