Alforja

Al compilar

En el Excel con P4

Código fuente 'EL PROBLEMA DE LA ALFORJA Option Explicit Dim w(5), v(5), C, N Sub Preliminary_Definitions() C = 10 N = 4 FillArray w(), "{3,6,7,5}", 1 FillArray v(), "{7,16,19,15}", 1 End Sub Sub Model_Structure() NSV = 2 NCT = 2 End Sub Sub Starting_State() s1 = 1 s2 = C End Sub Sub Decision_Set() DS = "{0,1}" End Sub Sub Transition_Function() sn1 = s1 + 1 sn2 = s2 - w(s1) * d End Sub Sub State_Constraints() Ct1 = (sn1 <= N) Ct2 = (sn2 >= 0) End Sub Sub Economic_Return() ad(s) = v(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) = IIf(s2 >= w(N), 1, 0) f(s) = v(N) * p(s) End Sub

w(5): v(5): C: N:

vector que muestra el peso de cada objeto vector que muestra el valor de cada objeto capacidad que se puede llevar en la alforja número máximo de objetos que puede llevar en la alforja

Alforja variación 1

Al compilar

En el Excel con P4

Código fuente 'EL PROBLEMA DE LA ALFORJA versión1 Option Explicit Dim w(5), v(5), C, N Sub Preliminary_Definitions() C = 10 N = 4 FillArray w(), "{3,6,7,5}", 1 FillArray v(), "{7,16,19,15}", 1 End Sub Sub Model_Structure() NSV = 2 NCT = 2 End Sub Sub Starting_State() s1 = 1 s2 = C End Sub Sub Decision_Set () DS = InvalSet (0, Int(s2 / w(s1))) End Sub Sub Transition_Function() sn1 = s1 + 1 sn2 = s2 - w(s1) * d End Sub Sub State_Constraints() Ct1 = (sn1 <= N) Ct2 = (sn2 >= 0) End Sub Sub Economic_Return() ad(s) = v(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) = IIf(s2 >= w(N), Int(s2 / w(N)), 0) f(s) = v(N) * p(s) End Sub

Alforja variación 2

Al compilar

En el Excel con P4

Código fuente 'EL PROBLEMA DE LA ALFORJA versión2 Option Explicit Dim w(5), v(5), k(5), C, N Sub Preliminary_Definitions() C = 10 N = 4 FillArray w(), "{3,6,7,5}", 1 FillArray v(), "{7,16,19,15}", 1 FillArray k(), "{2,3,1,1}", 1 End Sub Sub Model_Structure() NSV = 2 NCT = 2 End Sub Sub Starting_State() s1 = 1 s2 = C End Sub Sub Decision_Set() DS = IvalSet(0, minim(k(s1), Int(s2 / w(s1)))) End Sub Sub Transition_Function() sn1 = s1 + 1 sn2 = s2 - w(s1) * d End Sub Sub State_Constraints() Ct1 = (sn1 <= N) Ct2 = (sn2 >= 0) End Sub Sub Economic_Return() ad(s) = v(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) = IIf(s2 >= w(N), minim(k(N), Int(s2 / w(s1))), 0) f(s) = v(N) * p(s) End Sub

Alforja variación 3

Al compilar

En el Excel con P4

Código Fuente 'EL PROBLEMA DE LA ALFORJA versión2 Option Explicit Dim w(5), v(5), Rmin(5), Rmax(5), C, N, M Sub Preliminary_Definitions() C = 10 N = 4 FillArray w(), "{3,6,7,5}", 1 FillArray v(), "{7,16,19,15}", 1 FillArray k(), "{2,3,1,1}", 1 FillArray Rmin(), "{0,0,0,2}", 1 FillArray Rmax(), "{3,3,3,3}", 1 End Sub Sub Model_Structure() NSV = 2 NCT = 2 End Sub Sub Starting_State() s1 = 1 s2 = C End Sub Sub Decision_Set() DS = IvalSet(Rmin(s1), minim(Rmax(s1), k(s1), Int(s2 / (s1)))) End Sub Sub Transition_Function() sn1 = s1 + 1 sn2 = s2 - w(s1) * d End Sub Sub State_Constraints() Ct1 = (sn1 <= N) Ct2 = (sn2 >= 0) End Sub Sub Economic_Return() ad(s) = v(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) = IIf(s2 >= Rmin(N) * w(N), v(N) * minim(Rmax(N), k(N), Int(s2 / w(N))), -M) f(s) = v(N) * p(s) End Sub

Sign up to vote on this title
UsefulNot useful