Beispiel #1
0
Wire::Wire(Wire& ref)
    : QGraphicsPathItem(ref.parentItem(), ref.scene())
{
    setSource(ref.source());
    setDestination(ref.destination());
    setId(ref.id());
}
Beispiel #2
0
void Radio::PowerDown() {

	i2c.beginTransmission(SI4735ADR);
	i2c.write(0x11);
	i2c.endTransmission();
	_delay_ms(2);
}
Beispiel #3
0
void Circuit::print_testability()
{
    simulate_test();
    int num_sites = 0;
    int num_found = 0;
    for (int i = 0; i < linsts.size(); ++i) {
        Wire* owire = linsts[i]->get_output(0)->get_wire();
        if (owire->is_output()) {
            continue;
        } 
        if (linsts[i]->is_visited()) {
            continue;
        }

        num_sites += 2;
        if (observable_signal(linsts[i], STUCK1)) {
            ++num_found;
        }
        if (observable_signal(linsts[i], STUCK0)) {
            ++num_found;
        }
    } 
    
    cout << "Testability of candidate gates: " << 
        double(num_found) / double(num_sites) * 100 << "; Num remaining: " 
        << num_sites - num_found << "; Num faults: " << num_sites << endl;
}
Beispiel #4
0
void BddBuilder::__buildWireListB(BddBuilder * pA, Wire * pWireHead){
	Wire * pWireHorse;
	DdWire * pNewWire;
	DdWire * pInputWireHorse;
	__inputWireCnt = 0;
	__outputWireCnt = 0;

	for(pWireHorse=pWireHead ; pWireHorse ; pWireHorse=pWireHorse->get_next()){
		pNewWire = __addDdWireB(pA, pWireHorse);		
		switch(pWireHorse->get_value()){
			case -1: break;
			case 0: pNewWire->setDdNode(__GND); break;
			case 1: pNewWire->setDdNode(__Vcc); break;
			default: break;
		}
	}
	__pddInputNodes = new DdNode*[__inputWireCnt];	
	__ppInputNodesNames = new char*[__inputWireCnt];
	int i=0;
	pInputWireHorse = __pddInputWireHead->getInputListNext()->getInputListNext();
	for( ; pInputWireHorse ; pInputWireHorse=pInputWireHorse->getInputListNext()){
		__ppInputNodesNames[i] = pInputWireHorse->getName();
		__pddInputNodes[i++] = pInputWireHorse->getDdNode();
	}
}
/*---------------------------------------------------------------------------------------------
 * (function: mouseReleaseEvent)
 *-------------------------------------------------------------------------------------------*/
void ExplorerScene::mouseReleaseEvent(QGraphicsSceneMouseEvent *mouseEvent)
{
    if (line != 0 && myMode == InsertLine) {
        QList<QGraphicsItem *> startItems = items(line->line().p1());
        if (startItems.count() && startItems.first() == line)
            startItems.removeFirst();
        QList<QGraphicsItem *> endItems = items(line->line().p2());
        if (endItems.count() && endItems.first() == line)
            endItems.removeFirst();

        removeItem(line);
        delete line;


        if (startItems.count() > 0 && endItems.count() > 0 &&
            startItems.first()->type() == LogicUnit::Type &&
            endItems.first()->type() == LogicUnit::Type &&
            startItems.first() != endItems.first()) {
            LogicUnit *startItem =
                qgraphicsitem_cast<LogicUnit *>(startItems.first());
            LogicUnit *endItem =
                qgraphicsitem_cast<LogicUnit *>(endItems.first());
            Wire *wire = new Wire(startItem, endItem);
            wire->setColor(myLineColor);
            startItem->addConnection(wire);
            endItem->addConnection(wire);
            wire->setZValue(-1000.0);
            addItem(wire);
            wire->updatePosition();
        }
    }

    line = 0;
    QGraphicsScene::mouseReleaseEvent(mouseEvent);
}
Beispiel #6
0
    void spanResetWires(Pin* source){
        if (source == NULL) return;
        if (source->visited()) return;
        source->visited(true);

        Wire *wire = source->wire();
        if (!wire) return;
        //cout <<"spanResetWires wire: "<< wire->info()<<endl;
        wire->voltage(false);
        list<Pin *>pins = wire->pins();
        list<Pin *>::iterator it;
        for (it = pins.begin(); it != pins.end(); it++){
            Pin *pin = (*it);
            if (pin == source) continue;
            pin->visited(true);
            Element *element = pin->element();
            if (element->type() == "switch"){
                Switch *switc = (Switch *)element;
                Pin *nextPin = switc->outPin(pin);
                spanResetWires(nextPin);
            }
            else if (element->type() == "resistor"){
                Resistor *resistor = (Resistor *)element;
                Pin *nextPin = resistor->outPin(pin);
                spanResetWires(nextPin);
                
            }
            else if (element->type() == "bridge"){
                Bridge *bridge = (Bridge *)element;
                Pin *nextPin = bridge->outPin(pin);
                spanResetWires(nextPin);
            }
        }
    }
Beispiel #7
0
void Circuit::dumpCircuit()
{
    cout<<endl;
    cout<<"  Gate Name\tGate Level"<<endl;
    cout<<"========================================="<<endl;
    for( unsigned i = 0; i< numGate(); ++i )
    {
        Gate g = gate( i );
        cout<< "  " << g.name() << '\t' ;
        cout<< g.level() << '\t' ;
        //cout<< bitset<32>( value[i] ) <<'\t';
        cout<< endl;
    }

    cout<<endl;
    cout<<"  WireID\tWire Name\tType    \tValue"<<endl;
    cout<<"======================================================================================="<<endl;
    for( unsigned j = 0; j< numWire(); ++j )
    {
        Wire w = wire( j );
        cout<< "  "<< j << "\t\t";
        cout<< w.name() << "\t\t";
        cout<< setiosflags(ios::left) << setw(8) << w.type() <<'\t';
        if( w.type() != "UNUSED" )
            cout<< bitset<32>( w.valueSet() )<<'\t';
        else
            cout<<"XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX"<<'\t';
        cout<<endl;
    }
}
Beispiel #8
0
void BddBuilder::__buildWireList(Wire * pWireHead,char** input_sequence,int& total_input_band){
	Wire * pWireHorse;
	DdWire * pNewWire;
	DdWire * pInputWireHorse;
	__inputWireCnt = 0;
	__outputWireCnt = 0;

	for(pWireHorse=pWireHead ; pWireHorse ; pWireHorse=pWireHorse->get_next()){
		pNewWire = __addDdWire(pWireHorse);		
		switch(pWireHorse->get_value()){
			case -1: break;
			case 0: pNewWire->setDdNode(__GND); break;
			case 1: pNewWire->setDdNode(__Vcc); break;
			default: break;
		}
	}
	__pddInputNodes = new DdNode*[__inputWireCnt];
	__ppInputNodesNames = new char*[__inputWireCnt];
	int i=0;
	pInputWireHorse=__pddInputWireHead->getInputListNext()->getInputListNext();
	for( ; pInputWireHorse ; pInputWireHorse=pInputWireHorse->getInputListNext()){
		__ppInputNodesNames[i] = pInputWireHorse->getName();
		strcpy(input_sequence[i],__ppInputNodesNames[i]);
		__pddInputNodes[i++] = pInputWireHorse->getDdNode();
	}
	total_input_band =i;
}
void SchematicSceneBuilder::add_wire_component(
    std::map<std::string, std::string> props
  )
{
  if(!discard(props)) {
    Wire* item = static_cast<Wire*>(
      SchematicScene::itemByType(SchematicScene::WireItemType));

    bool ok;

    double to_x = QString::fromStdString(props["to_x"]).toDouble(&ok);
    if(!ok)
      to_x = SchematicScene::GridStep;

    double to_y = QString::fromStdString(props["to_y"]).toDouble(&ok);
    if(!ok)
      to_y = SchematicScene::GridStep;

    bool conn = QString::fromStdString(props["conn"]).toInt(&ok);
    if(!ok)
      conn = false;

    item->setWire(QLineF(QPointF(0, 0), QPointF(to_x, to_y)));
    item->setConnectedJunctions(conn);

    scene_->addSupportedItem(item, false);
    grid_coordinate(item, props);
    items_.push_back(item);
  }
}
Beispiel #10
0
void Radio::seekUpFMFreq() {

	i2c.beginTransmission(SI4735ADR);
	i2c.write(0x21);
	i2c.write(0x0C);
	i2c.endTransmission();
	_delay_ms(100);
}
Beispiel #11
0
 void upWires(list<Wire *>wires){
     list<Wire *>::iterator it;
     for (it = wires.begin(); it != wires.end(); it++){
         Wire *wire = (*it);
         wire->voltage(true);
         //cout <<"upped wire: "<<wire->info()<<endl;
     }
 }
Beispiel #12
0
void Radio::AMPowerOn() {

	i2c.beginTransmission(SI4735ADR);
	i2c.write(0x01);
	i2c.write(0x11);
	i2c.write(0x05);
	i2c.endTransmission();
	_delay_ms(500);
}
void SchematicSketchWidget::tidyWires() {
	QList<Wire *> wires;
	QList<Wire *> visited;
	foreach (QGraphicsItem * item, scene()->selectedItems()) {
		Wire * wire = dynamic_cast<Wire *>(item);
		if (wire == NULL) continue;
		if ((wire->getViewGeometry().wireFlags() & ViewGeometry::SchematicTraceFlag) == 0) continue;
		if (visited.contains(wire)) continue;
	}
/*---------------------------------------------------------------------------------------------
 * (function: setLineColor)
 *-------------------------------------------------------------------------------------------*/
void ExplorerScene::setLineColor(const QColor &color)
{
    myLineColor = color;
    if (isItemChange(Wire::Type)) {
        Wire *item =
            qgraphicsitem_cast<Wire *>(selectedItems().first());
        item->setColor(myLineColor);
        update();
    }
}
Beispiel #15
0
void Radio::seekDownAMFreq() {

	i2c.beginTransmission(SI4735ADR);
	i2c.write(0x41);
	i2c.write(0x04);
	i2c.write(0x00);
	i2c.write(0x00);
	i2c.endTransmission();
	_delay_ms(100);
}
Beispiel #16
0
void Circuit::commit_signatures()
{
    for (sym_map::iterator iter = sym_table.begin();
            iter != sym_table.end(); ++iter) {
        if (iter->second->get_type() == WIRE) {
            Wire* wire = (Wire*)(iter->second);
            wire->commit_signature();
        }
    }
}
Beispiel #17
0
Circuit::Circuit(Console *_console) : console(_console), terminals(1000),
    outLedList(IO_COUNT), usedInput(IO_COUNT, false), usedOutput(IO_COUNT, false)
{
    QList<QGraphicsItem *> items = console->items();

    Wire *wire;
    LED *led;
    IC *ic;
    int i, j;

    for (auto it = items.begin(); it != items.end(); it++)
    {
        if ((wire = dynamic_cast<Wire *>(*it)))
        {
            i = _console->getOffset(wire->line().p1());
            j = _console->getOffset(wire->line().p2());
            if (terminals.join(i, j))
            {
                connections.push_back(Connection(i, j));
                wire->markRedundent(false);
            }
            else
                wire->markRedundent(true);
            if (i >= OUTPUT_OFFSET)
                usedOutput[i-OUTPUT_OFFSET] = true;
            else if (i >= INPUT_OFFSET)
                usedInput[i-INPUT_OFFSET] = true;
            else if (j >= OUTPUT_OFFSET)
                usedOutput[j-OUTPUT_OFFSET] = true;
            else if (j >= INPUT_OFFSET)
                usedInput[j-INPUT_OFFSET] = true;
        }
        else if ((led = dynamic_cast<LED *>(*it)))
        {
            if (led->col >= 0 && led->col < 10)
                outLedList[led->col] = led;
            else
                ledList.push_back(led);
            led->switchOn(POWER);
        }
        else if ((ic = dynamic_cast<IC *>(*it)))
        {
            icList.push_back(ic);
        }
    }

    for (size_t i = 0; i < IO_COUNT; i++)
    {
        terminals.setstate(OUTPUT_OFFSET + i, State::undefined);
    }
    silentOutput = false;
#ifdef QT_DEBUG
    //terminals.print();
#endif
}
Beispiel #18
0
Wire* Wire::Clone()
{
    Wire* clone = new Wire();
    list<ConnectionPoint *>::iterator it;

    for( it = this->connectionPoints->begin(); it != this->connectionPoints->end(); it++ )
    {
        ConnectionPoint* cp = (*it)->Clone();
        clone->Attach( cp );
    }

    return clone;
}
Beispiel #19
0
void Radio::setFMFreq(int freq) {
	char hbyte, lbyte;
	
	hbyte = freq>>8;
	lbyte = freq & 0x00FF;
	i2c.beginTransmission(SI4735ADR);
	i2c.write(0x20);
	i2c.write(0x00);
	i2c.write(hbyte);
	i2c.write(lbyte);
	i2c.endTransmission();
	_delay_ms(100);
}
Beispiel #20
0
    //void spanResistors(Pin *source, list<Wire *>wires){
    void spanResistors(Pin *source, list<Resistor *>resistors){
        //cout <<"entering spanResistors"<<endl;
        /* 1. try to reach the end. 
         * 2. if end is reached, must go back and turn all wires on in the path
         */
        if (source == NULL) return;
        if (source->visited()) return;
        source->visited(true);
        //debug("spanResistors source pin: "<< source->fullName());

        Wire *wire = source->wire();
        if (!wire) return;
        //debug("spanResistors wire: "<< wire->name());
        list<Pin *>pins = wire->pins();
        list<Pin *>::iterator it;
        for (it = pins.begin(); it != pins.end(); it++){
            Pin *pin = (*it);
            if (pin == source) continue;
            pin->visited(true);
            //get element for source
            Element *element = pin->element();
            if (element->type() == "source"){
                //cerr << "Encountered source "<< element->info() <<" while completing circuit."<<endl;
                return;
            }
            else if (element->type() == "ground"){
                //cout <<"ground reached: "<<endl;
                //end reached.
                activateResistors(resistors);
                //upWires(wires);
            }
            else if (element->type() == "switch"){
                Switch *switc = (Switch *)element;
                if (!switc->isOn()) continue;

                Pin *nextPin = switc->outPin(pin);
                spanResistors(nextPin,resistors);
            }
            else if (element->type() == "resistor"){
                Resistor *resistor = (Resistor *)element;
                resistors.push_back(resistor);
                Pin *nextPin = resistor->outPin(pin);
                spanResistors(nextPin, resistors);
            }
            else if (element->type() == "bridge"){
                Bridge *bridge = (Bridge *)element;
                Pin *nextPin = bridge->outPin(pin);
                spanResistors(nextPin, resistors);
            }
        }
    }
Beispiel #21
0
void Radio::updateAMTuneStatus() {
	int i;
	
	i2c.beginTransmission(SI4735ADR);
	i2c.write(0x42);
	i2c.write(0x00);
	i2c.endTransmission();
	_delay_ms(2);

	i2c.requestFrom(SI4735ADR, 6);
	for(int i = 0; i < 6; i++) {
		switch(i) {
			case 2:
			AMfreq = i2c.read() * 256;
			break;
			case 3:
			AMfreq += i2c.read();
			break;
			case 4:
			AMrssi = i2c.read();
			break;
			default:
			i2c.read();
		}
	}
}
Beispiel #22
0
void init_objects() {
    TT.placement(40, 40 + ADOffset, 100, ADHeight + ADOffset - 40);

    turbine.placement(400, ADOffset + ADHeight / 2.0, ADHeight / 2.0);

    TIC.placement(30, 340, 180, 450);

    TT_TIC.placement(mean(TT.getStartX(), TT.getEndX()), TT.getEndY(), mean(TT.getStartX(), TT.getEndX()) ,400);

    wind.placement(ADOffset, ADOffset, WIDTH - ADOffset, ADOffset + ADHeight);

    boiler.placement(280, 220, 445, 330);

    boiler_wind[0].placement(mean(280, 445), mean(220, 330), 248, 152);
    boiler_wind[1].placement(248, 152, 248, 5);
    boiler_wind[2].placement(240, 5, 281, 280);
    boiler_wind[3].placement(248, 5, 240, 5);

    PrI.placement(300 , 390, 400, 440);
    PrI.sensePressure();

    oilValve.placement(mean(280, 445), mean(220, 330) - 80, 20);

    boiler_.placement(mean(280, 445), mean(220, 330), WIDTH, 375);
    pressureValve.placement(444, 375, 20);
    w[0].placement(mean (280, 445) - 20, mean(220, 330), mean(300, 400), mean(390, 440)); // Boiler_PrI
    w[1].placement(444, 375, mean(300, 400), mean(390, 440)); // Pressure Indicator_ PerssureValve
    w[2].placement(mean(40, 100), mean(40 + ADOffset, ADHeight + ADOffset - 40), mean(280, 445), mean(220, 330) - 80);
}
Beispiel #23
0
// true if current input signatures reveal that the given signal is observable
bool Circuit::observable_cover(string inst_name, string wire_name, CoverType cover)
{
    Inst* inst = (Inst*) sym_table[inst_name];
    Wire* wire = (Wire*) sym_table[wire_name];
    assert(sim_patterns > 0);

    Wire* owire = inst->get_output(0)->get_wire();
    int num_patterns = (sim_patterns - 1)/ SIGSTEP + 1;
    int leftover = sim_patterns%SIGSTEP;
        
    for (int j = 0; j < num_patterns; ++j) {
        for (int i = 0; i < int(input_wires.size()); ++i) {
            input_wires[i]->set_sig_temp(input_wires[i]->get_signature(j));
        }

        for (int i = 0; i < int(linsts.size()); ++i) {
            if ((j == (num_patterns - 1)) && (leftover > 0)) {
                linsts[i]->evaluate(leftover);
            } else {
                linsts[i]->evaluate(SIGSTEP);
            }

            if (linsts[i] == inst) {
                if (cover == EQUAL) {
                    owire->set_sig_temp((wire->get_sig_temp()));
                } else if (cover == AND) {
                    owire->set_sig_temp((wire->get_sig_temp() & owire->get_sig_temp()));
                } else if (cover == OR) {
                    owire->set_sig_temp((wire->get_sig_temp() | owire->get_sig_temp()));
                } else {
                    assert(0);
                }
            }
        } 

        for (int i = 0; i < int(output_wires.size()); ++i) {
            if (output_wires[i]->get_sig_temp() != output_wires[i]->get_signature(j)) {
                return true;
            }
        }
    }

    return false;
}
Beispiel #24
0
// true if current input signatures reveal that the given signal is observable
bool Circuit::observable_signal(Inst* inst, ModType mod)
{
    assert(sim_patterns > 0);

    Wire* owire = inst->get_output(0)->get_wire();
    int num_patterns = (sim_patterns - 1)/ SIGSTEP + 1;
    int leftover = sim_patterns%SIGSTEP;
        
    for (int j = 0; j < num_patterns; ++j) {
        for (int i = 0; i < int(input_wires.size()); ++i) {
            input_wires[i]->set_sig_temp(input_wires[i]->get_signature(j));
        }

        for (int i = 0; i < int(linsts.size()); ++i) {
            if ((j == (num_patterns - 1)) && (leftover > 0)) {
                linsts[i]->evaluate(leftover);
            } else {
                linsts[i]->evaluate(SIGSTEP);
            }

            if (linsts[i] == inst) {
                if (mod == FLIP) {
                    owire->set_sig_temp(~(owire->get_sig_temp()));
                } else if (mod == STUCK0) {
                    owire->set_sig_temp(0);
                } else if (mod == STUCK1) {
                    owire->set_sig_temp(~((unsigned long long)(0)));
                } else {
                    assert(0);
                }
            }
        } 

        for (int i = 0; i < int(output_wires.size()); ++i) {
            if (output_wires[i]->get_sig_temp() != output_wires[i]->get_signature(j)) {
                return true;
            }
        }
    }

    return false;
}
Beispiel #25
0
void display(void) {
    glClear(GL_COLOR_BUFFER_BIT);
    glPushMatrix();

    // Wind
    wind.draw();

    // Wires
    w[0].draw();
    w[1].draw();
    w[2].draw();

    // Air duct
    glColor3f WHITE;
    glLine(ADOffset, ADOffset, WIDTH - ADOffset, ADOffset);
    glLine(ADOffset, ADOffset + ADHeight, WIDTH - ADOffset, ADOffset + ADHeight);

    // Air sensor - controller connection
    TT_TIC.draw();

    // Air temperature sensor
    TT.draw();

    // Controller
    TIC.draw();

    // Air turbine
    glColor3f WHITE;
    turbine.draw();

    // Boiler_Wind pipe
    boiler_wind[0].draw();
    boiler_wind[1].draw();
    boiler_wind[2].draw();
    boiler_wind[3].draw();

    // Pressure Release Pipe
    boiler_.draw();

    // Pressure Valve;
    pressureValve.draw();

    // Boiler
    boiler.draw();

    // Pressure Indicator
    PrI.draw();

    // Oil Valve
    oilValve.draw();

    glPopMatrix();
    glutSwapBuffers();
}
Beispiel #26
0
void Circuit::AssignPiValue( Pattern* PatternSet )
{
    for( unsigned i = 0, j = 0 ; i < numWire(); ++i )
    {
        Wire pWire = wire(i);
        if( pWire.type() == "PI" )
        {
            value[ i ] = PatternSet->value[j];
            wire(i).setValueSet( PatternSet->value[j] );
            ++j;
        }
        else if ( pWire.type() == "TIE0" ) // assign value to TIE0
        {
            value[ i ] = 0;
            wire(i).setValueSet( 0 );
        }
        else if ( pWire.type() == "TIE1" ) // assign value to TIE1
        {
            value[ i ] = ~0;
            wire(i).setValueSet( ~0 );
        }
        else if ( pWire.type() == "CUT" || pWire.type() == "CUT_BAR" ) // assign value to cut points
        {
            value[ i ] = PatternSet->value[j];
            wire(i).setValueSet( PatternSet->value[j] );
            ++j;
        }
    }
}
Beispiel #27
0
void Radio::setProperty(int prop, int val) {
	char propertyHighByte;
	char propertyLowByte;
	char propertyValueHighByte;
	char propertyValueLowByte;
	
	propertyHighByte = prop>>8;
	propertyLowByte = prop & 0x00FF;
	propertyValueHighByte = val>>8;
	propertyValueLowByte = val & 0x00FF;
	
	i2c.beginTransmission(SI4735ADR);
	i2c.write(0x12);
	i2c.write(0x00);
	i2c.write(propertyHighByte);
	i2c.write(propertyLowByte);
	i2c.write(propertyValueHighByte);
	i2c.write(propertyValueLowByte);
	i2c.endTransmission();
	_delay_ms(20);
}
Beispiel #28
0
void Radio::updateFMRsqStatus() {
	int i;
	
	i2c.beginTransmission(SI4735ADR);
	i2c.write(0x23);
	i2c.write(0x20);
	i2c.endTransmission();
	_delay_ms(2);

	i2c.requestFrom(SI4735ADR, 6);
	for(int i = 0; i < 6; i++) {
		switch(i) {
			case 4:
			FMrssi = i2c.read();
			break;
			default:
			i2c.read();
		}
	}
}
Beispiel #29
0
void GraphUtils::minCut(QList<ConnectorItem *> & connectorItems, QList<SketchWidget *> & foreignSketchWidgets, ConnectorItem * source, ConnectorItem * sink, QList<ConnectorEdge *> & minCut) 
{
	// this helped:  http://boost.2283326.n4.nabble.com/graph-edmund-karp-max-flow-vs-kolmogorov-max-flow-color-map-td2565611.html
	
	using namespace boost;

	typedef adjacency_list_traits < vecS, vecS, directedS > Traits;
    typedef property < vertex_color_t, boost::default_color_type > COLOR;
	typedef property < vertex_index_t, long, COLOR > VERTEX;
    typedef property < edge_reverse_t, Traits::edge_descriptor > REVERSE;
    typedef property < edge_residual_capacity_t, long, REVERSE > RESIDUAL;
	typedef property < edge_capacity_t, long, RESIDUAL > EDGE;
	typedef adjacency_list < listS, vecS, directedS, VERTEX, EDGE > Graph;

	Graph g;

	property_map < Graph, edge_capacity_t >::type capacity = get(edge_capacity, g);
	property_map < Graph, edge_residual_capacity_t >::type residual_capacity = get(edge_residual_capacity, g);
	property_map < Graph, edge_reverse_t >::type reverse = get(edge_reverse, g);

	property_map < Graph, vertex_color_t >::type color = get(vertex_color, g);
	property_map < Graph, vertex_index_t >::type index = get(vertex_index, g);

	Traits::vertex_descriptor s, t;

	QList<Wire *> visitedWires;
	QList<int> indexes;
	QHash<ConnectorItem *, int> vertices;
	QList<ConnectorEdge *> edges;
	QVector<Traits::vertex_descriptor> verts;

	vertices.insert(source, 0);
	vertices.insert(sink, 1);
	verts.append(s = add_vertex(g));
	verts.append(t = add_vertex(g));

	foreach (ConnectorItem * connectorItem, connectorItems) {
		//connectorItem->debugInfo("input");
		if (connectorItem->attachedToItemType() == ModelPart::Wire) {
			Wire * wire = qobject_cast<Wire *>(connectorItem->attachedTo());
			if (visitedWires.contains(wire)) continue;

			QList<Wire *> wires;
			QList<ConnectorItem *> ends;
			wire->collectChained(wires, ends);
			visitedWires.append(wires);
			if (ends.count() < 2) continue;

			foreach (ConnectorItem * end, ends) {
				appendVertIf(end, vertices, verts);
			}

			for (int i = 0; i < ends.count(); i++) {
				ConnectorItem * end = ends[i];
				for (int j = i + 1; j < ends.count(); j++) {
					ConnectorEdge * connectorEdge = makeConnectorEdge(edges, end, ends[j], 1000, wire);
					connectorEdge->setHeadTail(vertices.value(connectorEdge->c0), vertices.value(connectorEdge->c1));
				}
			}
			continue;
		}
Beispiel #30
0
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;
}