Federico Amedeo Izzo 9 жил өмнө
parent
commit
769922f83a

+ 7 - 6
Data Bases 2/lesson_02.md

@@ -41,7 +41,7 @@ T2: UPDATE account
      WHERE client = 'Smith'  
 ```
 
-#### Execution with lost UPDATE
+#### Update Loss
 As the name states, one or more changes to the data are lost.  
 The error is produced by:
 - R1 R2 W1 W2
@@ -105,9 +105,9 @@ T1: C=AVG(B:A=1)
 T2: Insert (A=1,B=2)  
 T1: C=AVG(B: A=1)  
 ```
+## Concurrency Control
 
-### Schedule
-Sequence of input/output operations performed by concurrent transactions.
+__Schedule__: Sequence of input/output operations performed by concurrent transactions.
 es:  
 >S<sub>1</sub>: r<sub>1</sub>(x) r<sub>2</sub>(z) w<sub>1</sub>(x) w<sub>2</sub>  
 r<sub>1</sub>,w<sub>1</sub>
@@ -115,14 +115,15 @@ r<sub>1</sub>,w<sub>1</sub>
 $r_1,w_1\in T_1$
 $r_2,w_2\in T_2$
 
-#### Principles of Concurrent Control
+### Principles of Concurrency Control
 - __Goal__: to reject schedules that cause anomalies  
 - __Scheduler__: component that accepts or rejects the operations requested by the transactions  
 -  __Serial schedule__: the actions of each transaction occur in contiguous sequences
 - __Serializable schedule__: Produces the same results as some serial schedule on the same transactions (by *schedule equivalence*)
 - The class of acceptable schedules produced by a scheduler depends on the cost of equivalence checking, because scheduling must happen in real-time and the more is optimized my sheduling the more computational power I will need to obtain it.
-## CSR and VSR
-$CSR\subset VSR$
+### Concurrency Control techniques:
+- __Theoretical__: CSR and VSR, $CSR\subset VSR$
+- __Practical__: 2PL, 2PL Strict, TS Mono, TS Multi
 ### View-serializability
 ###### NOTE: what is a read-from operation?
 -  $r_i(x)$ *reads-from* $w_j(x)$ in a schedule S when $w_j(x)$ precedes $r_i(x)$ in S and there is no $w_k(x)$ between $r_i(x)$ and $w_j(x)$ in S

+ 17 - 0
OR_Lab/Lab-2/evacuation-i.mod

@@ -0,0 +1,17 @@
+# SETS
+
+set V;
+set T within V;
+set E within {V,V};
+set A within {V,V} :=
+   E union setof{(i,j) in E} (j,i);
+
+# PARAMS
+
+param s symbolic in T;
+param c{(i,j) in A} >= 0, default if (j,i) in E then c[j,i];
+param b{h in V} = 
+   (if h = s then card(T)-1
+    else if h in T then -1
+    else 0);
+

BIN
OR_Lab/Lab-2/evacuation-text.pdf


+ 35 - 0
OR_Lab/Lab-2/evacuation.dat

@@ -0,0 +1,35 @@
+data;
+
+set V := Duomo Cordusio SanBabila Missori Montenapoleone Cairoli Cadorna Lanza 
+	 S1 S2 S3 S4 S5 S6;
+
+set T := Duomo Cordusio SanBabila Missori Montenapoleone Cairoli Cadorna Lanza;
+
+param s := Duomo;
+
+param: E: c := 
+	Duomo Cordusio		0.2,
+	Duomo Missori	 	0.2,
+	Duomo S4		0.2,
+	Cordusio S2		0.2,
+	Cordusio S1		0.225,
+	Cordusio Cairoli	0.4,
+	Missori SanBabila	0.2125,
+	Missori S5		0.35,
+	S6 SanBabila		0.4,
+	S6 S5			0.35,
+	S6 Duomo		0.4,
+	SanBabila S5		0.225,
+	SanBabila Montenapoleone 0.6,
+	S5 S4	  		0.2,
+	S4 Montenapoleone	0.35,
+	S4 Cordusio		0.25,
+	Montenapoleone S3	0.25,
+	Montenapoleone Lanza	0.25,
+	S3 Cairoli     		0.05,
+	S3 Cordusio		0.15,
+	S2 S1			0.0875,
+	Lanza Cairoli		0.2,
+	Cairoli Cadorna		0.2,
+	S1 Cadorna		0.15
+;

+ 46 - 0
OR_Lab/Lab-2/lotsizing-i.mod

@@ -0,0 +1,46 @@
+# SETS
+
+set I;
+param n;
+set J := 1..n;
+
+# PARAMS
+
+param b{J}; #Work days
+param d{I,J}; #Max demand
+param r{I};   #Revenues
+param c{I};   #Cost
+param q{I};   #Max production
+param f{I};   
+param l{I};
+param m{I};   #Inventory cost
+param K;
+
+# VARIABLES
+
+var X{I,J} #Prod
+var V{I,J} #Sold
+var Z{I,J} #Store
+
+# OBJECTIVE FUNCTION
+
+mazimize Profit:
+	sum{i in I,j in J} V[i]*r[i]-(c[i]X[i,j] + m[i]*Z[i,j])
+	
+# CONSTRAINTS
+
+subject to MaxProdConstraint {j in J}:
+	sum {i in I} Z[i,j] <= K
+
+subject to MaxSellConstraint {i in I, j in J}:
+	V[i,j] <= d[i,j]
+
+subject to InventoryConstraint {i in I, j in J}:
+	Z[i,j]-Z[i,j-1]+X[i,j]-V[i,j]
+
+subject to InitialProduction {i in I}:
+	X[i,0] = 0
+
+subject to ConstantProduction {j in J}:
+	sum{i in I} x[i][j] {x[i][j]}/{q[i]} <= b[j]
+

BIN
OR_Lab/Lab-2/lotsizing-text.pdf


+ 26 - 0
OR_Lab/Lab-2/lotsizing.dat

@@ -0,0 +1,26 @@
+data;
+
+set I := A1 A2 A3;
+
+param n := 4;
+
+param b :=
+1	22
+2	20
+3	23
+4	22
+;
+
+param d:	1	2	3	4 :=
+	A1	5300	1200	7400	5300
+	A2	4500	5400	6500	7200
+	A3	4400	6700	12500	13200
+;
+
+param:  r	c	q	f	l	m :=
+A1	124	75	500	150000	20	3
+A2	109	53	450	150000	20	4
+A3	115	65	550	100000	16	2
+;
+
+param K := 800;

+ 13 - 0
OR_Lab/Lab-2/network-i.mod

@@ -0,0 +1,13 @@
+# SETS
+
+set V;                       
+set E within {V,V};
+set A within {V,V} :=
+   E union setof{(i,j) in E} (j,i);
+
+# PARAMS
+
+param s symbolic in V;
+param t symbolic in V;
+param k{(i,j) in A} >= 0, default if (j,i) in E then k[j,i];
+

BIN
OR_Lab/Lab-2/network-text.pdf


+ 38 - 0
OR_Lab/Lab-2/network.dat

@@ -0,0 +1,38 @@
+data;
+
+set V := a b c d e f g h i j k l m;
+
+param s := c;
+param t := f;
+
+param: E: k := 
+	a b 19
+	a c 7
+	a d 13
+	a e 2
+	a f 9
+	b c 14
+	b f 10
+	b g 18
+	b h 2
+	c d 11
+	c h 7
+	c i 15
+	c j 16
+	d e 17
+	d j 11
+	d k 16
+	e f 15
+	e k 8
+	e l 13
+	f g 12
+	f l 19
+	f m 4
+	g h 9
+	g m 5
+	h i 14
+	i j 3
+	j k 17
+	k l 20
+	l m 1
+;

+ 45 - 0
OR_Lab/lab_2.md

@@ -0,0 +1,45 @@
+## Lot sizing
+
+### Sets
+- $I$: Production $\{A_1,A_2,A_3\}$
+- $J$: Month {1,2,3,4}
+
+### Parameters
+
+- $b_J$ Work days $\forall j \in J$
+- $d_{i,j}$ Max Dem $\forall j \in J, \forall i \in I$
+- $r_i$ Revenues $\forall i \in I$
+- $c_i$ Cost $\forall i \in I$
+- $q_i$ Max Production Lev. $\forall j \in J$
+- $m_1$ Inv. $\forall i \in I$
+
+### Variables
+
+$X_{ij}$ Prod $i \in I, j \in J$
+$V_{ij}$ Sold $i \in I, j \in J$
+$Z_{ij}$ Store $i \in I, j \in J$
+
+### Objective
+$$max \sum_{I,J}{Vi*r_i-(c_iX_{ij}+m_iZ_{ij})}$$
+
+### Constraints
+Max production
+$$\sum_{I}{Z_{ij}\le K \forall j \in J}$$
+Sold cannot exceed produced
+$$V_{ij}\le d_{ij}  \forall i \in I, \forall j \in J $$
+Inventory balance
+$$Z_{ij}-Z_{ij-1}+X_{ij}-V_{ij} \forall i \in I, \forall j \in J$$
+Initial production
+$$X_{i0}=0 \forall i \in I $$
+
+$$\sum_I{\frac{x_{ij}}{q_i}}\le b_j \forall j \in J$$
+
+$$x_{ij} \le 0, Integer$$
+
+$$v_ij,z_ij\ge 0$$
+
+- To define the variable $Z$ we can use
+
+```
+VAR Z{I,J,UNION{0}}
+```

+ 79 - 0
SC_lab_1.md

@@ -0,0 +1,79 @@
+#### 9 November 2015
+# Soft Computing - Matlab lesson
+## Lake level problem
+
+The level of the water nees to be periodically rised and lowered to kill mosquito eggs.
+
+*Measuring* the __height of the water__
+
+Done by measuring the level against a wall,
+
+The level can vary in a range of -2, +2 meters, [m]
+
+### Membership functions
+
+We have to decide:
+- The minimum value
+- The maximum value
+- The shape of the function.
+
+Our three __labels__ will be
+- below
+- ze(ro)
+- above
+
+For the __below__ membership function we choose a *trapezoid* function
+
+For the __zero__ MF we choose a *triangular* function
+
+For the __above__ MF we choose a *trapezoid* function
+
+The two trapezoid functions have zero value in the center of the zero function.
+
+### Output functions
+
+__singletons__ aren't provided by matlab, instead we need to create a very narrow triangle.
+
+The output function is determined by 5 sigletons at each laber:
+- zero
+- few
+- half
+- lot
+- full
+
+### Rules
+
+We have to add rules as following:
+
+Height|Request|Output
+---|:---:|:---:
+below|zero|zero
+below|half|few
+below|max|few
+below|few|few
+below|lot|few
+zero|zero|zero
+zero|half|half
+zero|max|max
+zero|few|few
+zero|lot|lot
+zero|zero|few
+zero|half|lot
+zero|max|max
+zero|few|half
+zero|lot|max
+
+### Adding information
+
+If we have weather forecast available as another input  
+We can add another membership function.
+
+#### Additional Rules
+
+Rain|Output
+---|---
+Zero|Few
+Few|Few
+Half|Half
+A-Lot|A-Lot
+Max|Max