A RetroSearch Logo

Home - News ( United States | United Kingdom | Italy | Germany ) - Football scores

Search Query:

Showing content from https://www.gams.com/latest/docs/apis/examples_dotnet/Transport9_8cs_source.html below:

Transport9/Transport9.cs Source File

21 static void

Main(

string

[] args)

24 if

(Environment.GetCommandLineArgs().Length > 1)

25

ws =

new GAMSWorkspace

(systemDirectory: Environment.GetCommandLineArgs()[1]);

36

opt.AllModelTypes =

"xpress"

;

39

Console.WriteLine(

"x("

+ rec.Key(0) +

","

+ rec.Key(1) +

"): level="

+ rec.

Level

+

" marginal="

+ rec.

Marginal

);

41

WriteToAccess(ws, t9.OutDB);

46 static void

ReadSet(OleDbConnection connect,

GAMSDatabase

db,

string

strAccessSelect,

string

setName,

int

setDim,

string

setExp =

""

)

50

OleDbCommand cmd =

new

OleDbCommand(strAccessSelect, connect);

53

OleDbDataReader reader = cmd.ExecuteReader();

55 if

(reader.FieldCount != setDim)

57

Console.WriteLine(

"Number of fields in select statement does not match setDim"

);

63 string

[] keys =

new string

[setDim];

66 for

(

int

idx = 0; idx < setDim; idx++)

67

keys[idx] = reader.GetString(idx);

74

Console.WriteLine(

"Error: Failed to retrieve the required data from the database.\n{0}"

, ex.Message);

83 static void

ReadParameter(OleDbConnection connect,

GAMSDatabase

db,

string

strAccessSelect,

string

parName,

int

parDim,

string

parExp =

""

)

87

OleDbCommand cmd =

new

OleDbCommand(strAccessSelect, connect);

90

OleDbDataReader reader = cmd.ExecuteReader();

92 if

(reader.FieldCount != parDim+1)

94

Console.WriteLine(

"Number of fields in select statement does not match parDim+1"

);

100 string

[] keys =

new string

[parDim];

101 while

(reader.Read())

103 for

(

int

idx = 0; idx < parDim; idx++)

104

keys[idx] = reader.GetString(idx);

106

a.

AddRecord

(keys).

Value

= Convert.ToDouble(reader.GetValue(parDim));

111

Console.WriteLine(

"Error: Failed to retrieve the required data from the database.\n{0}"

, ex.Message);

126 string

strAccessConn =

@"Provider=Microsoft.ACE.OLEDB.12.0;Data Source="

+ Path.Combine(ws.

SystemDirectory

,

@"apifiles/Data/transport.accdb"

);

127

OleDbConnection connection =

null

;

130

connection =

new

OleDbConnection(strAccessConn);

134

Console.WriteLine(

"Error: Failed to create a database connection. \n{0}"

, ex.Message);

139

ReadSet(connection, db,

"SELECT Plant FROM Plant"

,

"i"

, 1,

"canning plants"

);

140

ReadSet(connection, db,

"SELECT Market FROM Market"

,

"j"

, 1,

"markets"

);

143

ReadParameter(connection, db,

"SELECT Plant,Capacity FROM Plant"

,

"a"

, 1,

"capacity of plant i in cases"

);

144

ReadParameter(connection, db,

"SELECT Market,Demand FROM Market"

,

"b"

, 1,

"demand at market j in cases"

);

145

ReadParameter(connection, db,

"SELECT Plant,Market,Distance FROM Distance"

,

"d"

, 2,

"distance in thousands of miles"

);

150 static void

WriteVariable(OleDbConnection connect,

GAMSDatabase

db,

string

varName, params

string

[] Domains)

155 if

(Domains.Length != var.Dim)

157

Console.WriteLine(

"Number of column names does not match the dimension of the variable."

);

164

OleDbCommand cmd =

new

OleDbCommand(

"drop table "

+ varName, connect);

167

cmd.ExecuteNonQuery();

173

String query =

"create table "

+ varName +

"("

;

174 foreach

(

string

dom

in

Domains)

175

query += dom +

" varchar(64), "

;

176

query +=

"lvl double)"

;

178

cmd.CommandText = query;

179

cmd.ExecuteNonQuery();

183

query =

"insert into "

+ varName +

"("

;

184 foreach

(

string

dom

in

Domains)

185

query += dom +

", "

;

186

query +=

"lvl) values ("

;

187 foreach

(

string

key

in

rec.Keys)

188

query +=

"'"

+ key +

"', "

;

189

query += rec.Level +

")"

;

190

cmd.CommandText = query;

191

cmd.ExecuteNonQuery();

196

Console.WriteLine(

"Error: Failed to write variable to the database.\n{0}"

, ex.Message);

208 string

strAccessConn =

@"Provider=Microsoft.ACE.OLEDB.12.0;Data Source="

+ Path.Combine(ws.

SystemDirectory

,

@"apifiles/Data/transport.accdb"

);

209

OleDbConnection connection =

null

;

212

connection =

new

OleDbConnection(strAccessConn);

216

Console.WriteLine(

"Error: Failed to create a database connection. \n{0}"

, ex.Message);

221

WriteVariable(connection, db,

"x"

,

"i"

,

"j"

);

225 static

String GetModelText()

233 a(i) capacity of plant i in cases 234 b(j) demand at market j in cases 235 d(i,j) distance in thousands of miles 236 Scalar f freight in dollars per case per thousand miles /90/; 238$if not set gdxincname $abort 'no include file name for data file provided' 243 Parameter c(i,j) transport cost in thousands of dollars per case ; 245 c(i,j) = f * d(i,j) / 1000 ; 248 x(i,j) shipment quantities in cases 249 z total transportation costs in thousands of dollars ; 251 Positive Variable x ; 254 cost define objective function 255 supply(i) observe supply limit at plant i 256 demand(j) satisfy demand at market j ; 258 cost .. z =e= sum((i,j), c(i,j)*x(i,j)) ; 260 supply(i) .. sum(j, x(i,j)) =l= a(i) ; 262 demand(j) .. sum(i, x(i,j)) =g= b(j) ; 264 Model transport /all/ ; 266 Solve transport using lp minimizing z ;

RetroSearch is an open source project built by @garambo | Open a GitHub Issue

Search and Browse the WWW like it's 1997 | Search results from DuckDuckGo

HTML: 3.2 | Encoding: UTF-8 | Version: 0.7.4