Sie sind auf Seite 1von 68

EJERCICIO 3.

Option Explicit

'Dim 'list of new variables

Dim Peso(1 To 5), Valor(1 To 5)

Sub Preliminary_Definitions()

Call fillarray(Peso, "{3,6,7,5}", 1)

Call fillarray(Valor, "{7,16,19,15}", 1)

End Sub

Sub Model_Structure()

NSV = 2

NCT = 2

End Sub

Sub Starting_State()

's1 = inicial value for variable s1

's2 = inicial value for variable s2

s1 = 1

s2 = 10

End Sub

Sub Decision_Set()

DS = "{0,1}"

End Sub

Sub Transition_Function()

'sn1 = transition equation for variable s1

'sn2 = transition equation for variable s2

sn1 = s1 + 1

sn2 = s2 - d * Peso(s1)
End Sub

Sub State_Constraints()

'Ct1 = constraint number 1

'Ct2 = constraint number 2

ct1 = (sn1 <= 5)

ct2 = (sn2 >= 0)

End Sub

Sub Economic_Return()

'ad(s) = definition of the economic return

ad(s) = d * Valor(s1)

End Sub

Sub Return_Function()

Rd(s) = ad(s) + f(sn)

End Sub

Sub Recursive_Equation()

f(s) = maxim(Rd(s))

End Sub

Sub Boundary_Conditions()

'p(s) = definition of the optimal policy in the boundary

'f(s) = definition of the optimal value function in the boundary

f(s) = 0

End Sub

Ejercicio 3.2

Option Explicit

'Dim 'list of new variables


Dim Peso(1 To 5), Valor(1 To 5), VOL(1 To 5)

Sub Preliminary_Definitions()

Call FILLARRAY(Peso, "{3,6,7,5}", 1)

Call FILLARRAY(Valor, "{7,16,19,15}", 1)

Call FILLARRAY(VOL, "{8,7,5,7}", 1)

End Sub

Sub Model_Structure()

NSV = 2

NCT = 2

End Sub

Sub Starting_State()

's1 = inicial value for variable s1

's2 = inicial value for variable s2

S1 = 1

s2 = 10

S3 = 13

End Sub

Sub Decision_Set()

DS = "{0,1}"

End Sub

Sub Transition_Function()

'sn1 = transition equation for variable s1

'sn2 = transition equation for variable s2

sn1 = S1 + 1

sn2 = s2 - D * Peso(S1)

SN3 = S3 - D * VOL(S1)
End Sub

Sub State_Constraints()

'Ct1 = constraint number 1

'Ct2 = constraint number 2

ct1 = (sn1 <= 5)

ct2 = (sn2 >= 0)

CT3 = (SN3 >= 0)

End Sub

Sub Economic_Return()

'ad(s) = definition of the economic return

ad(s) = D * Valor(S1)

End Sub

Sub Return_Function()

Rd(s) = ad(s) + f(sn)

End Sub

Sub Recursive_Equation()

f(s) = maxim(Rd(s))

End Sub

Sub Boundary_Conditions()

'p(s) = definition of the optimal policy in the boundary

'f(s) = definition of the optimal value function in the boundary

f(s) = 0

End Sub

EJERCICIO 3.3
EJERCICIO3.4

Option Explicit

'Dim 'list of new variables

Dim MEDICO(1 To 11), ENFERMERA(1 To 11), CM(1 To 11), CE(1 To 11)

Sub Preliminary_Definitions()

Call FILLARRAY(MEDICO, "{2,2,3,2,4,3,4,5,3,3}", 1)

Call FILLARRAY(ENFERMERA, "{4,6,6,5,10,6,7,10,8,6}", 1)

Call FILLARRAY(CM, "{4,5,5,4,6,7,5,3,8,5}", 1)

Call FILLARRAY(CE, "{2,3,2,2,3,3,2,2,3,2}", 1)

End Sub

Sub Model_Structure()

NSV = 3

NCT = 3

End Sub

Sub Starting_State()

S1 = 1

S2 = 20

S3 = 50

End Sub

Sub Decision_Set()

DS = "{0,1}"

End Sub

Sub Transition_Function()

Sn1 = S1 + 1
Sn2 = S2 - d * MEDICO(S1)

Sn3 = S3 - d * ENFERMERA(S1)

End Sub

Sub State_Constraints()

Ct1 = (Sn1 <= 11)

Ct2 = (Sn2 >= 0)

Ct3 = (Sn3 >= 0)

End Sub

Sub Economic_Return()

ad(S) = (MEDICO(S1) * CM(S1) + ENFERMERA(S1) * CE(S1)) * (1 - d)

End Sub

Sub Return_Function()

Rd(S) = ad(S) + F(sn)

End Sub

Sub Recursive_Equation()

F(S) = minim(Rd(S))

End Sub

Sub Boundary_Conditions()

F(S) = 0

End Sub

EJERCICIO 3.5
Option Explicit

'Dim 'list of new variables

Dim peso(1 To 7), a(1 To 7), b(1 To 7)

Sub Preliminary_Definitions()

Call fillarray(peso, "{5,3,4,5,6,8}", 1)

Call fillarray(a, "{900,700,800,1000,1400,950}", 1)

Call fillarray(b, "{800,900,700,1100,1300,1100}", 1)

End Sub

Sub Model_Structure()

NSV = 3

NCT = 3

End Sub

Sub Starting_State()
S1 = 1

s2 = 16

s3 = 18

End Sub

Sub Decision_Set()

DS = "{0,1}"

End Sub

Sub Transition_Function()

sn1 = S1 + 1

sn2 = s2 - peso(S1) * d

sn3 = s3 - peso(S1) * (1 - d)

End Sub

Sub State_Constraints()

Ct1 = (sn1 <= 7)

Ct2 = (sn2 >= 0)

Ct3 = (sn2 >= 0)

End Sub

Sub Economic_Return()

If sn1 >= 1 And sn1 <= 6 Then

ad(S) = a(S1) * peso(S1) * d + b(S1) * peso(S1) * (1 - d)

ElseIf sn1 = 6 Then

ad(S) = a(S1) * peso(S1) * d + b(S1) * peso(S1) * (1 - d) - 5000 * sn2 - 10000 * sn3

End If
End Sub

Sub Return_Function()

Rd(S) = ad(S) + f(sn)

End Sub

Sub Recursive_Equation()

f(S) = maxim(Rd(S))

End Sub

Sub Boundary_Conditions()

f(S) = 0

End Sub
Option Explicit

'Dim 'list of new variables

Dim cal(1 To 5), prot(1 To 5)

Sub Preliminary_Definitions()

Call fillarray(cal, "{300,500,600,400}", 1)

Call fillarray(prot, "{400,700,900,300}", 1)

End Sub
Sub Model_Structure()

NSV = 2

NCT = 2

End Sub

Sub Starting_State()

s1 = 1

s2 = 1500

End Sub

Sub Decision_Set()

If s1 = 2 Then

ds = ivalset(1, 2)

Else

ds = ivalset(0, 2)

End If

End Sub

Sub Transition_Function()

sn1 = s1 + 1

sn2 = sn2 - cal(s1) * d

End Sub

Sub State_Constraints()

Ct1 = (sn1 <= 5)

Ct2 = (sn2 >= 0)

End Sub

Sub Economic_Return()
ad(s) = prot(s1) * d

End Sub

Sub Return_Function()

Rd(s) = ad(s) + f(sn)

End Sub

Sub Recursive_Equation()

f(s) = maxim(Rd(s))

End Sub

Sub Boundary_Conditions()

f(s) = 0

End Sub

EJERCICIO 3.6

Option Explicit

'Dim 'list of new variables

Dim CF(1 To 7), CVU(1 To 7), P(1 To 7)


Sub Preliminary_Definitions()

Call FILLARRAY(CF, "{3,3,4,4,5,4}", 1)

Call FILLARRAY(CVU, "{5,9,10,11,9,11}", 1)

Call FILLARRAY(P, "{7,12,15,17,16,17}", 1)

End Sub

Sub Model_Structure()

NSV = 2

NCT = 2

End Sub

Sub Starting_State()

's1 = inicial value for variable s1

's2 = inicial value for variable s2

S1 = 1

S2 = 90

End Sub

Sub Decision_Set()

If S1 = 1 Then

DS = IVALSET(0, 3)

ElseIf S1 = 2 Then

DS = IVALSET(2, 6)

ElseIf S1 = 3 Then

DS = IVALSET(0, 5)

ElseIf S1 = 4 Then

DS = IVALSET(1, 9)

ElseIf S1 = 5 Then

DS = IVALSET(1, 7)
ElseIf S1 = 6 Then

DS = IVALSET(0, 8)

End If

End Sub

Sub Transition_Function()

'sn1 = transition equation for variable s1

SN1 = S1 + 1

SN2 = S2 - CF(S1) - CVU(S1) * D

'sn2 = transition equation for variable s2

End Sub

Sub State_Constraints()

'Ct1 = constraint number 1

'Ct2 = constraint number 2

CT1 = (SN1 <= 7)

CT2 = (SN2 >= 0)

End Sub

Sub Economic_Return()

'ad(s) = definition of the economic return

If D > 0 Then

AD(S) = P(S1) * D - CF(S1) - CVU(S1) * D

Else

AD(S) = 0

End If

End Sub
Sub Return_Function()

Rd(S) = AD(S) + F(sn)

End Sub

Sub Recursive_Equation()

F(S) = maxim(Rd(S))

End Sub

Sub Boundary_Conditions()

'p(s) = definition of the optimal policy in the boundary

'f(s) = definition of the optimal value function in the boundary

F(S) = 0

End Sub

Option Explicit

'Dim 'list of new variables

Dim tp(1 To 6), cf(1 To 6), cvu(1 To 6)

Sub Preliminary_Definitions()

Call fillarray(tp, "{10000,8000,9000,7000,6000}", 1)

Call fillarray(cf, "{4000,3000,3500,2500,2000}", 1)

Call fillarray(cvu, "{1200,1000,1100,1000,900}", 1)

End Sub

Sub Model_Structure()

NSV = 2

NCT = 2

End Sub
Sub Starting_State()

's1 = inicial value for variable s1

's2 = inicial value for variable s2

s1 = 1

s2 = 0

End Sub

Sub Decision_Set()

ds = ivalset(0, 8)

End Sub

Sub Transition_Function()

'sn1 = transition equation for variable s1

sn1 = s1 + 1

sn2 = s2 + tp(s1) * d

'sn2 = transition equation for variable s2

End Sub

Sub State_Constraints()

'Ct1 = constraint number 1

'Ct2 = constraint number 2

ct1 = (sn1 <= 6)

ct2 = (sn2 >= 0)

End Sub

Sub Economic_Return()

'ad(s) = definition of the economic return

If d > 0 Then

ad(s) = cf(s1) + cvu(s1) * d

Else

ad(s) = 0
End If

End Sub

Sub Return_Function()

Rd(s) = ad(s) + f(sn)

End Sub

Sub Recursive_Equation()

f(s) = minim(Rd(s))

End Sub

Sub Boundary_Conditions()

'p(s) = definition of the optimal policy in the boundary

'f(s) = definition of the optimal value function in the boundary

If sn2 >= 100000 Then

f(s) = 0

Else

f(s) = bigm

End If

End Sub
EJERCICIO 3.7

Option Explicit

'Dim 'list of new variables

Dim tp(1 To 6), cf(1 To 6), cvu(1 To 6)

Sub Preliminary_Definitions()

Call fillarray(tp, "{10000,8000,9000,7000,6000}", 1)

Call fillarray(cf, "{4000,3000,3500,2500,2000}", 1)

Call fillarray(cvu, "{1200,1000,1100,1000,900}", 1)

End Sub

Sub Model_Structure()

NSV = 2

NCT = 2

End Sub

Sub Starting_State()
's1 = inicial value for variable s1

's2 = inicial value for variable s2

S1 = 1

s2 = 0

End Sub

Sub Decision_Set()

ds = ivalset(0, 8)

End Sub

Sub Transition_Function()

'sn1 = transition equation for variable s1

sn1 = S1 + 1

sn2 = s2 + tp(S1) * d

'sn2 = transition equation for variable s2

End Sub

Sub State_Constraints()

'Ct1 = constraint number 1

'Ct2 = constraint number 2

ct1 = (sn1 <= 6)

ct2 = (sn2 >= 0)

End Sub

Sub Economic_Return()

'ad(s) = definition of the economic return

If d > 0 Then

ad(s) = cf(S1) + cvu(S1) * d

Else

ad(s) = cvu(S1) * d
End If

End Sub

Sub Return_Function()

Rd(s) = ad(s) + f(sn)

End Sub

Sub Recursive_Equation()

f(s) = minim(Rd(s))

End Sub

Sub Boundary_Conditions()

'p(s) = definition of the optimal policy in the boundary

'f(s) = definition of the optimal value function in the boundary

If s2 >= 100000 Then

f(s) = 0

Else

f(s) = bigm

End If

End Sub

EJERCICIO 3.7B
Option Explicit

'Dim 'list of new variables

Dim tp(1 To 6), cf(1 To 6), cvu(1 To 6)

Sub Preliminary_Definitions()

Call fillarray(tp, "{10000,8000,9000,7000,6000}", 1)

Call fillarray(cf, "{4000,3000,3500,2500,2000}", 1)

Call fillarray(cvu, "{1200,1000,1100,1000,900}", 1)

End Sub

Sub Model_Structure()

NSV = 2

NCT = 2

End Sub

Sub Starting_State()

's1 = inicial value for variable s1

's2 = inicial value for variable s2

S1 = 1
s2 = 0

End Sub

Sub Decision_Set()

If S1 = 1 Then

DS = IVALSET(2, 6, 2)

ElseIf S1 = 2 Then

DS = IVALSET(1, 6, 1)

ElseIf S1 = 3 Then

DS = IVALSET(1, 6, 3)

ElseIf S1 = 4 Then

DS = IVALSET(1, 5, 1)

ElseIf S1 = 5 Then

DS = IVALSET(2, 6, 2)

End If

End Sub

Sub Transition_Function()

'sn1 = transition equation for variable s1

sn1 = S1 + 1

sn2 = s2 + tp(S1) * d

'sn2 = transition equation for variable s2

End Sub

Sub State_Constraints()

'Ct1 = constraint number 1

'Ct2 = constraint number 2

ct1 = (sn1 <= 6)

ct2 = (sn2 >= 0)

End Sub
Sub Economic_Return()

'ad(s) = definition of the economic return

If d > 0 Then

ad(s) = cf(S1) + cvu(S1) * d

Else

ad(s) = cvu(S1) * d

End If

End Sub

Sub Return_Function()

Rd(s) = ad(s) + f(sn)

End Sub

Sub Recursive_Equation()

f(s) = minim(Rd(s))

End Sub

Sub Boundary_Conditions()

'p(s) = definition of the optimal policy in the boundary

'f(s) = definition of the optimal value function in the boundary

If s2 >= 100000 Then

f(s) = 0

Else

f(s) = bigm

End If

End Sub
Option Explicit

'Dim 'list of new variables

Dim PEDIDO(1 To 7), PI(1 To 7), PC(1 To 7)

Sub Preliminary_Definitions()

Call FILLARRAY(PEDIDO, "{100,150,200,180,200,100}", 1)

Call FILLARRAY(PI, "{200,180,190,200,180,200}", 1)

Call FILLARRAY(PC, "{80,90,75,85,90,90}", 1)

End Sub

Sub Model_Structure()

NSV = 2

NCT = 2

End Sub

Sub Starting_State()

's1 = inicial value for variable s1

's2 = inicial value for variable s2

S1 = 1

s2 = 120
End Sub

Sub Decision_Set()

DS = "{0,1}"

End Sub

Sub Transition_Function()

'sn1 = transition equation for variable s1

'sn2 = transition equation for variable s2

SN1 = SN1 + 1

SN2 = s2 + 80 * d

End Sub

Sub State_Constraints()

'Ct1 = constraint number 1

'Ct2 = constraint number 2

CT1 = (SN1 <= 7)

CT2 = (SN2 >= 0)

End Sub

Sub Economic_Return()

'ad(s) = definition of the economic return

If PEDIDO(S1) > SN2 Then

AD(s) = PI(S1) * (PEDIDO(S1) - SN2)

ElseIf PEDIDO(S1) < SN2 Then

AD(s) = PC(S1) * (SN2 - PEDIDO(S1))

End If

End Sub

Sub Return_Function()
Rd(s) = AD(s) + F(sn)

End Sub

Sub Recursive_Equation()

F(s) = minim(Rd(s))

End Sub

Sub Boundary_Conditions()

'p(s) = definition of the optimal policy in the boundary

'f(s) = definition of the optimal value function in the boundary

If s2 > 120 And s2 <= 200 Then

F(s) = 0

Else

F(s) = bigm

End If

End Sub

Sub Return_Function()

Rd(s) = AD(s) + F(sn)

End Sub

Sub Recursive_Equation()

F(s) = minim(Rd(s))

End Sub

Sub Boundary_Conditions()

'p(s) = definition of the optimal policy in the boundary

'f(s) = definition of the optimal value function in the boundary

If s2 > 120 And s2 <= 200 Then

F(s) = 0
Else

F(s) = bigm

End If

End Sub

EJERCICIO 3.8

Option Explicit

'Dim 'list of new variables

Dim pedido(1 To 7), PI(1 To 7), PC(1 To 7)

Sub Preliminary_Definitions()

Call FILLARRAY(pedido, "{100,150,200,180,200,100}", 1)

Call FILLARRAY(PI, "{200,180,190,200,180,200}", 1)

Call FILLARRAY(PC, "{80,90,75,85,90,90}", 1)

End Sub

Sub Model_Structure()

NSV = 2

NCT = 2
End Sub

Sub Starting_State()

's1 = inicial value for variable s1

's2 = inicial value for variable s2

S1 = 1

S2 = 120

End Sub

Sub Decision_Set()

DS = "{0,1}"

End Sub

Sub Transition_Function()

'sn1 = transition equation for variable s1

'sn2 = transition equation for variable s2

SN1 = S1 + 1

Sn2 = S2 + 80 * D

End Sub

Sub State_Constraints()

'Ct1 = constraint number 1

'Ct2 = constraint number 2

CT1 = (SN1 <= 7)

CT2 = (Sn2 >= 0)

End Sub

Sub Economic_Return()

If pedido(S1) > Sn2 Then

AD(s) = PI(S1) * (pedido(S1) - Sn2)


Else

AD(s) = PC(S1) * (Sn2 - pedido(S1))

End If

'ad(s) = definition of the economic return

End Sub

Sub Return_Function()

Rd(s) = AD(s) + F(sn)

End Sub

Sub Recursive_Equation()

F(s) = minim(Rd(s))

End Sub

Sub Boundary_Conditions()

'p(s) = definition of the optimal policy in the boundary

'f(s) = definition of the optimal value function in the boundary

If S2 <= 200 Then

F(s) = 0

Else

F(s) = BIGM

End If

End Sub
3.9 EJERCICIO
Option Explicit

'Dim 'list of new variables

Dim honorario(1 To 4, 0 To 5)

Sub Preliminary_Definitions()

Call fillarray(honorario,
"{{0,100,250,400,525,600},{0,125,250,375,500,625},{0,150,300,400,550,650}}", 1, 0)

End Sub

Sub Model_Structure()

NSV = 2

NCT = 2

End Sub

Sub Starting_State()

's1 = inicial value for variable s1

's2 = inicial value for variable s2

s1 = 1

s2 = 6
End Sub

Sub Decision_Set()

DS = ivalset(0, 5)

End Sub

Sub Transition_Function()

'sn1 = transition equation for variable s1

'sn2 = transition equation for variable s2

sn1 = s1 + 1

sn2 = s2 - d

End Sub

Sub State_Constraints()

'Ct1 = constraint number 1

'Ct2 = constraint number 2

ct1 = (sn1 <= 4)

ct2 = (sn2 >= 0)

End Sub

Sub Economic_Return()

'ad(s) = definition of the economic return

ad(S) = honorario(s1, d)

End Sub

Sub Return_Function()

Rd(S) = ad(S) + f(sn)

End Sub

Sub Recursive_Equation()

f(S) = maxim(Rd(S))
End Sub

Sub Boundary_Conditions()

'p(s) = definition of the optimal policy in the boundary

'f(s) = definition of the optimal value function in the boundary

f(S) = 0

End Sub

3.9 EJERCICIO
Option Explicit

'Dim 'list of new variables

Dim honorario(1 To 4, 0 To 5)

Sub Preliminary_Definitions()

Call fillarray(honorario,
"{{0,100,250,400,525,600},{0,125,250,375,500,625},{0,150,300,400,550,650}}", 1, 0)

End Sub

Sub Model_Structure()

NSV = 2

NCT = 2

End Sub

Sub Starting_State()

's1 = inicial value for variable s1

's2 = inicial value for variable s2

s1 = 1

s2 = 6
End Sub

Sub Decision_Set()

DS = ivalset(0, 5)

End Sub

Sub Transition_Function()

'sn1 = transition equation for variable s1

'sn2 = transition equation for variable s2

sn1 = s1 + 1

sn2 = s2 - d

End Sub

Sub State_Constraints()

'Ct1 = constraint number 1

'Ct2 = constraint number 2

ct1 = (sn1 <= 4)

ct2 = (sn2 >= 0)

End Sub

Sub Economic_Return()

'ad(s) = definition of the economic return

ad(S) = honorario(s1, d)

End Sub

Sub Return_Function()

Rd(S) = ad(S) + f(sn)

End Sub

Sub Recursive_Equation()

f(S) = maxim(Rd(S))
End Sub

Sub Boundary_Conditions()

'p(s) = definition of the optimal policy in the boundary

'f(s) = definition of the optimal value function in the boundary

f(S) = 0

End Sub

3.10 EJERCICIO
Option Explicit

'Dim 'list of new variables

Dim a(1 To 4), mp(1 To 4), u(1 To 4, 1 To 6)

Sub Preliminary_Definitions()

Call fillarray(a, "{3,3,4}", 1)

Call fillarray(mp, "{4,5,4}", 1)

Call fillarray(u, "{{3,4.5,6.5,9,11},{3,5,7,9,13},{2.5,4,6,8,11}}", 1, 1)

End Sub

Sub Model_Structure()

NSV = 3

NCT = 3

End Sub

Sub Starting_State()

's1 = inicial value for variable s1


's2 = inicial value for variable s2

s1 = 1

s2 = 14

s3 = 20

End Sub

Sub Decision_Set()

DS = ivalset(1, 5)

End Sub

Sub Transition_Function()

'sn1 = transition equation for variable s1

'sn2 = transition equation for variable s2

sn1 = s1 + 1

sn2 = s2 - a(s1) * d

sn3 = s3 - mp(s1) * d

End Sub

Sub State_Constraints()

'Ct1 = constraint number 1

'Ct2 = constraint number 2

ct1 = (sn1 <= 4)

ct2 = (sn2 >= 0)

ct3 = (sn3 >= 0)

End Sub

Sub Economic_Return()

'ad(s) = definition of the economic return

ad(S) = u(s1, d)

End Sub
Sub Return_Function()

Rd(S) = ad(S) + f(sn)

End Sub

Sub Recursive_Equation()

f(S) = maxim(Rd(S))

End Sub

Sub Boundary_Conditions()

'p(s) = definition of the optimal policy in the boundary

'f(s) = definition of the optimal value function in the boundary

f(S) = 0

End Sub

3.11 EJERCICIO

Option Explicit

'Dim 'list of new variables

Dim C(1 To 6, 0 To 3)

Sub Preliminary_Definitions()

Call FILLARRAY(C, "{{5,9,16,21},{4,7,14,20},{2,5,11,15},{2,5,8,14},{3,4,8,13}}", 1, 0)


End Sub

Sub Model_Structure()

NSV = 2

NCT = 2

End Sub

Sub Starting_State()

's1 = inicial value for variable s1

's2 = inicial value for variable s2

S1 = 1

s2 = 0

End Sub

Sub Decision_Set()

DS = IVAlSET(0, 3)

End Sub

Sub Transition_Function()

'sn1 = transition equation for variable s1

'sn2 = transition equation for variable s2

SN1 = 1 + S1

SN2 = s2 + D

End Sub

Sub State_Constraints()

'Ct1 = constraint number 1

'Ct2 = constraint number 2

CT1 = (SN1 <= 6)


CT2 = (SN2 >= 0)

End Sub

Sub Economic_Return()

'ad(s) = definition of the economic return

AD(s) = C(S1, D)

End Sub

Sub Return_Function()

Rd(s) = AD(s) + f(sn)

End Sub

Sub Recursive_Equation()

f(s) = minim(Rd(s))

End Sub

Sub Boundary_Conditions()

'p(s) = definition of the optimal policy in the boundary

'f(s) = definition of the optimal value function in the boundary

If s2 = 12 Then

f(s) = 0

Else

f(s) = bigm

End If

End Sub
3.12 EJERCICIO
Option Explicit

'Dim 'list of new variables

Dim dem(1 To 5), cpn(1 To 5), cpe(1 To 5)

Sub Preliminary_Definitions()

Call fillarray(dem, "{900,800,1000,1200}", 1)

Call fillarray(cpe, "{3.5,5,2.5,7}", 1)

Call fillarray(cpn, "{3,4,2,5}", 1)

End Sub

Sub Model_Structure()

NSV = 2

NCT = 2

End Sub

Sub Starting_State()

's1 = inicial value for variable s1

's2 = inicial value for variable s2

S1 = 1
s2 = 0

End Sub

Sub Decision_Set()

DS = ivalset(0, 1100, 100)

End Sub

Sub Transition_Function()

'sn1 = transition equation for variable s1

'sn2 = transition equation for variable s2

sn1 = S1 + 1

sn2 = s2 + d - dem(S1)

End Sub

Sub State_Constraints()

'Ct1 = constraint number 1

'Ct2 = constraint number 2

ct1 = (sn1 <= 5)

ct2 = (sn2 >= 0 And sn2 <= 300)

End Sub

Sub Economic_Return()

'ad(s) = definition of the economic return

If d <= 900 Then

ad(S) = cpn(S1) * d + s2

Else

ad(S) = cpn(S1) * 900 + cpe(S1) * (d - 900) + s2

End If

End Sub

Sub Return_Function()
Rd(S) = ad(S) + f(sn)

End Sub

Sub Recursive_Equation()

f(S) = minim(Rd(S))

End Sub

Sub Boundary_Conditions()

'p(s) = definition of the optimal policy in the boundary

'f(s) = definition of the optimal value function in the boundary

If s2 >= 100 Then

f(S) = 0

Else

f(S) = bigm

End If

End Sub

3.13

Option Explicit

'Dim 'list of new variables

Dim dem(1 To 5), cpn(1 To 5), cpe(1 To 5)

Sub Preliminary_Definitions()

Call fillarray(dem, "{900,800,1000,1200}", 1)

Call fillarray(cpe, "{3.5,5,2.5,7}", 1)

Call fillarray(cpn, "{3,4,2,5}", 1)

End Sub

Sub Model_Structure()

NSV = 2
NCT = 2

End Sub

Sub Starting_State()

's1 = inicial value for variable s1

's2 = inicial value for variable s2

s1 = 1

s2 = 0

End Sub

Sub Decision_Set()

DS = ivalset(0, 1100, 100)

End Sub

Sub Transition_Function()

'sn1 = transition equation for variable s1

'sn2 = transition equation for variable s2

sn1 = s1 + 1

sn2 = s2 + d - dem(s1)

End Sub

Sub State_Constraints()

'Ct1 = constraint number 1

'Ct2 = constraint number 2

ct1 = (sn1 <= 5)

ct2 = (sn2 >= 0 And sn2 <= 300)

End Sub

Sub Economic_Return()

'ad(s) = definition of the economic return

If dem(s1) > d + sn2 And d > 900 Then


ad(S) = cpe(s1) * d + sn2 + 1.2 * (dem(s1) - sn2 - d)

ElseIf dem(s1) <= d + sn2 And d > 900 Then

ad(S) = cpe(s1) * d + sn2

ElseIf dem(s1) >= sn2 + d And d <= 900 Then

ad(S) = cpn(s1) + sn2 + 1.2 * (dem(s1) - d - sn2)

ElseIf dem(s1) <= sn2 + d And d <= 900 Then

ad(S) = cpn(s1) + sn2

End If

End Sub

Sub Return_Function()

Rd(S) = ad(S) + f(sn)

End Sub

Sub Recursive_Equation()

f(S) = minim(Rd(S))

End Sub

Sub Boundary_Conditions()

'p(s) = definition of the optimal policy in the boundary

'f(s) = definition of the optimal value function in the boundary

If s2 = dem(s1) Then

f(S) = 0

Else

f(S) = bigm

End If

End Sub
3.14
Option Explicit

'Dim 'list of new variables

Dim costoq(1 To 7), costom(1 To 7), dem(1 To 7)

Sub Preliminary_Definitions()

Call fillarray(costoq, "{10.2,10.3,11,11.8,11.3,11.9}", 1)

Call fillarray(costom, "{9.5,9.6,10.2,11,10.7,11.3}", 1)

Call fillarray(dem, "{500,480,460,490,460,490}", 1)

End Sub

Sub Model_Structure()

NSV = 3

NCT = 3

End Sub

Sub Starting_State()

's1 = inicial value for variable s1

's2 = inicial value for variable s2


s1 = 1

s2 = 800

s3 = 2500

End Sub

Sub Decision_Set()

DS = ivalset(0, 1000, 500)

End Sub

Sub Transition_Function()

'sn1 = transition equation for variable s1

'sn2 = transition equation for variable s2

sn1 = s1 + 1

sn2 = s2 + d - dem(s1)

sn3 = s3 - d * (0.8)

End Sub

Sub State_Constraints()

'Ct1 = constraint number 1

'Ct2 = constraint number 2

ct1 = (sn1 <= 7)

ct2 = (sn2 >= 0 And sn2 <= 1000)

ct3 = (sn3 >= 0)

End Sub

Sub Economic_Return()

'ad(s) = definition of the economic return

If d = 0 Then

ad(S) = 0 + 0.2 * s2

ElseIf d = 500 Then

ad(S) = d * costoq(s1) + 0.2 * s2


Else

ad(S) = d * costom(s1) + 0.2 * s2

End If

End Sub

Sub Return_Function()

Rd(S) = ad(S) + f(sn)

End Sub

Sub Recursive_Equation()

f(S) = minim(Rd(S))

End Sub

Sub Boundary_Conditions()

'p(s) = definition of the optimal policy in the boundary

'f(s) = definition of the optimal value function in the boundary

If s2 >= 500 Then

f(S) = 0

Else

f(S) = bigm

End If

End Sub

3.15
Option Explicit

'Dim 'list of new variables

Dim q(1 To 11), cp(1 To 11)

Sub Preliminary_Definitions()

Call fillarray(q, "{140,180,180,200,120,180,100,100,120,100}", 1)

Call fillarray(cp, "{5.2,5,5.7,5.9,5.1,5.6,5.8,5.8,5.4,6}", 1)

End Sub
Sub Model_Structure()

NSV = 3

NCT = 3

End Sub

Sub Starting_State()

's1 = inicial value for variable s1

's2 = inicial value for variable s2

S1 = 1

s2 = 50

s3 = 0

End Sub

Sub Decision_Set()

DS = ivalset(0, 300, 60)

End Sub

Sub Transition_Function()

'sn1 = transition equation for variable s1

'sn2 = transition equation for variable s2

sn1 = S1 + 1

sn2 = s2 + d - q(S1)

If d = 0 Then

sn3 = s3 + 1

Else

sn3 = s3

End If

End Sub

Sub State_Constraints()
'Ct1 = constraint number 1

'Ct2 = constraint number 2

ct1 = (sn1 <= 11)

ct2 = (sn2 >= 0 And sn2 <= 150)

ct3 = (sn3 >= 0 And sn3 <= 3)

End Sub

Sub Economic_Return()

'ad(s) = definition of the economic return

ad(s) = cp(S1) * d + 0.5 * s2

End Sub

Sub Return_Function()

Rd(s) = ad(s) + f(sn)

End Sub

Sub Recursive_Equation()

f(s) = minim(Rd(s))

End Sub

Sub Boundary_Conditions()

'p(s) = definition of the optimal policy in the boundary

'f(s) = definition of the optimal value function in the boundary

If s3 = 3 Then

f(s) = 0

Else

f(s) = bigm

End If
End Sub

Option Explicit

'Dim 'list of new variables

Dim distancia(1 To 5, 1 To 5)

Sub Preliminary_Definitions()

Call fillarray(distancia,
"{{0,1030,1250,570},{1030,0,530,1520},{1250,530,0,1440},{570,1520,1440,0}}", 1, 1)

End Sub
Sub Model_Structure()

NSV = 2

NCT = 2

End Sub

Sub Starting_State()

's1 = inicial value for variable s1

's2 = inicial value for variable s2

s1 = 1

s2 = "{2,3,4}"

End Sub

Sub Decision_Set()

DS = s2

End Sub

Sub Transition_Function()

'sn1 = transition equation for variable s1

'sn2 = transition equation for variable s2

sn1 = d

sn2 = remelem(s2, d)

End Sub

Sub State_Constraints()

'Ct1 = constraint number 1

'Ct2 = constraint number 2

ct1 = (sn1 <= 5)

ct2 = (sn2 >= 0)

End Sub
Sub Economic_Return()

'ad(s) = definition of the economic return

ad(S) = distancia(s1, d)

End Sub

Sub Return_Function()

Rd(S) = ad(S) + f(sn)

End Sub

Sub Recursive_Equation()

f(S) = minim(Rd(S))

End Sub

Sub Boundary_Conditions()

'p(s) = definition of the optimal policy in the boundary

'f(s) = definition of the optimal value function in the boundary

f(S) = distancia(s1, 1)

End Sub

3.17 EJERCCIO
Option Explicit

'Dim 'list of new variables

Dim m(1 To 5, 1 To 5)

Sub Preliminary_Definitions()

Call FILLARRAY(m, "{{120,110,105,115},{90,95,90,85},{150,140,130,120},{95,110,130,105}}", 1,


1)
End Sub

Sub Model_Structure()

NSV = 2

NCT = 2

End Sub

Sub Starting_State()

's1 = inicial value for variable s1

's2 = inicial value for variable s2

S1 = 1

S2 = "{1,2,3,4}"

End Sub

Sub Decision_Set()

DS = S2

End Sub

Sub Transition_Function()

'sn1 = transition equation for variable s1

'sn2 = transition equation for variable s2

SN1 = S1 + 1

SN2 = REMELEM(S2, D)

End Sub

Sub State_Constraints()

'Ct1 = constraint number 1

'Ct2 = constraint number 2

CT1 = (SN1 <= 5)


CT2 = (SN2 >= 0)

End Sub

Sub Economic_Return()

'ad(s) = definition of the economic return

AD(s) = m(D, S1)

End Sub

Sub Return_Function()

Rd(s) = AD(s) + F(sn)

End Sub

Sub Recursive_Equation()

F(s) = minim(Rd(s))

End Sub

Sub Boundary_Conditions()

'p(s) = definition of the optimal policy in the boundary

'f(s) = definition of the optimal value function in the boundary

F(s) = 0

End Sub

Option Explicit

'Dim 'list of new variables

Dim TP(1 To 5), P(1 To 5)

Sub Preliminary_Definitions()

Call fillarray(TP, "{2,4,6,8}", 1)


Call fillarray(P, "{14,14,10,16}", 1)

End Sub

Sub Model_Structure()

NSV = 2

NCT = 2

End Sub

Sub Starting_State()

's1 = inicial value for variable s1

's2 = inicial value for variable s2

S1 = "{1,2,3,4}"

s2 = 0

End Sub

Sub Decision_Set()

DS = S1

End Sub

Sub Transition_Function()

'sn1 = transition equation for variable s1

'sn2 = transition equation for variable s2

sn1 = remelem(S1, d)

sn2 = s2 + TP(S1, d)

End Sub

Sub State_Constraints()
'Ct1 = constraint number 1

'Ct2 = constraint number 2

ct1 = (sn1 <= 5)

ct2 = (sn2 >= 0)

End Sub

Sub Economic_Return()

'ad(s) = definition of the economic return

ad(S) = P(S1) - s2

End Sub

Sub Return_Function()

Rd(S) = ad(S) + f(sn)

End Sub

Sub Recursive_Equation()

f(S) = minim(Rd(S))

End Sub

Sub Boundary_Conditions()

'p(s) = definition of the optimal policy in the boundary

'f(s) = definition of the optimal value function in the boundary

f(S) = 0

End Sub

Option Explicit

'Dim 'list of new variables

Dim TP(1 To 5), P(1 To 5)

Sub Preliminary_Definitions()
Call fillarray(TP, "{2,4,6,8}", 1)

Call fillarray(P, "{14,14,10,16}", 1)

End Sub

Sub Model_Structure()

NSV = 3

NCT = 3

End Sub

Sub Starting_State()

's1 = inicial value for variable s1

's2 = inicial value for variable s2

s1 = 1

s2 = "{1,2,3,4}"

s3 = 0

End Sub

Sub Decision_Set()

DS = s2

End Sub

Sub Transition_Function()

'sn1 = transition equation for variable s1

'sn2 = transition equation for variable s2

sn1 = s1 + 1

sn2 = remelem(s2, d)

sn3 = s2 + TP(s2, d)
End Sub

Sub State_Constraints()

'Ct1 = constraint number 1

'Ct2 = constraint number 2

ct1 = (sn1 <= 5)

ct2 = (sn2 >= 0)

ct3 = (sn3 >= 0)

End Sub

Sub Economic_Return()

'ad(s) = definition of the economic return

ad(S) = P(s1) - s2

End Sub

Sub Return_Function()

Rd(S) = ad(S) + f(sn)

End Sub

Sub Recursive_Equation()

f(S) = minim(Rd(S))

End Sub

Sub Boundary_Conditions()

'p(s) = definition of the optimal policy in the boundary

'f(s) = definition of the optimal value function in the boundary

f(S) = 0

End Sub

Option Explicit

'Dim 'list of new variables


Dim TP(1 To 5), P(1 To 5)

Sub Preliminary_Definitions()

Call fillarray(TP, "{2,4,6,8}", 1)

Call fillarray(P, "{14,14,10,16}", 1)

End Sub

Sub Model_Structure()

NSV = 3

NCT = 3

End Sub

Sub Starting_State()

's1 = inicial value for variable s1

's2 = inicial value for variable s2

s1 = "{1,2,3,4}"

s2 = 0

End Sub

Sub Decision_Set()

DS = s1

End Sub

Sub Transition_Function()

'sn1 = transition equation for variable s1

'sn2 = transition equation for variable s2


sn1 = remelem(s1, d)

sn2 = s2 + TP(s1)

End Sub

Sub State_Constraints()

'Ct1 = constraint number 1

'Ct2 = constraint number 2

ct1 = (sn1 <= 5)

ct2 = (sn2 >= 0)

End Sub

Sub Economic_Return()

'ad(s) = definition of the economic return

If P(s1) - s2 <= 0 Then

ad(s) = 0

Else

ad(s) = P(s1) - s2

End If

End Sub

Sub Return_Function()

Rd(s) = ad(s) + f(sn)

End Sub

Sub Recursive_Equation()

f(s) = minim(Rd(s))

End Sub

Sub Boundary_Conditions()
'p(s) = definition of the optimal policy in the boundary

'f(s) = definition of the optimal value function in the boundary

f(s) = 0

End Sub

Das könnte Ihnen auch gefallen