Skip to content

Commit c728181

Browse files
committed
connected and functional with the second model
1 parent ddb09fb commit c728181

24 files changed

+253
-66
lines changed

back/Dockerfile

+51
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,51 @@
1+
FROM debian:stretch
2+
3+
RUN apt-get update &&\
4+
apt-get -y install \
5+
git \
6+
wget \
7+
libgl1 && \
8+
rm -rf /var/lib/apt/lists/* && \
9+
mkdir /tool && \
10+
cd /tool && \
11+
wget https://github.com/MiniZinc/MiniZincIDE/releases/download/2.3.1/MiniZincIDE-2.3.1-bundle-linux-x86_64.tgz && \
12+
tar -zxvf MiniZincIDE-2.3.1-bundle-linux-x86_64.tgz && \
13+
mv /tool/MiniZincIDE-2.3.1-bundle-linux /tool/MiniZincIDE && \
14+
rm -rf MiniZincIDE-2.3.1-bundle-linux-x86_64.tgz
15+
16+
RUN apt-get update &&\
17+
apt-get -y install\
18+
build-essential \
19+
zlib1g-dev \
20+
libncurses5-dev \
21+
libgdbm-dev \
22+
libnss3-dev \
23+
libssl-dev \
24+
libreadline-dev \
25+
libffi-dev && \
26+
wget https://www.python.org/ftp/python/3.7.3/Python-3.7.3.tar.xz && \
27+
tar -xf Python-3.7.3.tar.xz && \
28+
cd Python-3.7.3 && \
29+
./configure --enable-optimizations && \
30+
make -j 8 && \
31+
make altinstall && \
32+
python3.7 --version && \
33+
apt-get -y install python3-pip
34+
35+
RUN export LC_ALL=C && \
36+
pip3 install flask && \
37+
pip3 install -U flask-cors
38+
#export LC_ALL=C && \
39+
#export LANG=C
40+
41+
WORKDIR /code
42+
43+
COPY . .
44+
45+
RUN export FLASK_APP=api/__init__.py
46+
47+
ENV PATH "$PATH:/tool/MiniZincIDE/bin"
48+
ENV LD_LIBRARY_PATH "$LD_LIBRARY_PATH:/tool/MiniZincIDE/lib"
49+
50+
CMD ["python3","api.py"]
51+
#CMD ["flask","run","--host:0.0.0.0"]

back/api.py

+7-2
Original file line numberDiff line numberDiff line change
@@ -24,11 +24,16 @@ def upload_file():
2424
dznfile = request.files['dznfile']
2525
filename = secure_filename(dznfile.filename)
2626
dznfile.save(os.path.join(target, 'temp.dzn'))
27-
command = "/home/esmeralda/Desktop/MiniZincIDE-2.3.2-bundle-linux-x86_64/MiniZincIDE-2.3.2-bundle-linux/bin/minizinc --solver Gecode /home/esmeralda/Desktop/DesenfrenoPasiones/minizinc/DesenfrenoDePasiones.mzn " + os.path.join(target, 'temp.dzn') + '>' + os.path.join(target, 'output.txt')
27+
command = "minizinc --solver Gecode " + os.path.join(getcwd(),'minizinc', 'DesenfrenoDePasiones2.mzn') + " " + os.path.join(target, 'temp.dzn') + '>' + os.path.join(target, 'output.txt')
2828
result = subprocess.Popen(command, shell=True)
2929
f = open(os.path.join(target, 'output.txt'))
3030
result = f.read()
3131
return result
3232

33+
@app.route('/', methods=['GET'])
34+
35+
def hi():
36+
return "hello pyzinc"
37+
3338
if __name__ == '__main__':
34-
app.run(debug=True)
39+
app.run(debug=True, host='0.0.0.0', port=5000)
File renamed without changes.

back/ejemplos/Desenfreno2.dzn

+26
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
ACTORES = {Actor1, Actor2, Actor3, Actor4, Actor5, Actor6, Actor7, Actor8} ;
2+
3+
Escenas = [| 1, 1, 1, 1, 0, 1, 0, 1, 0, 1, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 10
4+
| 1, 1, 1, 0, 0, 0, 1, 1, 0, 1, 0, 0, 1, 1, 1, 0, 1, 0, 0, 1, 4
5+
| 0, 1, 1, 0, 1, 0, 1, 1, 0, 0, 0, 0, 1, 1, 1, 0, 0, 0, 0, 0, 5
6+
| 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 1, 1, 1, 0, 0, 0, 0, 0, 0, 0, 5
7+
| 0, 1, 0, 0, 0, 0, 1, 1, 0, 0, 0, 1, 0, 1, 0, 0, 0, 1, 1, 1, 5
8+
| 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 1, 1, 1, 1, 0, 0, 40
9+
| 0, 0, 0, 0, 1, 0, 1, 1, 0, 0, 0, 0, 0, 0, 1, 0, 0, 0, 0, 0, 4
10+
| 0, 0, 0, 0, 0, 1, 1, 1, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 20|];
11+
12+
Duracion = [2 , 1 , 1, 1, 1, 3, 1, 1, 1, 2, 1, 1, 2, 1, 2, 1, 1, 2, 1, 1];
13+
14+
Disponibilidad =[|Actor1, 0
15+
|Actor2, 0
16+
|Actor3, 23
17+
|Actor4, 0
18+
|Actor5, 80
19+
|Actor6, 10
20+
|Actor7, 5
21+
|Actor8, 100|];
22+
23+
Evitar =[|Actor1, Actor3
24+
|Actor1, Actor4
25+
|Actor2, Actor3
26+
|Actor2, Actor4|];
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.

back/ejemplos/Propia1-1.dzn

+11
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
ACTORES = {Actor1, Actor2, Actor3, Actor4, Actor5, Actor6, Actor7} ;
2+
3+
Escenas = [| 0,1,0,0,0,0,1,0,10
4+
| 0,1,1,1,0,1,1,1,20
5+
| 1,1,1,1,0,1,0,0,5
6+
| 0,1,1,1,0,0,1,1,5
7+
| 1,0,0,0,1,1,0,0,15
8+
| 1,0,0,0,1,0,1,1,10
9+
| 1,1,0,1,0,1,1,0,10|];
10+
11+
Duracion = [2,1,1,1,3,4,2,3];

back/ejemplos/Propia1-2.dzn

+9
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
ACTORES = {Actor1, Actor2, Actor3, Actor4, Actor5} ;
2+
3+
Escenas = [| 0,1,0,0,0,0,1,0,1,1,10
4+
| 0,1,1,1,0,1,1,1,0,1,20
5+
| 1,1,1,1,0,1,0,0,1,1,5
6+
| 0,1,1,1,0,0,1,1,0,1,5
7+
| 1,0,0,0,1,1,0,0,1,0,15|];
8+
9+
Duracion = [2,1,1,1,3,4,2,3,2,3];
File renamed without changes.
File renamed without changes.
+110
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,110 @@
1+
% Encabezado
2+
% Restricciones Naive Model
3+
% Jaime Cuartas Granada 1632664
4+
% Emily Esmeralda Carvajal Camelo 1630436
5+
% Desenfreno de Pasiones
6+
include "globals.mzn";
7+
enum ACTORES;
8+
array[ACTORES, int] of int: Escenas;
9+
int: nEscenas=length(row(Escenas,1))-1;
10+
array[1..nEscenas] of int: Duracion;
11+
%array[int,1..2] of int: Disponibilidad;
12+
%array[int,1..2] of ACTORES: Evitar;
13+
14+
% asserts
15+
16+
constraint assert(length(ACTORES) = length(col(Escenas,1)),
17+
"Cantidad invalida de escenas o actores, no coincide");
18+
constraint assert(length(row(Escenas,1))-1 = length(Duracion),
19+
"Cantidad invalida de escenas o duracion, no coincide");
20+
21+
constraint assert(forall(d in Duracion)(d > 0),
22+
"Valores de duracion invalidos");
23+
24+
constraint assert(forall(i in index_set(Duracion))
25+
(forall (j in col(Escenas,i))(j = 0 \/ j = 1)),
26+
"Algun valor es invalido en la matriz Escenas");
27+
28+
%faltan asserts de disponibilidad y evitar%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
29+
30+
% Dado un actor retorna el costo del actor por las escenas en que participa
31+
array[ACTORES] of int: Costo = [Escenas[x,nEscenas+1] | x in ACTORES];
32+
% Dado un actor retorna las escenas en que esta
33+
array[ACTORES] of set of int: EscenaDe = [{y | y in 1..nEscenas where Escenas[x,y]=1} | x in ACTORES];
34+
35+
% Variable
36+
array[1..nEscenas] of var 1..nEscenas: PosicionDeEscena;
37+
38+
% Suma los costos de cada actor por las escenas en que esta
39+
var int : costo = (sum(j in ACTORES)(
40+
let {
41+
var int: primera=min([PosicionDeEscena[e] | e in EscenaDe[j]]);
42+
var int: ultima=max([PosicionDeEscena[e] | e in EscenaDe[j]]);
43+
}
44+
in
45+
(sum(i in 1..nEscenas)
46+
(if PosicionDeEscena[i] >= primera
47+
/\
48+
PosicionDeEscena[i] <= ultima
49+
then Duracion[i]
50+
else 0
51+
endif)) * Costo[j]));
52+
53+
% Dado un actor suma los costos por las escenas en que esta
54+
array[ACTORES] of var int : TiempoDe = [(
55+
let {
56+
var int: primera = min([PosicionDeEscena[e] | e in EscenaDe[j]]);
57+
var int: ultima = max([PosicionDeEscena[e] | e in EscenaDe[j]]);
58+
}
59+
in
60+
(sum(i in 1..nEscenas)
61+
(if PosicionDeEscena[i] >= primera
62+
/\
63+
PosicionDeEscena[i] <= ultima
64+
then Duracion[i]
65+
else 0
66+
endif))) | j in ACTORES];
67+
68+
%Suma la duracion de las escenas en que dos actores que estan en la lista evitar se encuentran en el mismo momento en el set
69+
%var int: evitar = (sum(j in 1..length(col(Evitar,1)))(
70+
% let {
71+
% set of int: a = EscenaDe[row(Evitar,j)[1]];
72+
% set of int: b = EscenaDe[row(Evitar,j)[2]];
73+
% var int: primera = (if sum(a intersect b) != 0
74+
% then min([PosicionDeEscena[e] | e in a intersect b])
75+
% else 0
76+
% endif);
77+
% var int: ultima = (if primera != 0
78+
% then min([max([PosicionDeEscena[e] | e in a]),
79+
% max([PosicionDeEscena[e] | e in b])])
80+
% else -1
81+
% endif);
82+
% }
83+
% in
84+
% (sum(i in 1..nEscenas)
85+
% (if PosicionDeEscena[i] >= primera
86+
% /\
87+
% PosicionDeEscena[i] <= ultima
88+
% then Duracion[i]
89+
% else 0
90+
% endif))));
91+
92+
% Restricciones
93+
94+
constraint all_different(PosicionDeEscena);
95+
96+
%constraint forall(i in 1..length(col(Disponibilidad,1)))
97+
% (if row(Disponibilidad,i)[2] = 0
98+
% then TiempoDe[ACTORES[row(Disponibilidad,i)[1]]] > row(Disponibilidad,i)[2]
99+
% else TiempoDe[ACTORES[row(Disponibilidad,i)[1]]] <= row(Disponibilidad,i)[2]
100+
% endif);
101+
102+
103+
%solve satisfy;
104+
105+
solve minimize costo;
106+
107+
%salida
108+
109+
output ["[ "]++["\(p) " | p in arg_sort(PosicionDeEscena)]++["]"]++["Costo: \(costo) \n"];
110+
%output["Costo: \(costo) \n"];

minizinc/DesenfrenoDePasiones.mzn back/minizinc/DesenfrenoDePasiones2.mzn

+3-3
Original file line numberDiff line numberDiff line change
@@ -102,11 +102,11 @@ constraint forall(i in 1..length(col(Disponibilidad,1)))
102102

103103
%solve satisfy;
104104

105-
solve minimize costo;
105+
solve minimize 9*costo + evitar;
106106

107107
%salida
108108

109-
output["posicion(\(PosicionDeEscena[p])):\(p) " | p in 1..length(PosicionDeEscena)]++["\n"]
109+
output ["[ "]++["\(p) " | p in arg_sort(PosicionDeEscena)]++["]\n"]
110110
++["Tiempo compartido: \(evitar)"]++["\n"]
111111
++["Costo: \(costo) \n"];
112-
%output["Costo: \(costo) \n"];
112+
%output["Costo: \(costo) \n"];

back/upload/output.txt

+3-3
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
1-
posicion(8):1 posicion(3):2 posicion(6):3 posicion(4):4 posicion(9):5 posicion(7):6 posicion(2):7 posicion(1):8 posicion(5):9
2-
Tiempo compartido: 11
3-
Costo: 520
1+
[ 2 4 3 6 1 5 ]
2+
Tiempo compartido: 8
3+
Costo: 330
44
----------
55
==========

back/upload/temp.dzn

+20-20
Original file line numberDiff line numberDiff line change
@@ -1,29 +1,29 @@
1-
ACTORES = {Actor1, Actor2, Actor3, Actor4, Actor5} ;
1+
ACTORES = {Actor1, Actor2, Actor3, Actor4} ;
22

3-
Escenas = [| 0,1,0,0,0,0,1,0,0,10
4-
| 0,1,1,1,0,1,1,1,1,20
5-
| 1,1,1,1,0,1,0,0,1,5
6-
| 0,1,1,1,0,0,1,1,1,5
7-
| 1,0,0,0,1,1,0,0,0,15|];
3+
Escenas = [| 0,1,0,0,0,0,10
4+
| 0,1,1,1,0,1,20
5+
| 1,1,1,1,0,1,5
6+
| 1,0,0,0,1,1,15|];
87

9-
Duracion = [2,1,1,1,3,4,2,3,1];
8+
Duracion = [2,1,1,1,3,4];
109

11-
12-
Disponibilidad =[|Actor1, 13
13-
|Actor2, 14
14-
|Actor3, 15
15-
|Actor4, 14
16-
|Actor5, 10|];
10+
Disponibilidad =[|Actor1, 5
11+
|Actor2, 8
12+
|Actor3, 0
13+
|Actor4, 10|];
1714

1815
Evitar =[|Actor1, Actor2
19-
|Actor2, Actor3
20-
|Actor4, Actor5|];
16+
|Actor2, Actor3|];
2117

22-
%Ejecución con Gecode
18+
% Ejecución con Gecode
2319

24-
% Orden de las Escenas: [5, 1, 6, 9, 4, 3, 2, 7, 8]
25-
% Costo: 520
26-
% Tiempo Compartido: 11
20+
% Orden de las Escenas: [4, 3, 2, 6, 1, 5]
21+
% Costo: 330
22+
% Tiempo Compartido: 8
2723
% ----------
2824
% ==========
29-
% Finished in 31s 398msec
25+
% Finished in 260msec
26+
27+
28+
29+

docker-compose.yml

+10-2
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,20 @@
11
version: '3'
22

33
services:
4-
#frontreact
54
client:
65
container_name: react
76
build: ./front-minizinc
87
volumes:
98
- ./front-minizinc:/code
109
ports:
1110
- "8000:3000"
12-
tty: true
11+
depends_on:
12+
- server
13+
tty: true
14+
server:
15+
container_name: pyzinc
16+
build: ./back
17+
volumes:
18+
- ./back:/code
19+
ports:
20+
- "5000:5000"

front-minizinc/src/App.js

+3
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@ class App extends React.Component {
1212
super(props);
1313
this.state = {
1414
r: '',
15+
data: 'No hay informacion',
1516
dznfile: null,
1617
}
1718
this.dznfile = this.dznfile.bind(this);
@@ -21,6 +22,7 @@ class App extends React.Component {
2122
event.preventDefault();
2223
let file = event.target.files[0];
2324
this.setState({ 'dznfile' : file})
25+
2426
}
2527
execute = () => {
2628
const data = new FormData();
@@ -50,6 +52,7 @@ class App extends React.Component {
5052
<Card>
5153
<h5>Carga tu archivo de dzn</h5>
5254
<input name="dzn" type="file" onChange={this.dznfile} />
55+
<p>{this.state.data}</p>
5356
<Button onClick={this.execute} variant="primary">
5457
Enviar
5558
</Button>

minizinc/Actores.mzn

-36
This file was deleted.

0 commit comments

Comments
 (0)