The described LP Problem is the following:
Problem Name: "LPDemo" identified by <PbId>
Maximize:
4
2X1 + X2 + S Yi
i=1
Subject to:
4
4X1 + X2+ S Yi
= 2
i=1
0 < X1 < 3 (Continuous)
0 < X2 < 2 (Continuous)
0 < Yi < 1 (Continuous) |
Here is the code of the Visual basic subroutine that
describes this LP problem:
' Defining the Problem
Identifier as Long and Public
Public PbId As Long
Private Sub GenerateModel()
' Defining indices
Dim i, j As Integer
' Defining the returned status of the
functions as Long
'(available for almost functions)
Dim status As Long
' Opening the problem LPDemo
PbId = ezmOpenPb("LPDemo")
' Define the optimization criterion as
Maximize with
' returning the status
status = ezmOptCri(PbId, EZM_MAX)
' Describe the linear terms X1 and X2 of the
objective function
status = ezmCCoef(PbId, "X1", EZM_SET, 2#)
status = ezmCCoef(PbId, "X2", EZM_SET, 1#)
' Describe the linear terms Y
of the objective function
For j
= 1 To 4
status = ezmCCoef(PbId, "Y" & j, EZM_SET, 1#)
Next
j
' Describe the constraint
' The sense of the
constraint "Equal ..."
status = ezmConType(PbId, "Constraint", EZM_EQCON)
' The left-hand side (Yi,
i=1,..., 4)
For j = 1 To 4
status = ezmACoef(PbId, "Y" & j,
"Constraint", EZM_SET, 1#)
Next
j
' The left-hand side (X1)
status = ezmACoef(PbId, "X1",
"Constraint", EZM_SET, 4#)
' The left-hand side (X2)
status = ezmACoef(PbId, "X2",
"Constraint", EZM_SET, 1#)
' The right-hand side
status = ezmBCoef(PbId,
"Constraint", EZM_SET, 2#)
' Specify the type of the
variables Y(j), X1 and X2
' as "continuous variables"
For j
= 1 To 4
status = ezmVarType(PbId, "Y" & j, EZM_CONVAR)
Next
j
status = ezmVarType(PbId, "X1", EZM_CONVAR)
status = ezmVarType(PbId, "X2", EZM_CONVAR)
' Specify the non-negativity of the variables Yi, X1 and X2
For j
= 1 To 4
status = ezmLwCoef(PbId, "Y" & j, EZM_SET, 0#)
Next
j
status = ezmLwCoef(PbId, "X1", EZM_SET, 0#)
status = ezmLwCoef(PbId, "X2", EZM_SET, 0#)
' Specify The upper bounds of
the variables Yi, X1 and X2
For j
= 1 To 4
status = ezmUpCoef(PbId, "Y" & j, EZM_SET, 1#)
Next
j
status = ezmUpCoef(PbId, "X1", EZM_SET, 2#)
status = ezmUpCoef(PbId, "X2", EZM_SET, 2#)
End Sub
' Here
is the subroutine to solve the described LP problem
' It uses the same problem identifier (PbId) defined as Public
Private Sub Solve()
' Defining the returned status of the
functions as Long
Dim status As Long
' Solve the problem LPDemo using
EZMMSE-SMALL-Version Solver
status = ezmSolve(PbId, EZM_LP, EZM_MSE_SMALL)
End Sub
' Here is
the subroutine to get the solution of the LP problem
' It uses the same problem identifier (PbId) defined as Public
Private Sub Results()
' Defining the returned status of the
functions as Long
Dim status As Long
' Add two text box components named Text1 and
Text2 to your Form
' and run the code to get the Objective Value
and the X1 value
Text1.Text = CStr(ezmGetZ(PbId))
Text2.Text = CStr(ezmGetX(PbId, "X1"))
' Get the solution with all the parameters and
variables
' and open the "PbSolution.txt" (in
C:\) using a text viewer
status = ezmWritePb(PbId, "C:\PbSolution.txt")
End Sub |