Esempio n. 1
0
int new_savings3(heur_prob *p, tree_node *max_ptr, tree_node *head, _node *tour,
		int *node1, int *node2, route_data *route_info)
{
   int savings, max_savings;
   int ins_route = max_ptr->node1 ? tour[max_ptr->node1].route :
      tour[max_ptr->node2].route;
   
   if (((head->node1 == max_ptr->node1) && (head->node2 == max_ptr->node2)) ||
       (route_info[ins_route].weight + p->demand[max_ptr->cust_num] >=
	p->capacity)){
      max_savings = find_new_ins_route3(p, head->cust_num, tour, node1, node2,
				       route_info);
      return(max_savings);
   }
   
   if ((savings = (int) (SAV(&p->dist, max_ptr->node1, max_ptr->cust_num,
		      head->cust_num))) > head->savings){
      *node1 = max_ptr->node1;
      *node2 = max_ptr->cust_num;
      max_savings = savings;
   }
   else if ((savings = (int) (SAV(&p->dist, max_ptr->cust_num, max_ptr->node2,
			   head->cust_num))) > head->savings){
      *node1 = max_ptr->cust_num;
      *node2 = max_ptr->node2;
      max_savings = savings;
   }
   else{
      *node1 = head->node1;
      *node2 = head->node2;
      max_savings = head->savings;
   }
   return(max_savings);
}
Esempio n. 2
0
void find_max(int *ins_cust, int *savings, int *node1,
              int *node2, _node *tour, int *intour,
              int prev_route_end, heur_prob *p)
{
    int v0 = 0, v1;
    register int i;
    int vertnum = p->vertnum;

    *savings = -MAXINT;

    for (i = 1; i<vertnum; i++)
        if (intour[i] != IN_TOUR) {
            v0 = 0;
            v1 = tour[prev_route_end].next;
            if (SAV(&p->dist, v0, v1, i) > *savings) {
                *savings = (int) (SAV(&p->dist, v0, v1, i));
                *node1 = v0;
                *node2 = v1;
                *ins_cust = i;
            }
            do {
                v1 = tour[v0=v1].next;
                if (SAV (&p->dist, v0, v1, i) > *savings) {
                    *savings = (int) (SAV(&p->dist, v0, v1, i));
                    *node1 = v0;
                    *node2 = v1;
                    *ins_cust = i;
                }
            } while (v1 != 0);
        }
    return;
}
Esempio n. 3
0
int find_new_ins_route3(heur_prob *p, int ins_node,
		       _node *tour, int *node1, int *node2,
		       route_data *route_info)
{
   int max_savings, savings;
   int cur_route, cur_node, prev_node;
   int weight = p->demand[ins_node];
   
   for (max_savings = -MAXINT, cur_route = 1; cur_route <= p->numroutes;
	cur_route++){
      if (route_info[cur_route].weight + weight > p->capacity)
	 continue;
      cur_node = route_info[cur_route].first;
      prev_node = 0;
      for (; cur_node; prev_node = cur_node, cur_node = tour[cur_node].next){
	if ((savings = (int) (SAV(&p->dist, prev_node, cur_node, ins_node)))
	     > max_savings){
	    max_savings = savings;
	    *node1 = prev_node;
	    *node2 = cur_node;
	 }
      }
   }

   return(max_savings);
}