Minimaler Schnitt wird hervorgehoben, wenn der Algorithmus fertig ist
parent
d7887f77db
commit
eba13bb713
|
|
@ -18,6 +18,7 @@ editMode="drag";
|
||||||
draggedVertex=null;
|
draggedVertex=null;
|
||||||
possibleNextSteps=[];
|
possibleNextSteps=[];
|
||||||
flowVertices=["s"];
|
flowVertices=["s"];
|
||||||
|
reachableFromStart=null;
|
||||||
function draw(){
|
function draw(){
|
||||||
function drawEdge(vertexFrom,vertexTo,number,fillColor,strokeColor){
|
function drawEdge(vertexFrom,vertexTo,number,fillColor,strokeColor){
|
||||||
co.fillStyle=fillColor;
|
co.fillStyle=fillColor;
|
||||||
|
|
@ -49,12 +50,24 @@ function draw(){
|
||||||
co.fillStyle="#888888"
|
co.fillStyle="#888888"
|
||||||
co.fillRect(0,0,1000,1000);
|
co.fillRect(0,0,1000,1000);
|
||||||
for(let vertex of vertices){
|
for(let vertex of vertices){
|
||||||
|
let vertexReachable=false;
|
||||||
|
if(done){
|
||||||
|
for(let reachableOne of reachableFromStart){
|
||||||
|
if(reachableOne==vertex.name){
|
||||||
|
vertexReachable=true;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
if(vertex.special=="source"){
|
if(vertex.special=="source"){
|
||||||
co.fillStyle="#aaffaa";
|
co.fillStyle="#aaffaa";
|
||||||
}else if(vertex.special=="target"){
|
}else if(vertex.special=="target"){
|
||||||
co.fillStyle="#ffaaaa";
|
co.fillStyle="#ffaaaa";
|
||||||
}else{
|
}else{
|
||||||
co.fillStyle="white";
|
co.fillStyle="white";
|
||||||
|
if(done){
|
||||||
|
co.fillStyle="#ffaaaa";
|
||||||
|
if(vertexReachable){co.fillStyle="#aaffaa"}
|
||||||
|
}
|
||||||
for(let alreadyVisited of flowVertices){
|
for(let alreadyVisited of flowVertices){
|
||||||
if(alreadyVisited==vertex.name){
|
if(alreadyVisited==vertex.name){
|
||||||
co.fillStyle="#aaaaff";
|
co.fillStyle="#aaaaff";
|
||||||
|
|
@ -77,9 +90,23 @@ function draw(){
|
||||||
}
|
}
|
||||||
|
|
||||||
co.fillStyle="black";
|
co.fillStyle="black";
|
||||||
|
co.font="10px sans-serif";
|
||||||
co.fillText(vertex.name,vertex.x,vertex.y,20);
|
co.fillText(vertex.name,vertex.x,vertex.y,20);
|
||||||
|
|
||||||
for(let otherVertex of vertices){
|
for(let otherVertex of vertices){
|
||||||
|
|
||||||
|
if(vertexReachable){
|
||||||
|
otherVertexReachable=false;
|
||||||
|
for(let reachableOne of reachableFromStart){
|
||||||
|
if(reachableOne==otherVertex.name){
|
||||||
|
otherVertexReachable=true;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if(otherVertexReachable==false){
|
||||||
|
co.font="bold 15px sans-serif";
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
if(shownEdges=="capacity"){
|
if(shownEdges=="capacity"){
|
||||||
if(edgesCapacity[vertex.name][otherVertex.name]>0){
|
if(edgesCapacity[vertex.name][otherVertex.name]>0){
|
||||||
drawEdge(vertex,otherVertex,edgesCapacity[vertex.name][otherVertex.name],"black","white");
|
drawEdge(vertex,otherVertex,edgesCapacity[vertex.name][otherVertex.name],"black","white");
|
||||||
|
|
@ -97,6 +124,7 @@ function draw(){
|
||||||
drawEdge(vertex,otherVertex,getEdge(edgesFlow,vertex.name,otherVertex.name)+"/"+edgesCapacity[vertex.name][otherVertex.name],"black",edgesFlow[vertex.name][otherVertex.name]>0?(edgesFlow[vertex.name][otherVertex.name]==edgesCapacity[vertex.name][otherVertex.name]?"#ff88ff":"#8888ff"):"white");
|
drawEdge(vertex,otherVertex,getEdge(edgesFlow,vertex.name,otherVertex.name)+"/"+edgesCapacity[vertex.name][otherVertex.name],"black",edgesFlow[vertex.name][otherVertex.name]>0?(edgesFlow[vertex.name][otherVertex.name]==edgesCapacity[vertex.name][otherVertex.name]?"#ff88ff":"#8888ff"):"white");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
co.font="10px sans-serif";
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
for(let i=0;i<flowVertices.length-1;i++){
|
for(let i=0;i<flowVertices.length-1;i++){
|
||||||
|
|
@ -209,7 +237,6 @@ function resetFlows(){
|
||||||
function bfs(){
|
function bfs(){
|
||||||
let searches=[["s"]];
|
let searches=[["s"]];
|
||||||
let visitedVertices=["s"];
|
let visitedVertices=["s"];
|
||||||
let end=false;
|
|
||||||
while(searches.length>0){
|
while(searches.length>0){
|
||||||
currentSearch=searches.shift();
|
currentSearch=searches.shift();
|
||||||
if(currentSearch[currentSearch.length-1]=="t"){
|
if(currentSearch[currentSearch.length-1]=="t"){
|
||||||
|
|
@ -229,6 +256,7 @@ function bfs(){
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
reachableFromStart=visitedVertices;
|
||||||
}
|
}
|
||||||
function selectShortestPath(){
|
function selectShortestPath(){
|
||||||
result=bfs();
|
result=bfs();
|
||||||
|
|
@ -243,7 +271,7 @@ function selectShortestPath(){
|
||||||
function selectRandomPath(){
|
function selectRandomPath(){
|
||||||
flowVertices=["s"];
|
flowVertices=["s"];
|
||||||
let visitedVertices=["s"];
|
let visitedVertices=["s"];
|
||||||
for(let i=0;i<2000;i++){
|
for(let i=0;i<20000;i++){
|
||||||
calculatePossibleNextSteps();
|
calculatePossibleNextSteps();
|
||||||
let nextSteps=[];
|
let nextSteps=[];
|
||||||
for(let step of possibleNextSteps){
|
for(let step of possibleNextSteps){
|
||||||
|
|
@ -350,12 +378,12 @@ function generateNewFlow(){
|
||||||
totalFlow+=newFlow;
|
totalFlow+=newFlow;
|
||||||
flowVertices=["s"];
|
flowVertices=["s"];
|
||||||
calculatePossibleNextSteps();
|
calculatePossibleNextSteps();
|
||||||
draw();
|
|
||||||
statusSim.innerText="Iteration "+iterations+". Augmentierender Pfad mit Flusskapazität "+newFlow+" hinzugefügt. Insgesamt hat der Fluss die Kapazität "+totalFlow+".";
|
statusSim.innerText="Iteration "+iterations+". Augmentierender Pfad mit Flusskapazität "+newFlow+" hinzugefügt. Insgesamt hat der Fluss die Kapazität "+totalFlow+".";
|
||||||
if(bfs()==undefined){
|
if(bfs()==undefined){
|
||||||
statusSim.innerText+=" Es gibt keinen augmentierenden Pfad mehr, der Algorithmus ist fertig.";
|
statusSim.innerText+=" Es gibt keinen augmentierenden Pfad mehr, der Algorithmus ist fertig.";
|
||||||
done=true;
|
done=true;
|
||||||
};
|
}
|
||||||
|
draw();
|
||||||
}
|
}
|
||||||
function resetToDefaultGraph(){
|
function resetToDefaultGraph(){
|
||||||
vDef.value="u;v;w;x;y;z;";
|
vDef.value="u;v;w;x;y;z;";
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue