本文整理汇总了C++中Switch::GetIsOn方法的典型用法代码示例。如果您正苦于以下问题:C++ Switch::GetIsOn方法的具体用法?C++ Switch::GetIsOn怎么用?C++ Switch::GetIsOn使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Switch
的用法示例。
在下文中一共展示了Switch::GetIsOn方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: CountCost
void Graph::CountCost (){
ResetVerticesMarks();
for (auto source:source_vertices_) { //bfs for each source;
ResetVerticesMarks();
queue<Vertex*> bfs_queue;
bfs_queue.push(source);
source->SetIsVisted(true);
string source_name = source ->GetRaw()->GetName();
vector <Vertex*> vector_leafs;
//cout <<"Start:"<<source_name<<endl;
while (!bfs_queue.empty()){
Vertex* front = bfs_queue.front();
bfs_queue.pop();
for (int i=0; i<front->GetIncidentEdgesNum();++i){
Vertex* child = front->GetIncidentEdge(i)->GetNeighbor(front);
Edge* connect_edge = front->GetIncidentEdge(i);
if (child->GetType()==Vertex::Type::PSEUDO){
child = dynamic_cast<PseudoVertex*>(child)->GetBoundaryVertex(front->GetIncidentEdge(i));
connect_edge = edges_[front->GetIncidentEdge(i)->GetRaw()->GetName()];
}
if (child->GetIsVisited() || child->GetAssignSource()!=source_name){
continue;
}
child->SetIsVisted(true);
child->SetParent(front);
front->AddChild(child);
bfs_queue.push(child);
child->SetParentEdge(connect_edge);
}
if (front->GetChildrenNum() == 0){
vector_leafs.push_back(front);
} else if (front->GetType() == Vertex::Type::RESIDENT ){
cout <<"error!!! :resident has more one edge"<<endl;
}
}
/*
for (auto pair: vertices_) {
if (!pair.second->GetIsVisited() && pair.second->GetAssignSource()==source_name){
cout <<"someting wrong!!"<<endl;
}
}
*/
cout <<"process:"<<source_name<<" leafnum:"<<vector_leafs.size()<<endl;
for (auto child : vector_leafs){
//Vertex* child = pair.second;
if (child->GetType() == Vertex::Type::RESIDENT && child->GetAssignSource() == source_name) {
//cout <<"IN!! "<<endl;
double load_current = dynamic_cast<ResidentVertex*>(child)->GetConsumingPower()/child->GetVoltage();
//cout <<"load:"<< load_current<<endl;
while (child!=source) {
Vertex* parent = child->GetParent();
Edge* connect_edge = child->GetParentEdge();
assert(connect_edge->GetNeighbor(child)==parent);
connect_edge->SetCurrent(connect_edge->GetCurrent()+load_current);
child = parent;
}
}
}
//cout <<"finish:"<<source_name<<endl;
}
//cout <<"counting..."<<endl;
wire_upgrade = 0.0;
switch_change =0;
for (auto pair:edges_) {
if (pair.second->GetType()==Edge::Type::EDGE){
Wire* wire = pair.second->GetRaw();
if (pair.second->GetCurrent() > wire->GetCurrentLimit()){
//cout <<"Current:"<< pair.second->GetCurrent()<< " Limit:"<< wire->GetCurrentLimit()<<endl;
wire_upgrade += pair.second->GetCurrent()-wire->GetCurrentLimit();
}
}else if(pair.second->GetType()==Edge::Type::SWITCH){
Switch* switches = dynamic_cast<Switch*> (pair.second->GetRaw());
Vertex* a = pair.second->GetIncidentVertex(0);
Vertex* b = pair.second->GetIncidentVertex(1);
if ( (a->GetAssignSource() != b->GetAssignSource() && switches->GetIsOn()) || (a->GetAssignSource() == b->GetAssignSource() && !switches->GetIsOn() ))
switch_change++;
}
}
cout << "wire upgrade :" << wire_upgrade << endl;
cout << "wire change :" << switch_change << endl;
}