model:
!集定义;
Sets:
Pro/1..4/;
Con/1..1/;
ProFlow(Pro,Pro)|&1 #ne# &2 :FPP;
FreFlow(Pro):FFP; !定义过程使用新鲜水;
WasFlow(Pro):FPW; !定义过程排放废水;
ProConc(Pro,Con):COut,CIn,COut_Max,CIn_Max; !定义过程进出口浓度及及先进出口浓度;
MassLoad(Pro,Con):ML; !定义过程需要移除的污染物负荷;Endsets
Data:
COut_Max=@pointer(1); CIn_Max=@pointer(2); ML=@pointer(3);
Enddata!目标函数:;
[OBJ]min=@sum(FreFlow(I):FFP);!约束条件:;
!1.过程j进出口流率相等;
@for(Pro(J):
FFP(J)+@sum(Pro(I)|I#ne#J:FPP(I,J))=@sum(Pro(K)|k#ne#J:FPP(J,K))+FPW(J));!2.过程j入口处混合前后的污染物s的质量相等;
@for(Pro(J):
@for(Con(S):
@sum(Pro(I)|I#ne#J:FPP(I,J)*COut(I,S))=(@sum(Pro(I)|I#ne#J:FPP(I,J))+FFP(J))*CIn(J,S)));!3.过程j中污染物s的进出口质量衡算式;
@for(Pro(J):
@for(Con(S):
(@sum(Pro(I)|I#ne#J:FPP(I,J))+FFP(J))*CIn(J,S)+ML(J,S)=(@sum(Pro(I)|I#ne#J:FPP(I,J))+FFP(J))*COut(J,S)));!4.污染物进口浓度不能高于上限;
@for(Pro(J):
@for(Con(S):
COut(J,S)<=COut_Max(J,S)));!5.污染物出口浓度不能高于上限;
@for(Pro(J):
@for(Con(S):
CIn(J,S)<=CIn_Max(J,S)));!@sum(FreFlow(I):FFP)<=150;
data:
@pointer(4)=OBJ;
@pointer(5)=@status();
@pointer(6)=FPP;
enddata
这是lingo中simple.lng文件using System;
using System.Text;
using System.IO;using System.Runtime.InteropServices;
using System.Runtime.Remoting;namespace Simple
{
[StructLayout( LayoutKind.Sequential)]
public class CallbackData
{
public int nIterations; // Constructor:
public CallbackData()
{
nIterations = 0;
}
} class Class1
{ [STAThread]
static void Main(string[] args)
{
IntPtr pLingoEnv;
int nError=-1, nPointersNow=-1;
double dObjective=-1, dStatus=-1; // Get a pointer to a Lingo environment
pLingoEnv = lingo.LScreateEnvLng();
if ( pLingoEnv == IntPtr.Zero)
{
Console.WriteLine( "Unable to create Lingo environment.\n");
goto FinalExit;
} // Open LINGO's log file
nError = lingo.LSopenLogFileLng( pLingoEnv, "lingo.log");
if ( nError != lingo.LSERR_NO_ERROR_LNG) goto ErrorExit; // Let Lingo know we have a callback function
CallbackData cbd = new CallbackData();
lingo.typCallback cb = new lingo.typCallback( LngCallback.MyCallback);
nError = lingo.LSsetCallbackSolverLng( pLingoEnv, cb, cbd);
if ( nError != lingo.LSERR_NO_ERROR_LNG) goto ErrorExit; // must pin lingo's transfer areas in memory
unsafe {
fixed (
byte* cComputers = new byte[64])
{
fixed(
// Model data that gets referenced by the
// template model, simple.lng
double* dCOut_Max = new double[4]{200,500,650,200},
dCIn_Max = new double[4]{0,100,200,0},
dML = new double[4]{7620,23750,69410,2280})
{
// Pass Lingo the pointer to the objective coefficients (refer
// to the template model, simple.lng)
nError = lingo.LSsetPointerLng(pLingoEnv, dCOut_Max, ref nPointersNow);
if ( nError != lingo.LSERR_NO_ERROR_LNG) goto ErrorExit; // Pass a pointer to the production limits
nError = lingo.LSsetPointerLng(pLingoEnv, dCIn_Max, ref nPointersNow);
if ( nError != lingo.LSERR_NO_ERROR_LNG) goto ErrorExit; // Pointer to the labor utilization coefficients
nError = lingo.LSsetPointerLng(pLingoEnv, dML, ref nPointersNow);
if ( nError != lingo.LSERR_NO_ERROR_LNG) goto ErrorExit; // Point to dObjective, where Lingo will return the objective value
nError = lingo.LSsetPointerLng( pLingoEnv, &dObjective, ref nPointersNow);
if ( nError != lingo.LSERR_NO_ERROR_LNG) goto ErrorExit; // Pointer to the solution status code
nError = lingo.LSsetPointerLng( pLingoEnv, &dStatus, ref nPointersNow);
if ( nError != lingo.LSERR_NO_ERROR_LNG) goto ErrorExit;
// Here is the script we want LINGO to run.
string cScript =
"set echoin 1 \n take f:\\软件及项目\\lingo11\\programming samples\\c#net\\simple\\simple.lng \n go \n quit \n"; // Run the script
nError = lingo.LSexecuteScriptLng( pLingoEnv, cScript);
if ( nError != lingo.LSERR_NO_ERROR_LNG) goto ErrorExit; // Close the log file
lingo.LScloseLogFileLng( pLingoEnv); // Any problems?
if ( nError != 0 ||
dStatus != lingo.LS_STATUS_GLOBAL_LNG)
{
// Had a problem
Console.WriteLine( "Unable to solve!");
}
else
{
// Everything went OK ... print results
Console.WriteLine(
"\nStandards: {0} ",
dObjective);
} }}} goto NormalExit; ErrorExit:
Console.WriteLine( "LINGO Error Code: {0}\n", nError); NormalExit:
lingo.LSdeleteEnvLng( pLingoEnv); FinalExit:
Console.WriteLine("press enter...");
String sTemp = Console.ReadLine();
} } public class LngCallback
{
public LngCallback()
{
} public static int MyCallback( IntPtr pLingoEnv, int nReserved, IntPtr pMyData)
{ // Lingo callback function to display the current iteration count CallbackData cb = new CallbackData();
Marshal.PtrToStructure( pMyData, cb); int nIterations=-1, nErr;
nErr = lingo.LSgetCallbackInfoLng( pLingoEnv,
lingo.LS_IINFO_ITERATIONS_LNG, ref nIterations);
if ( nErr == lingo.LSERR_NO_ERROR_LNG && nIterations != cb.nIterations)
{
cb.nIterations = nIterations;
Console.WriteLine("Iteration count={0}", nIterations);
} Marshal.StructureToPtr( cb, pMyData, true); return 0;
}
}
}
这个是C#中的程序,我怎么不能把值传到lng中,然后再lng中计算,并把结果返回来呢?跪求各位大神了小弟一直等着热心人的帮助。
解决方案 »
免费领取超大流量手机卡,每月29元包185G流量+100分钟通话, 中国电信官方发货