Skip to content

Commit

Permalink
ajout fortement connexe
Browse files Browse the repository at this point in the history
  • Loading branch information
safirex committed Jun 28, 2020
1 parent de6f8d2 commit b2cfa5f
Show file tree
Hide file tree
Showing 7 changed files with 108 additions and 115 deletions.
2 changes: 1 addition & 1 deletion graphicview.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@ void GraphicView::updateDisplay()
cout<<"taille de la matrice "<<sqrt(vf.size())<<endl;
int nbSommet=sqrt(vf.size());

for(int i=0;i<vf.size();i++)
for(int i=0;i<(int)vf.size();i++)
{
if(vf[i]!=0)
{
Expand Down
23 changes: 18 additions & 5 deletions mainwindow.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -30,12 +30,12 @@ void MainWindow::updateInfoContent()
qs=qs.fromStdString(to_string(matrice.ordre));
ui->label_Ordre->setText(qs);


/*
QString symetrie;
if(matrice.type==Matrice::Type::NonOrientee)
symetrie=symetrie.fromStdString("oui");
ui->label_Symetrie->setText(symetrie);

*/

QString connexe;
if(matrice.isConnex())
Expand All @@ -44,6 +44,14 @@ void MainWindow::updateInfoContent()
connexe=connexe.fromStdString("non");
ui->label_Connexe->setText(connexe);

QString fortementConnexe;
if(matrice.isFortementConnex())
fortementConnexe=fortementConnexe.fromStdString("oui");
else
fortementConnexe=fortementConnexe.fromStdString("non");
ui->label_FortementConnexe->setText(fortementConnexe);


}


Expand All @@ -55,6 +63,8 @@ void MainWindow::on_pushButton_2_clicked()
matrice.calculTransposee(tab);
Dialog dial(nullptr,tab);
dial.setModal(true);

dial.setWindowTitle("Transposée");
dial.exec();
}

Expand All @@ -66,6 +76,8 @@ void MainWindow::on_pushButton_clicked()
matrice.calculPowN(n,tab);
Dialog dial(nullptr,tab);
dial.setModal(true);

dial.setWindowTitle("M^n");
dial.exec();
}

Expand All @@ -77,7 +89,7 @@ void MainWindow::on_typeChangeButton_clicked()
char ch[30];
strcpy(ch,matrice->getTypeToString().c_str());
QString qs(ch);
ui->typeChangeButton->setText(qs);
//ui->typeChangeButton->setText(qs);
ui->tableWidget->displayRefresh();
}

Expand All @@ -104,12 +116,13 @@ void MainWindow::on_pushButton_Dijkstra_clicked()
vector<float> tab (matrice.ordre*matrice.ordre);
//int n=ui->factorNSpinBox->value();

Sommet* s =matrice.getSommetNum(1);
Sommet* s =matrice.getSommetNum(0);
cout<<s->getName()+" pos = "+to_string(matrice.getPosSommet(s))<<endl;
matrice.calculateDijkstra(*s,tab);
cout<<"still ok"<<endl;
Dialog dial(nullptr,tab);
Dialog dial(this,tab);
dial.setModal(true);
dial.setWindowTitle("Dijkstra");
dial.exec();
}

Expand Down
91 changes: 5 additions & 86 deletions mainwindow.ui
Original file line number Diff line number Diff line change
Expand Up @@ -299,36 +299,6 @@
</property>
</widget>
</item>
<item>
<layout class="QHBoxLayout" name="horizontalLayout_14" stretch="0,0">
<item>
<widget class="QLabel" name="label_17">
<property name="enabled">
<bool>false</bool>
</property>
<property name="text">
<string>Type</string>
</property>
</widget>
</item>
<item>
<widget class="QPushButton" name="typeChangeButton">
<property name="enabled">
<bool>false</bool>
</property>
<property name="sizePolicy">
<sizepolicy hsizetype="Preferred" vsizetype="Fixed">
<horstretch>0</horstretch>
<verstretch>0</verstretch>
</sizepolicy>
</property>
<property name="text">
<string>Non Orientée</string>
</property>
</widget>
</item>
</layout>
</item>
<item>
<layout class="QHBoxLayout" name="horizontalLayout_16">
<item>
Expand All @@ -347,30 +317,6 @@
</item>
</layout>
</item>
<item>
<layout class="QHBoxLayout" name="horizontalLayout_15" stretch="0,0">
<item>
<widget class="QLabel" name="label_18">
<property name="enabled">
<bool>false</bool>
</property>
<property name="text">
<string>Biparti</string>
</property>
</widget>
</item>
<item>
<widget class="QRadioButton" name="radioButton">
<property name="enabled">
<bool>false</bool>
</property>
<property name="text">
<string/>
</property>
</widget>
</item>
</layout>
</item>
<item>
<layout class="QHBoxLayout" name="horizontalLayout_7" stretch="0,0">
<item>
Expand Down Expand Up @@ -408,46 +354,19 @@
</layout>
</item>
<item>
<layout class="QHBoxLayout" name="horizontalLayout_6" stretch="0,0">
<layout class="QHBoxLayout" name="horizontalLayout_6">
<item>
<widget class="QLabel" name="label_5">
<widget class="QLabel" name="label_4">
<property name="enabled">
<bool>false</bool>
<bool>true</bool>
</property>
<property name="text">
<string>Carré</string>
<string>Fortement Connexe</string>
</property>
</widget>
</item>
<item>
<widget class="QLabel" name="label_6">
<property name="enabled">
<bool>false</bool>
</property>
<property name="text">
<string>Non</string>
</property>
</widget>
</item>
</layout>
</item>
<item>
<layout class="QHBoxLayout" name="horizontalLayout_9" stretch="0,0">
<item>
<widget class="QLabel" name="label_8">
<property name="enabled">
<bool>false</bool>
</property>
<property name="text">
<string>Symétrique</string>
</property>
</widget>
</item>
<item>
<widget class="QLabel" name="label_Symetrie">
<property name="enabled">
<bool>false</bool>
</property>
<widget class="QLabel" name="label_FortementConnexe">
<property name="text">
<string>Non</string>
</property>
Expand Down
93 changes: 72 additions & 21 deletions matrice.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -126,34 +126,26 @@ void Matrice::calculPowN(int n, vector<float> &emptyVector)
newtab[i]=caseValue;
}
tab2=newtab;
string tmp="| ";
/*string tmp="| ";
for (int i=0;i<ordre*ordre;i++)
{
tmp+=to_string(newtab[i])+" | ";
if((i+1)%ordre==0)
tmp+="\n| ";
}
cout<<tmp<<endl;
cout<<tmp<<endl;*/
}
emptyVector=newtab;
}

void Matrice::calculateDijkstra(Sommet &s, vector<float> &emptyVector)
{
updateOrdre();
vector<float> tab (ordre*ordre);
vector<float> newtab;
getCalculationTab(tab);
vector<Sommet*> outedSommetList(ordre);


tab=newtab;

// first loop
vector<float>vf(ordre,numeric_limits<float>::infinity());
newtab=vf;
vector<float>newtab(ordre,numeric_limits<float>::infinity());

int pos=getPosSommet(&s);
cout<<"pos = "+to_string(pos)<<endl;
newtab[pos]=0.0;
vector<Sommet*>vs;

Expand All @@ -177,6 +169,11 @@ void Matrice::calculateDijkstra(Sommet &s, vector<float> &emptyVector)

void Matrice::fillVoisin(vector<float> &DijkstraMap, Sommet & sommet, vector<Sommet *> &outList)
{
Sommet* nextSommet;
float nextSommetValue=numeric_limits<float>::infinity();

outList.push_back(&sommet);

cout<<"fill voisin point: "+sommet.getName()+" pos: "+to_string(getPosSommet(&sommet))<<endl;
float infValue=numeric_limits<float>::infinity();
int lastLine= DijkstraMap.size()-ordre ; //get to first elem of last line
Expand All @@ -202,11 +199,31 @@ void Matrice::fillVoisin(vector<float> &DijkstraMap, Sommet & sommet, vector<Som

if(poidsNextSommet>poidSommet+it->getPoid() || poidsNextSommet==infValue)
{
if(it->getPoid()==0) // 0 equals no link
continue;
if(it->getPoid()!=0) // 0 equals no link
DijkstraMap[lastLine+ordre+posSommet2]=poidSommet+it->getPoid();
}


bool roar=true;
for (auto somm : outList)
{
if(somm->getName().compare(it->getSecond()->getName())==0)
roar=false;

DijkstraMap[lastLine+ordre+posSommet2]=poidSommet+it->getPoid();
}
if(roar)
{
// v does not contain x
if(nextSommetValue==infValue ||
nextSommetValue>DijkstraMap[lastLine+ordre+getPosSommet(it->getSecondAddr())])
{
nextSommet=&it->getSecondAddr();
nextSommetValue=DijkstraMap[lastLine+ordre+getPosSommet(it->getSecondAddr())];
}
}



}


Expand All @@ -219,8 +236,13 @@ void Matrice::fillVoisin(vector<float> &DijkstraMap, Sommet & sommet, vector<Som
}
cout<<tmp<<endl;

outList.push_back(&sommet);
if((int)outList.size()<ordre)
if(outList.size()<ordre)
fillVoisin(DijkstraMap,*nextSommet,outList);



/*
if((int)outList.size()<=ordre)
{
for (it=arrList->begin();it!=arrList->end();it++) //for each arrete of actual Sommet
{
Expand All @@ -237,7 +259,7 @@ void Matrice::fillVoisin(vector<float> &DijkstraMap, Sommet & sommet, vector<Som
cout<<"Nouveau Sommet = "+it->getSecond()->getName()<<endl;
}
}
}
}*/

}

Expand All @@ -251,7 +273,7 @@ void Matrice::setNextType()
if(type==Type::Orientee)
type=Type::NonOrientee;
else if(type==Type::NonOrientee)
type=Type::Orientee;
type=Type::Orientee;

}

Expand Down Expand Up @@ -340,7 +362,7 @@ void Matrice::updateValues()
updateTaille();
updateOrdre();
updateSymetrie();
updateConnexe();
updateConnexe();updateFortementConnexe();
}

void Matrice::updateTaille()
Expand All @@ -365,6 +387,28 @@ void Matrice::updateSymetrie()

void Matrice::updateConnexe()
{
int tab[ordre];
vector<float> vf(ordre*ordre);
getCalculationTab(vf);
for(int i=0;i<(int)vf.size();i++)
{
if(vf[i]!=0)
{
tab[i/ordre]=1;
tab[i%ordre]=1;
}
}
bool tmp=true;
for(int it=0;it<ordre;it++){
if (tab[it]!=1)
tmp=false;
}
connexe=tmp;
}

void Matrice::updateFortementConnexe()
{

bool tmp=true;
vector<float> vf(ordre*ordre);
calculPowN(ordre,vf);
Expand All @@ -376,13 +420,20 @@ void Matrice::updateConnexe()
break;
}
}
connexe=tmp;
fortementConnexe=tmp;
}



bool Matrice::isConnex()
{
return connexe;
}

bool Matrice::isFortementConnex()
{
return fortementConnexe;
}
string Matrice::toString()
{
string tmp="matrice:\n";
Expand Down
Loading

0 comments on commit b2cfa5f

Please sign in to comment.