-
Notifications
You must be signed in to change notification settings - Fork 2
/
script.min.js
1 lines (1 loc) · 2.62 KB
/
script.min.js
1
class Matrix{constructor(a){this.data=[],this.size=0,a===void 0||this._load(a)}_load(a){a=JSON.parse(a),this.size=a.n[0];for(let b=a.A.splice(0),c=a.B.splice(0);b.length;)this.data.push(b.splice(0,this.size).concat(c.splice(0,1)))}swapRows(a,b){this.data[b]=[this.data[a],this.data[a]=this.data[b]][0]}indiceMaxColumn(a,b=0){let c=this.size,g=b,l=Math.abs(this.data[b][a]),o=0;for(let p=b+1;p<c;++p)o=Math.abs(this.data[p][a]),l<o&&(l=o,g=p);return g}substractLineFactor(a,b,c,g=0){for(let l=g;l<this.size+1;++l)this.data[b][l]-=this.data[a][l]*c}}class Solver{constructor(){this.x=[]}solve(a){this.x=[],this.x.length=a.size;let b,c;try{b=performance.now(),this.gaussTransform(a),this.resolveX(a,this.x),c=performance.now(),document.getElementById("chronotime").innerHTML=c-b+"ms"}catch(g){this.x=void 0}}gaussTransform(a){let b=a.data,c=a.size;if(0!==c)for(let g=b[0].length,l=0,o=0,p=0,q=0;l<c;)if(p=a.indiceMaxColumn(o,l),0==b[p][o])throw console.log("No constant solutions"),new Error("R\xE9sultat non-constant");else{l!=p&&a.swapRows(l,p);for(let r=l+1;r<c;++r)q=b[r][o]/b[l][o],b[r][o]=0,a.substractLineFactor(l,r,q,o+1);++l,++o}}resolveX(a){let b=a.size,c=a.data;for(let g=b-1;0<=g;--g){this.x[g]=c[g][b]/c[g][g];for(let l=g-1;0<=l;--l)c[l][b]-=c[l][g]*this.x[g]}}displayX(){let a=document.getElementById("result"),b="";if(!(this.x!=void 0))b="<div class=\"alert alert-danger\">Aucune solution constante trouv\xE9e!</div>";else if(0<this.x.length)for(let c=0;c<this.x.length;c++)b+="x<sub>"+(c+1)+"</sub> = "+this.x[c]+"<br>";else b="<div class=\"alert alert-warning\">Matrice de taille null!</div>";a.innerHTML=b}}let matrix=new Matrix;function loadClickedFile(a){a=a||window.event;let b=a.target||a.srcElement,c="./data/"+b.innerHTML,g=new XMLHttpRequest;g.overrideMimeType("application/json"),g.onreadystatechange=function(){4==this.readyState&&200==this.status&&(holder.value=this.responseText,matrix=new Matrix(this.responseText))},g.open("GET",c,!0),g.send(void 0)}document.onreadystatechange=()=>{if("interactive"===document.readyState){let a=/Chrome/.test(navigator.userAgent)&&/Google Inc/.test(navigator.vendor);if(!a){let g=document.getElementById("files");g.onclick=function(l){loadClickedFile(l)}}let b=document.getElementById("holder"),c=new Solver;document.getElementById("solve").onclick=function(){matrix=new Matrix(b.value),c.solve(matrix),c.displayX()},b.ondragover=function(){return this.className="hover",!1},b.ondragend=function(){return this.className="",!1},b.ondrop=function(g){g.preventDefault();let l=g.dataTransfer.files[0],o=new FileReader;return o.onload=function(p){b.value=p.target.result,matrix=new Matrix(p.target.result)},o.readAsText(l),!1}}};