Skip to content

Commit dc8a2d9

Browse files
committed
preenchendo a tabela com a classe Matriz
1 parent 8ee1e58 commit dc8a2d9

3 files changed

Lines changed: 169 additions & 49 deletions

File tree

app/models/matriz-test.js

Lines changed: 58 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,58 @@
1+
class Matriz {
2+
constructor(rows, cols) {
3+
this.rows = rows;
4+
this.cols = cols;
5+
6+
this.data = [];
7+
8+
for (var i = 0; i < rows; i++) {
9+
var arr = [];
10+
for (var j = 0; j < cols; j++) {
11+
arr.push(0);
12+
}
13+
this.data.push(arr);
14+
}
15+
}
16+
17+
print() {
18+
console.table(this.data);
19+
}
20+
21+
getEnterLine()
22+
{
23+
24+
}
25+
26+
addInput(arr, column) {
27+
for (var i = 0; i < arr.length; i++)
28+
this.data[column][i] = arr[i];
29+
}
30+
31+
static generateSimplexFrame(matriz) {
32+
var frame = new Matriz(matriz.rows, (matriz.rows + matriz.cols) - 1);
33+
34+
// Adiciona os valores iniciais
35+
for (var i = 0; i < frame.rows; i++) {
36+
for (var j = 0; j < matriz.cols - 1; j++) {
37+
frame.data[i][j] = matriz.data[i][j];
38+
}
39+
}
40+
41+
// Adiciona as variáveis de folga
42+
for (var i = 0; i < frame.rows - 1; i++) {
43+
for (var j = matriz.cols - 1; j < frame.cols - 1; j++) {
44+
if (i == (j - (matriz.cols - 1))) {
45+
frame.data[i][j] = 1;
46+
}
47+
}
48+
}
49+
50+
// Adiciona as retrições
51+
for (var i = 0; i < matriz.rows - 1; i++)
52+
frame.data[i][frame.cols - 1] = matriz.data[i][matriz.cols - 1];
53+
54+
return frame;
55+
}
56+
}
57+
58+
//module.exports = Matriz;

maximizar.html

Lines changed: 33 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -20,12 +20,14 @@
2020
var restrictions = window.localStorage.getItem("restrictions");
2121
var iterations = window.localStorage.getItem("iterations");
2222

23+
var stepTo = document.querySelector('#passo');
24+
2325
var obj_function = document.querySelector('#fo');
2426

2527
var HTMLInputsVariables = "";
2628
for(var i = 0; i < variables; i++) {
2729
HTMLInputsVariables += "<div class='col-sm-2'>"
28-
+ "<input type='text' class='form-control' placeholder='X"+(i+1)+"'>" +
30+
+ "<input type='text' class='form-control' placeholder='X"+(i+1)+"' id='fo_x"+(i+1)+"'>" +
2931
"</div>";
3032

3133
if(i != variables-1) {
@@ -48,7 +50,7 @@
4850

4951
for(var j = 0; j < variables; j++) {
5052
res_variables += "<div class='col-sm-2'>"
51-
+ "<input type='text' class='form-control' placeholder='X"+(j+1)+"'>" +
53+
+ "<input type='text' class='form-control' placeholder='X"+(j+1)+"' id='f"+(i+1)+"_x"+(j+1)+"'>" +
5254
"</div>";
5355

5456
if(j != variables-1) {
@@ -59,14 +61,41 @@
5961
HTMLInputsRestrictions += res_variables;
6062
HTMLInputsRestrictions += "<p><=</p>"+
6163
"<div class='col-sm-2'>"+
62-
"<input type='text' class='form-control' placeholder='B'>"+
64+
"<input type='text' class='form-control' placeholder='B' id='f"+(i+1)+"_base'>"+
6365
"</div>";
6466
HTMLInputsRestrictions += "</div>";
6567

6668
}
6769

6870
res.innerHTML = HTMLInputsRestrictions;
6971

72+
stepTo.addEventListener("click", (event) => {
73+
74+
var data = {
75+
fo: []
76+
}
77+
78+
for(var i = 0; i < variables; i++) {
79+
data.fo.push( eval(document.querySelector('#fo_x'+(i+1)).value) )
80+
}
81+
82+
83+
for(var i = 0; i < restrictions; i++) {
84+
if(!data[`f${i+1}`]) data[`f${i+1}`] = []
85+
86+
for(var j = 0; j < variables; j++) {
87+
data[`f${i+1}`].push( eval(document.querySelector('#f'+(i+1)+'_x'+(j+1)).value) )
88+
}
89+
90+
data[`f${i+1}`].push( eval(document.querySelector('#f'+(i+1)+'_base').value) )
91+
}
92+
93+
window.localStorage.setItem("data", JSON.stringify(data));
94+
95+
96+
window.location.href = "tabela.html";
97+
});
98+
7099
});
71100

72101
</script>
@@ -94,37 +123,8 @@ <h6 style="text-align: left;">Função Objetivo:</h6>
94123
<h6 style="text-align: left;">Restrições:</h6>
95124

96125
<div id="res">
97-
98-
<!--div class="row">
99-
<div class="col-sm-2">
100-
<input type="text" class="form-control" placeholder="X1">
101-
</div>
102-
103-
<p>+</p>
104-
<div class="col-sm-2">
105-
<input type="text" class="form-control" placeholder="X2">
106-
</div>
107-
<p>
108-
<=</p>
109-
<div class="col-sm-2">
110-
<input type="text" class="form-control" placeholder="B">
111-
</div>
126+
<!--Conteudo gerado dinamicamente via JS-->
112127
</div>
113-
<div class="row">
114-
<div class="col-sm-2">
115-
<input type="text" class="form-control" placeholder="X1">
116-
</div>
117-
118-
<p>+</p>
119-
<div class="col-sm-2">
120-
<input type="text" class="form-control" placeholder="X2">
121-
</div>
122-
<p>
123-
<=</p>
124-
<div class="col-sm-2">
125-
<input type="text" class="form-control" placeholder="B">
126-
</div>
127-
</div-->
128128
</form>
129129

130130

tabela.html

Lines changed: 78 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -9,14 +9,89 @@
99
<link rel="stylesheet" href="node_modules/bootstrap/compiler/style.css">
1010
<link rel="stylesheet" href="node_modules/font-awesome/css/font-awesome.css">
1111
<link rel="stylesheet" type="text/css" href="css/estilo.css">
12+
<script src="./app/models/matriz-test.js"></script>
1213

14+
<script>
15+
window.addEventListener("load", function(event) {
16+
var variables = parseFloat(window.localStorage.getItem("variables"));
17+
var restrictions = parseFloat(window.localStorage.getItem("restrictions"));
18+
var iterations = parseFloat(window.localStorage.getItem("iterations"));
19+
20+
21+
//Implementacao da classe Matriz
22+
var data = window.localStorage.getItem("data");
23+
data = JSON.parse(data);
24+
console.log(data);
25+
26+
27+
var matriz = new Matriz(restrictions + 1, variables + 1);
28+
29+
30+
for (var i = 0; i < restrictions; i++)
31+
{
32+
matriz.addInput(data[`f${i+1}`], i);
33+
}
34+
35+
matriz.addInput(data.fo, restrictions);
36+
37+
var simplexFrame = Matriz.generateSimplexFrame(matriz);
38+
39+
console.log(simplexFrame)
40+
41+
var simplexTable = document.querySelector('#simplex');
42+
43+
var table = "";
44+
45+
for(var i = 0; i <= simplexFrame.rows; i++) {
46+
47+
if(i == 0) {
48+
table = "<thead><tr><th scope='col'>Base</th>";
49+
50+
//variaveis de decisao
51+
for(var j = 0; j < variables; j++) {
52+
table += "<th scope='col'>X"+(j+1)+"</th>";
53+
}
54+
55+
//variaveis de folga (restricoes)
56+
for(var j = 0; j < restrictions; j++) {
57+
table += "<th scope='col'>F"+(j+1)+"</th>";
58+
}
59+
60+
table += "</tr></thead><tbody>";
61+
}
62+
else if(i == simplexFrame.rows) {
63+
table += "<tr><th scope='row'>Z</th>";
64+
65+
for(var j = 0; j < simplexFrame.cols; j++) {
66+
table += "<td scope='col'>"+simplexFrame.data[i-1][j]+"</td>";
67+
}
68+
}
69+
else {
70+
table += "<tr><th scope='row'>F"+(i)+"</th>";
71+
72+
for(var j = 0; j < simplexFrame.cols; j++) {
73+
table += "<td scope='col'>"+simplexFrame.data[i-1][j]+"</td>";
74+
}
75+
}
76+
77+
}
78+
79+
simplexTable.innerHTML = table;
80+
81+
82+
83+
});
84+
85+
</script>
86+
87+
</head>
1388

1489
<body>
1590
<div class="wrapper fadeInDown">
1691
<div id="formContent">
1792
<div class="fadeIn first">
1893
<h5>SIMPLEX PO20</h5>
19-
<table class="table table-bordered">
94+
<table class="table table-bordered" id="simplex">
2095
<thead>
2196
<tr>
2297
<th scope="col">Base</th>
@@ -58,7 +133,7 @@ <h5>SIMPLEX PO20</h5>
58133

59134

60135

61-
<h5>Análise de Sensibilidade</h5>
136+
<!--h5>Análise de Sensibilidade</h5>
62137
<table class="table table-bordered">
63138
<thead>
64139
<tr>
@@ -108,7 +183,7 @@ <h5>Análise de Sensibilidade</h5>
108183
<td></td>
109184
</tr>
110185
</tbody>
111-
</table>
186+
</table-->
112187
</div>
113188

114189

@@ -120,19 +195,6 @@ <h5>Análise de Sensibilidade</h5>
120195
<script src="node_modules/jquery/dist/jquery.js"></script>
121196
<script src="node_modules/popper.js/dist/umd/popper.js"></script>
122197
<script src="node_modules/bootstrap/dist/js/bootstrap.js"></script>
123-
<script type="text/javascript">
124-
buttonAreaAdm.addEventListener('click', function() {
125-
const rotaUrl = inputAreaAdm.value;
126-
if (rotaUrl) {
127-
window.location = rotaUrl;
128-
}
129-
})
130-
</script>
131-
<html>
132-
133-
</body>
134-
135-
</html>
136198
</body>
137199

138200
</html>

0 commit comments

Comments
 (0)