Exemplo n.º 1
0
void ResidualNetwork::removeArc(uint32_t src, uint32_t dst) {
	// indices in range
	assert(validID(src) && validID(dst));
	uint32_t num_erased = arcs[src].erase(dst);
	assert(num_erased == 1); // check arc did exist
	num_erased = arcs[dst].erase(src);
	assert(num_erased == 1);
}
Exemplo n.º 2
0
void ResidualNetwork::pushFlow(uint32_t src, uint32_t dst, int64_t amount) {
	assert(validID(src) && validID(dst));
	arcs[src][dst]->pushFlow(amount);
	arcs[dst][src]->pushFlow(-amount);

	changeBalance(src, - amount);
	changeBalance(dst, amount);
}
Exemplo n.º 3
0
Arc *ResidualNetwork::getArc(uint32_t src, uint32_t dst) const {
	assert(validID(src) && validID(dst));
	std::unordered_map<uint32_t, Arc*>::const_iterator arcIt = arcs[src].find(dst);
	if (arcIt == arcs[src].end()) {
		return nullptr;
	} else {
		return arcIt->second;
	}
}
Exemplo n.º 4
0
bool ResidualNetwork::changeArcCapacity(uint32_t src, uint32_t dst,
		                                    uint64_t capacity) {
	// indices in range
	assert(validID(src) && validID(dst));

	// reverse arcs capacity remains 0 (the residual capacity on reverse arc
	// is flow on forward arc, which is unchanged)
	return arcs[src][dst]->setCapacity(capacity);
}
Exemplo n.º 5
0
void ResidualNetwork::addArc(uint32_t src, uint32_t dst,
							  uint64_t capacity, int64_t cost) {
	// indices in range
	assert(validID(src) && validID(dst));
	// arc does not already exist in graph
	assert(arcs[src].count(dst) == 0);
	// forward arc
	arcs[src][dst] = new Arc(src, dst, capacity, cost);
	// reverse arc
	arcs[dst][src] = new Arc(dst, src, 0, -cost);
}
Exemplo n.º 6
0
// SOMEDAY(adam): size of arcs & balance vector will grow without bound:
// we never compact the graph after having removed nodes.
void ResidualNetwork::removeNode(uint32_t id) {
	// check node currently exists
	assert(validID(id));

	// remove edges
	std::unordered_map<uint32_t, Arc*> &adjacencies = arcs[id];

	// remove the incoming edges
	for (auto &adjacency : adjacencies) {
		uint32_t dst_id = adjacency.first;
		// erase reverse pointer
		uint32_t num_erased = arcs[dst_id].erase(id);
		assert(num_erased == 1);
	 }

	// remove the outgoing edges
	adjacencies.clear();

	// remove any other references to it
	sources.erase(id);
	sinks.erase(id);

	// clear up state
	balances[id] = 0;
	supplies[id] = 0;

	// node now free
	num_nodes--;
	free_nodes.insert(id);
}
Exemplo n.º 7
0
void ResidualNetwork::setSupply(uint32_t id, int64_t supply) {
	assert(validID(id));

	int64_t delta = supply - supplies[id];
	supplies[id] = supply;
	changeBalance(id, delta);
	VLOG(3) << "setSupply (" << id << "): balance/supply = "
			    << balances[id] << "/" << supplies[id];
}
Exemplo n.º 8
0
void ResidualNetwork::changeBalance(uint32_t id, int64_t delta) {
	assert(validID(id));

	if (balances[id] > 0) {
		sources.erase(id);
	} else if (balances[id] < 0) {
		sinks.erase(id);
	}

	balances[id] += delta;

	if (balances[id] > 0) {
		sources.insert(id);
	} else if (balances[id] < 0) {
		sinks.insert(id);
	}
}
Exemplo n.º 9
0
void TransPanel::onClickBtnSaveConfig()
{
#define MIN_FREQUENCY_VALUE	1080
#define MAX_FREQUENCY_VALUE	1100

	QString ICAO_str = ui.lineEdit_icaoaddr->text() ;
	QString ID_str = ui.lineEdit_trID->text() ; 
	unsigned int frequency = ui.lineEdit_ply->text().toUInt() ;

	if(frequency>MAX_FREQUENCY_VALUE || frequency<MIN_FREQUENCY_VALUE)
	{
		QMessageBox::critical(this , "错误" , "频率源设置错误,取值范围[1080-1100]!");
		return	 ; 
	}

	bool icao_valid = validICAO(ICAO_str);
	if(!icao_valid)
	{
		QMessageBox::critical(this , "错误" , "ICAO地址必须为6个字节长度,0-F十六进制字符!");
		return	;
	}

	bool id_valid = validID(ID_str);
	if(!id_valid)
	{
		QMessageBox::critical(this , "错误" , "ID号长度不能超过8个字符!");
		return	;
	}

	std::string cmd = adsb_trans_ctrl_.cmd_save_config(ICAO_str.toStdString() ,ID_str.toStdString() ,frequency);


	sendCMD(cmd);



}
Exemplo n.º 10
0
int64_t ResidualNetwork::getSupply(uint32_t id) const {
	assert(validID(id));
	return supplies[id];
}
Exemplo n.º 11
0
void ResidualNetwork::changeArcCost(uint32_t src, uint32_t dst, int64_t cost) {
	// indices in range
	assert(validID(src) && validID(dst));
	arcs[src][dst]->setCost(cost);
	arcs[dst][src]->setCost(-cost);
}
Exemplo n.º 12
0
const std::unordered_map<uint32_t, Arc*>& ResidualNetwork::getAdjacencies
																													(uint32_t src) const {
	assert(validID(src));
	return arcs[src];
}