Beispiel #1
0
void IntervalMap::remove(pcNode*node, int interval) {
	// Ein Blatt
	//TODO: FIX BUG
	if (!node->left && !node->right) {
		*get_parent_ptr(node, interval) = 0;
		delete node;
	}
	// Nur ein Kind
	else if (node->left && !node->right) {
		*get_parent_ptr(node, interval) = node->left;
		node->left->parent = node->parent;
		delete node;
	} else if (!node->left && node->right) {
		*get_parent_ptr(node, interval) = node->right;
		node->right->parent = node->parent;
		delete node;
	}
	// Zwei Kinder
	else {
		std::cout << "swap" << std::endl;
		pcNode*other = get_prev_node(node);
		std::cout << other->y << std::endl;
		swap_nodes(node, other, interval);
		std::cout << "after swap" << std::endl;
		// Löschen des Knoten durch Benutzen von einer
		// der beiden anderen Methoden
		remove(node, interval);
	}
}
Beispiel #2
0
void remove_shelf(node* n, shelf* shelf)
{
  list* l = get_list(n);
  linked_list_node* prev = get_prev_node(l, shelf);
  linked_list_node* remove;
  if (prev == NULL)
    {
      remove = l -> ll_first;
      l -> ll_first = remove -> next_node;
    }
  else
    {    
      remove = prev -> next_node;
      linked_list_node* next = remove -> next_node;
      prev -> next_node = next;
    }
  int r_amount = get_shelf_amount2(remove);
  l -> total = l -> total - r_amount;
  destroy_llnode(remove);
}
int update_with_sensor_data( track_node *triggered_sensor, Train_status *train_status, 
							 Train_server_data *server_data ){
	// Initialization
	int error_distance; 
	track_node *prev_node; 
	Train_position current_pos = train_status->current_position;

	// What's the distance from the calculated position to the actual position? 
	// NOTE: From the current position we check the next and previous landmark and see if
	// the triggered sensor is there. If not, the train is declared lost. 
	if ( current_pos.landmark == triggered_sensor ){
		error_distance = -current_pos.offset;
	}
	else if( current_pos.edge->dest == triggered_sensor ){
		error_distance = current_pos.edge->dist - current_pos.offset;
	}
	else{ 
		int sensor_found = 0; 
		prev_node = get_prev_node( &current_pos );

		if ( prev_node ){
			if ( prev_node == triggered_sensor ){
				sensor_found = 1; 
				error_distance = current_pos.landmark->reverse->edge[ DIR_AHEAD ].dist;
			}
		}
		else if( current_pos.landmark->type == NODE_MERGE ) {
			// The current node is a merge
			track_node *straight_node = current_pos.landmark->reverse->edge[ DIR_STRAIGHT ].dest;
			track_node *reverse_node = current_pos.landmark->reverse->edge[ DIR_CURVED ].dest; 

			if ( straight_node == triggered_sensor ){
				sensor_found = 1; 
				error_distance = current_pos.landmark->reverse->edge[ DIR_STRAIGHT ].dist;
			}
			else if( reverse_node == triggered_sensor ){
				sensor_found = 1; 
				error_distance = current_pos.landmark->reverse->edge[ DIR_CURVED ].dist;
			}
		}

		if( sensor_found ){
			error_distance = ( error_distance * -1 ) - current_pos.offset; 
		}
		else{
			bwdebug( DBG_USR, TRAIN_SRV_DEBUG_AREA, 
				"TRAIN_MOTION: update_with_sensor_data -> The train is lost [ train_id: %d ]", 
				train_status->train_id );
			// TODO: Mark the train status as lost
			// Stop the train right away. 
			return 0; 
		}
	}

	// Make the sensor the current position
	// TODO: Do we need to calculate the time the train spent processing? 
	train_status->current_position.offset = 0; 
	train_status->current_position.landmark = triggered_sensor;
	train_status->current_position.edge = &triggered_sensor->edge[ DIR_AHEAD ];

	// Update the error
	train_status->motion_data.current_error += error_distance;
	return 1; 
}