[.NET] Gurobi讀檔

作者: kirghizia (雲和山的彼端)   2014-02-08 15:19:24
請輸入專案類型(網站專案或者應用程式專案):應用程式
各位前輩好,小弟最近在研究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

Links booklink

Contact Us: admin [ a t ] ucptt.com