int main() { TabSample t; auto x = t.alpha = 7; auto y = t.beta = "kaesekuchen"; auto z = t.gamma = true; { using T = decltype(update(t)); static_assert(sqlpp::is_regular<T>::value, "type requirement"); } { using T = decltype(update(t).set(t.gamma = false).where(t.beta != "transparent")); static_assert(sqlpp::is_regular<T>::value, "type requirement"); } { using T = decltype(dynamic_update(db, t).dynamic_set(t.gamma = false).dynamic_where()); static_assert(sqlpp::is_regular<T>::value, "type requirement"); } update(t).serialize(std::cerr, db); std::cerr << "\n"; update(t).set(t.gamma = false).serialize(std::cerr, db); std::cerr << "\n"; update(t).set(t.gamma = false).where(t.beta != "transparent").serialize(std::cerr, db); std::cerr << "\n"; auto u = dynamic_update(db, t).dynamic_set(t.gamma = false).dynamic_where(); u = u.add_set(t.gamma = false); u.serialize(std::cerr, db); std::cerr << "\n"; return 0; }
int Update(int, char* []) { MockDb db; MockDb::_serializer_context_t printer = {}; const auto t = test::TabBar{}; { using T = decltype(update(t)); static_assert(sqlpp::is_regular<T>::value, "type requirement"); } { using T = decltype(update(t).set(t.gamma = false).where(t.beta != "transparent")); static_assert(sqlpp::is_regular<T>::value, "type requirement"); } { using T = decltype(dynamic_update(db, t).dynamic_set(t.gamma = false).dynamic_where()); static_assert(sqlpp::is_regular<T>::value, "type requirement"); } serialize(update(t), printer).str(); serialize(update(t).set(t.gamma = false), printer).str(); serialize(update(t).set(t.gamma = false).where(t.beta != "transparent"), printer).str(); serialize(update(t).set(t.beta = "opaque").where(t.beta != t.beta + "this is nonsense"), printer).str(); auto u = dynamic_update(db, t).dynamic_set(t.gamma = false).dynamic_where(); u.assignments.add(t.beta = "cannot update gamma a second time"); u.where.add(t.gamma != false); printer.reset(); std::cerr << serialize(u, printer).str() << std::endl; db(u); db(update(t).set(t.delta = sqlpp::verbatim<sqlpp::integer>("17+4")).unconditionally()); db(update(t).set(t.delta = sqlpp::null).unconditionally()); db(update(t).set(t.delta = sqlpp::default_value).unconditionally()); db(update(t).set(t.delta += t.alpha * 2, t.beta += " and cake").unconditionally()); return 0; }
int SSrun_scatter_search(SS *scatter_search, CCutil_timer *timer) { guint i; REFSET *refset = scatter_search->rs; int flag, val = 0; int nbnew_sol = 0; int nbjobs = scatter_search->njobs; int nmachines = scatter_search->nmachines; int nb_noimprovements = 0; int *totsubset = (int *) NULL; double limit = scatter_search->timelimit; totsubset = CC_SAFE_MALLOC(scatter_search->b1 + 1, int); CCcheck_NULL_2(totsubset, "Failed tot allocate memory to tot subset"); if (refset->list1->len == 0) { printf("We can't run scatter search, refset is empty\n"); val = 1; goto CLEAN; } printf("PMCombination method\n"); CCutil_suspend_timer(timer); CCutil_resume_timer(timer); while (refset->newsol && scatter_search->status != opt && timer->cum_zeit < limit) { GPtrArray *list = g_ptr_array_new(); for (i = 0; i < refset->list1->len; ++i) { g_ptr_array_add(list, g_ptr_array_index(refset->list1, i)); } for (i = 0; i < refset->list2->len; ++i) { g_ptr_array_add(list, g_ptr_array_index(refset->list2, i)); } compute_fitness(scatter_search); refset->newsol = 0; if (scatter_search->iter > 0) { int best = scatter_search->upperbound; CCutil_suspend_timer(timer); CCutil_resume_timer(timer); double rel_error = ((double)best - (double)scatter_search->lowerbound) / (double)scatter_search->lowerbound; printf("iteration %d with best wct %d and rel error %f, number of new solutions %d, time = %f\n", scatter_search->iter, best, rel_error, nbnew_sol, timer->cum_zeit); } nbnew_sol = 0; k_subset_init(list->len, 2, totsubset, &flag); while (flag && scatter_search->status != opt) { solution *new_sol = CC_SAFE_MALLOC(1, solution); solution_init(new_sol); solution_alloc(new_sol, nmachines, nbjobs); int rval = 1; rval = combine_PM(scatter_search, list, totsubset, 2, new_sol); if (!rval) { solution_calc(new_sol, *(scatter_search->jobarray)); new_sol->iter = scatter_search->iter + 1; localsearch_random_k(new_sol, scatter_search->lowerbound, 2); solution_unique(new_sol); if (!dynamic_update(scatter_search, list, new_sol)) { if (new_sol->totalweightcomptime < scatter_search->upperbound) { scatter_search->upperbound = new_sol->totalweightcomptime; } if (new_sol->totalweightcomptime == scatter_search->lowerbound) { scatter_search->status = opt; printf("Found optimal with SS with subset generation 1\n"); } nbnew_sol++; } else { solution_free(new_sol); CC_IFFREE(new_sol, solution); } } else { solution_free(new_sol); CC_IFFREE(new_sol, solution); } k_subset_lex_successor(list->len, 2, totsubset, &flag); } k_subset_init(list->len, 3, totsubset, &flag); solution *sol = (solution *)NULL; sol = (solution *) g_ptr_array_index(list, 0); while (flag && scatter_search->status != opt) { solution *new_sol = CC_SAFE_MALLOC(1, solution); solution_init(new_sol); solution_alloc(new_sol, nmachines, nbjobs); int rval = 1; rval = combine_PM(scatter_search, list, totsubset, 3, new_sol); //Dell'Amico et al. if (!rval) { solution_calc(new_sol, *(scatter_search->jobarray)); new_sol->iter = scatter_search->iter + 1; localsearch_random_k(new_sol, scatter_search->lowerbound, 2); solution_unique(new_sol); if (!dynamic_update(scatter_search, list, new_sol)) { if (new_sol->totalweightcomptime < scatter_search->upperbound) { scatter_search->upperbound = new_sol->totalweightcomptime; } if (new_sol->totalweightcomptime == scatter_search->lowerbound) { scatter_search->status = opt; printf("Found optimal with SS\n"); } nbnew_sol++; } else { solution_free(new_sol); CC_IFFREE(new_sol, solution); } } else { solution_free(new_sol); CC_IFFREE(new_sol, solution); } k_subset_lex_successor(list->len, 3, totsubset, &flag); sol = (solution *) g_ptr_array_index(list, totsubset[1] - 1); } k_subset_init(list->len, 4, totsubset, &flag); sol = (solution *) g_ptr_array_index(list, 0); solution *temp_sol = (solution *) g_ptr_array_index(list, 1); while (flag && scatter_search->status != opt && sol->totalweightcomptime <= scatter_search->upperbound && temp_sol->totalweightcomptime <= scatter_search->upperbound) { solution *new_sol = CC_SAFE_MALLOC(1, solution); solution_init(new_sol); solution_alloc(new_sol, nmachines, nbjobs); int rval = 1; rval = combine_PM(scatter_search, list, totsubset, 4, new_sol); if (!rval) { solution_calc(new_sol, *(scatter_search->jobarray)); new_sol->iter = scatter_search->iter + 1; localsearch_random_k(new_sol, scatter_search->lowerbound, 2); solution_unique(new_sol); if (!dynamic_update(scatter_search, list, new_sol)) { if (new_sol->totalweightcomptime < scatter_search->upperbound) { scatter_search->upperbound = new_sol->totalweightcomptime; } if (new_sol->totalweightcomptime == scatter_search->lowerbound) { scatter_search->status = opt; printf("Found optimal with SS\n"); } nbnew_sol++; } else { solution_free(new_sol); CC_IFFREE(new_sol, solution); } } else { solution_free(new_sol); CC_IFFREE(new_sol, solution); } k_subset_lex_successor(list->len, 4, totsubset, &flag); sol = (solution *) g_ptr_array_index(list, totsubset[1] - 1); temp_sol = (solution *)g_ptr_array_index(list, totsubset[2] - 1); } for (i = 0; i < refset->list2->len + 1; ++i) { totsubset[i] = i; } for (i = 5; i < refset->list2->len + 1 && scatter_search->status != opt; i++) { solution *new_sol = CC_SAFE_MALLOC(1, solution); solution_init(new_sol); solution_alloc(new_sol, nmachines, nbjobs); int rval = 1; rval = combine_PM(scatter_search, list, totsubset, i, new_sol); if (!rval) { solution_calc(new_sol, *(scatter_search->jobarray)); new_sol->iter = scatter_search->iter + 1; localsearch_random_k(new_sol, scatter_search->lowerbound, 2); solution_unique(new_sol); if (!dynamic_update(scatter_search, list, new_sol)) { if (new_sol->totalweightcomptime < scatter_search->upperbound) { scatter_search->upperbound = new_sol->totalweightcomptime; } if (new_sol->totalweightcomptime == scatter_search->lowerbound) { scatter_search->status = opt; printf("Found optimal with SS\n"); } nbnew_sol++; } else { solution_free(new_sol); CC_IFFREE(new_sol, solution); } } else { solution_free(new_sol); CC_IFFREE(new_sol, solution); } } scatter_search->iter++; if (nbnew_sol == 0) { nb_noimprovements++; } if (refset->newsol == 0 && scatter_search->iter < 10 && nb_noimprovements < 5) { add_solution_refset(scatter_search); refset->newsol = 1; } g_ptr_array_free(list, TRUE); } CLEAN: CC_IFFREE(totsubset, int); return val; }
/* * This is called at startup and after that, every CHECK_INTERVAL seconds or * when a SIGHUP is received. */ void initifs(void) { static char *buf = NULL; static uint_t maxbufsize = 0; int bufsize; int numifs; struct lifnum lifn; struct lifconf lifc; struct lifreq lifr; struct lifreq *lifrp; int n; struct interface ifs; struct interface *ifp; int netmaskchange = 0; boolean_t changes = _B_FALSE; lifn.lifn_family = AF_INET6; lifn.lifn_flags = 0; if (ioctl(iocsoc, SIOCGLIFNUM, (char *)&lifn) < 0) { syslog(LOG_ERR, "initifs: ioctl (get interface numbers): %m"); return; } numifs = lifn.lifn_count; bufsize = numifs * sizeof (struct lifreq); if (buf == NULL || bufsize > maxbufsize) { if (buf != NULL) free(buf); maxbufsize = bufsize; buf = (char *)malloc(maxbufsize); if (buf == NULL) { syslog(LOG_ERR, "initifs: out of memory"); return; } } lifc.lifc_family = AF_INET6; lifc.lifc_flags = 0; lifc.lifc_len = bufsize; lifc.lifc_buf = buf; if (ioctl(iocsoc, SIOCGLIFCONF, (char *)&lifc) < 0) { syslog(LOG_ERR, "initifs: ioctl (get interface configuration): %m"); return; } /* * Mark all of the currently known interfaces in order to determine * which of the these interfaces no longer exist. */ for (ifp = ifnet; ifp != NULL; ifp = ifp->int_next) ifp->int_flags |= RIP6_IFF_MARKED; lifrp = lifc.lifc_req; for (n = lifc.lifc_len / sizeof (struct lifreq); n > 0; n--, lifrp++) { bzero((char *)&ifs, sizeof (ifs)); (void) strncpy(lifr.lifr_name, lifrp->lifr_name, sizeof (lifr.lifr_name)); if (ioctl(iocsoc, SIOCGLIFFLAGS, (char *)&lifr) < 0) { syslog(LOG_ERR, "initifs: ioctl (get interface flags): %m"); continue; } if (!(lifr.lifr_flags & IFF_IPV6) || !(lifr.lifr_flags & IFF_MULTICAST) || (lifr.lifr_flags & IFF_LOOPBACK)) continue; ifp = if_ifwithname(lifr.lifr_name); if (ifp != NULL) ifp->int_flags &= ~RIP6_IFF_MARKED; if (lifr.lifr_flags & IFF_POINTOPOINT) ifs.int_flags |= RIP6_IFF_POINTOPOINT; if (lifr.lifr_flags & IFF_NORTEXCH) ifs.int_flags |= RIP6_IFF_NORTEXCH; if (lifr.lifr_flags & IFF_PRIVATE) ifs.int_flags |= RIP6_IFF_PRIVATE; if (lifr.lifr_flags & IFF_UP) { ifs.int_flags |= RIP6_IFF_UP; } else { if (ifp != NULL) { if (ifp->int_flags & RIP6_IFF_UP) { /* * If there is an transition from up to * down for an exisiting interface, * increment the counter. */ ifp->int_transitions++; changes = _B_TRUE; } if_purge(ifp); } continue; } if (ifs.int_flags & RIP6_IFF_POINTOPOINT) { /* * For point-to-point interfaces, retrieve both the * local and the remote addresses. */ if (ioctl(iocsoc, SIOCGLIFADDR, (char *)&lifr) < 0) { syslog(LOG_ERR, "initifs: ioctl (get interface address): " "%m"); continue; } ifs.int_addr = ((struct sockaddr_in6 *)&lifr.lifr_addr)->sin6_addr; if (ioctl(iocsoc, SIOCGLIFDSTADDR, (char *)&lifr) < 0) { syslog(LOG_ERR, "initifs: ioctl (get destination address): " "%m"); continue; } ifs.int_dstaddr = ((struct sockaddr_in6 *) &lifr.lifr_dstaddr)->sin6_addr; ifs.int_prefix_length = IPV6_ABITS; } else { /* * For other interfaces, retreieve the prefix (including * the prefix length. */ if (ioctl(iocsoc, SIOCGLIFSUBNET, (char *)&lifr) < 0) { syslog(LOG_ERR, "initifs: ioctl (get subnet prefix): %m"); continue; } /* * This should never happen but check for it in any case * since the kernel stores it as an signed integer. */ if (lifr.lifr_addrlen < 0 || lifr.lifr_addrlen > IPV6_ABITS) { syslog(LOG_ERR, "initifs: ioctl (get subnet prefix) " "returned invalid prefix length of %d", lifr.lifr_addrlen); continue; } ifs.int_prefix_length = lifr.lifr_addrlen; ifs.int_addr = ((struct sockaddr_in6 *) &lifr.lifr_subnet)->sin6_addr; } if (ioctl(iocsoc, SIOCGLIFMETRIC, (char *)&lifr) < 0 || lifr.lifr_metric < 0) ifs.int_metric = 1; else ifs.int_metric = lifr.lifr_metric + 1; if (ioctl(iocsoc, SIOCGLIFINDEX, (char *)&lifr) < 0) { syslog(LOG_ERR, "initifs: ioctl (get index): %m"); continue; } ifs.int_ifindex = lifr.lifr_index; if (ioctl(iocsoc, SIOCGLIFMTU, (char *)&lifr) < 0) { syslog(LOG_ERR, "initifs: ioctl (get mtu): %m"); continue; } /* * If the interface's recorded MTU doesn't make sense, use * IPV6_MIN_MTU instead. */ if (lifr.lifr_mtu < IPV6_MIN_MTU) ifs.int_mtu = IPV6_MIN_MTU; else ifs.int_mtu = lifr.lifr_mtu; if (ifp != NULL) { /* * RIP6_IFF_NORTEXCH flag change by itself shouldn't * cause an if_purge() call, which also purges all the * routes heard off this interface. So, let's suppress * changes of RIP6_IFF_NORTEXCH in the following * comparisons. */ if (ifp->int_prefix_length == ifs.int_prefix_length && ((ifp->int_flags | RIP6_IFF_NORTEXCH) == (ifs.int_flags | RIP6_IFF_NORTEXCH)) && ifp->int_metric == ifs.int_metric && ifp->int_ifindex == ifs.int_ifindex) { /* * Now let's make sure we capture the latest * value of RIP6_IFF_NORTEXCH flag. */ if (ifs.int_flags & RIP6_IFF_NORTEXCH) ifp->int_flags |= RIP6_IFF_NORTEXCH; else ifp->int_flags &= ~RIP6_IFF_NORTEXCH; if (!(ifp->int_flags & RIP6_IFF_POINTOPOINT) && IN6_ARE_ADDR_EQUAL(&ifp->int_addr, &ifs.int_addr)) continue; if ((ifp->int_flags & RIP6_IFF_POINTOPOINT) && IN6_ARE_ADDR_EQUAL(&ifp->int_dstaddr, &ifs.int_dstaddr)) continue; } if_purge(ifp); if (ifp->int_prefix_length != ifs.int_prefix_length) netmaskchange = 1; ifp->int_addr = ifs.int_addr; ifp->int_dstaddr = ifs.int_dstaddr; ifp->int_metric = ifs.int_metric; /* * If there is an transition from down to up for an * exisiting interface, increment the counter. */ if (!(ifp->int_flags & RIP6_IFF_UP) && (ifs.int_flags & RIP6_IFF_UP)) ifp->int_transitions++; ifp->int_flags |= ifs.int_flags; ifp->int_prefix_length = ifs.int_prefix_length; /* * If the interface index has changed, we may need to * set up the listen socket again. */ if (ifp->int_ifindex != ifs.int_ifindex) { if (ifp->int_sock != -1) { resetup_listen_sock(ifp, ifs.int_ifindex); } ifp->int_ifindex = ifs.int_ifindex; } ifp->int_mtu = ifs.int_mtu; } else { char *cp; int log_num; ifp = (struct interface *) malloc(sizeof (struct interface)); if (ifp == NULL) { syslog(LOG_ERR, "initifs: out of memory"); return; } *ifp = ifs; ifp->int_name = ifp->int_ifbase = NULL; ifp->int_name = (char *)malloc((size_t)strlen(lifr.lifr_name) + 1); if (ifp->int_name == NULL) { free(ifp); syslog(LOG_ERR, "initifs: out of memory"); return; } (void) strcpy(ifp->int_name, lifr.lifr_name); ifp->int_ifbase = (char *)malloc((size_t)strlen(lifr.lifr_name) + 1); if (ifp->int_ifbase == NULL) { free(ifp->int_name); free(ifp); syslog(LOG_ERR, "initifs: out of memory"); return; } (void) strcpy(ifp->int_ifbase, lifr.lifr_name); cp = (char *)index(ifp->int_ifbase, IF_SEPARATOR); if (cp != NULL) { /* * Verify that the value following the separator * is an integer greater than zero (the only * possible value for a logical interface). */ log_num = atoi((char *)(cp + 1)); if (log_num <= 0) { free(ifp->int_ifbase); free(ifp->int_name); free(ifp); syslog(LOG_ERR, "initifs: interface name %s could " "not be parsed", ifp->int_name); return; } *cp = '\0'; } else { log_num = 0; } if (log_num == 0) { ifp->int_sock = setup_listen_sock(ifp->int_ifindex); } else { ifp->int_sock = -1; } ifp->int_next = ifnet; ifnet = ifp; traceinit(ifp); } addrouteforif(ifp); changes = _B_TRUE; } /* * Any remaining interfaces that are still marked and which were in an * up state (RIP6_IFF_UP) need to removed from the routing table. */ for (ifp = ifnet; ifp != NULL; ifp = ifp->int_next) { if ((ifp->int_flags & (RIP6_IFF_MARKED | RIP6_IFF_UP)) == (RIP6_IFF_MARKED | RIP6_IFF_UP)) { if_purge(ifp); ifp->int_flags &= ~RIP6_IFF_MARKED; changes = _B_TRUE; } } if (netmaskchange) rtchangeall(); if (supplier & changes) dynamic_update((struct interface *)NULL); }