作者kirghizia (云和山的彼端)
看板Visual_Basic
标题[.NET] Gurobi读档
时间Sat Feb 8 15:19:24 2014
请输入专案类型(网站专案或者应用程式专案):应用程式
各位前辈好,小弟最近在研究vb.net呼叫Gurobi进行数学规划求解
看了很多相关资料,可是还是不了解如何读档
请各位前辈给些建议
===程式码===
Imports System
Imports Gurobi
Public Class Form1
Private Sub Button1_Click(sender As Object, e As EventArgs) Handles
Button1.Click
Dim file As String
If OpenFileDialog1.ShowDialog = DialogResult.OK Then
file = OpenFileDialog1.FileName
If file.Length < 1 Then
RichTextBox1.AppendText("Usage: lp_vb filename" & vbNewLine)
Return
Else
RichTextBox1.AppendText("档案路径为:" &
OpenFileDialog1.FileName & vbNewLine)
End If
End If
Dim env As GRBEnv = New GRBEnv("outcome.log")
Dim model As GRBModel = New GRBModel(env, file)
Dim optimstatus As Integer = model.Get(GRB.IntAttr.Status)
Dim objval As Double = model.Get(GRB.DoubleAttr.ObjVal)
'model.Read(file)
Try
model.Optimize()
If optimstatus = GRB.Status.INF_OR_UNBD Then
model.GetEnv().Set(GRB.IntParam.Presolve, 0)
model.Optimize()
optimstatus = model.Get(GRB.IntAttr.Status)
End If
If optimstatus = GRB.Status.OPTIMAL Then
RichTextBox1.AppendText("Optimal objective: " & objval &
vbNewLine)
ElseIf optimstatus = GRB.Status.INFEASIBLE Then
RichTextBox1.AppendText("Model is infeasible" & vbNewLine)
model.ComputeIIS()
model.Write("model.ilp")
ElseIf optimstatus = GRB.Status.UNBOUNDED Then
RichTextBox1.AppendText("Model is unbounded" & vbNewLine)
Else
RichTextBox1.AppendText("Optimization was stopped with status
= " & _
optimstatus & vbNewLine)
End If
' Dispose of model and env
model.Dispose()
env.Dispose()
Catch ex As GRBException
RichTextBox1.AppendText("Error code: " & ex.ErrorCode & ". " &
ex.Message & vbNewLine)
End Try
End Sub
End Class
--
※ 发信站: 批踢踢实业坊(ptt.cc)
◆ From: 114.40.100.150