Hi Everyone,
I need help on using Microsoft solver foundation to solve linear programming models.
Does anyone one how to load/read data from a file and then use that data to solve a linear programming model using Microsoft solver foundation in C#?
Here is my code in C# using Microsoft solver foundation to solve a linear program. But I don't want to write all constraints one by one, I want to load/read data from a file then use it to solve this linear model.
If anyone knows, PLEASE help me!!!! -
using System;
-
using System.Collections.Generic;
-
using System.Linq;
-
using System.Text;
-
using Microsoft.SolverFoundation.Common;
-
using Microsoft.SolverFoundation.Services;
-
-
-
namespace PetroChem
-
{
-
class Program
-
{
-
static void Main(string[] args)
-
{
-
SolverContext context = SolverContext.GetContext();
-
Model model = context.CreateModel();
-
-
Decision x11 = new Decision(Domain.IntegerNonnegative, "x11");
-
Decision x12 = new Decision(Domain.IntegerNonnegative, "x12");
-
Decision x13 = new Decision(Domain.IntegerNonnegative, "x13");
-
Decision x14 = new Decision(Domain.IntegerNonnegative, "x14");
-
Decision x15 = new Decision(Domain.IntegerNonnegative, "x15");
-
Decision x21 = new Decision(Domain.IntegerNonnegative, "x21");
-
Decision x22 = new Decision(Domain.IntegerNonnegative, "x22");
-
Decision x23 = new Decision(Domain.IntegerNonnegative, "x23");
-
Decision x24 = new Decision(Domain.IntegerNonnegative, "x24");
-
Decision x25 = new Decision(Domain.IntegerNonnegative, "x25");
-
Decision x31 = new Decision(Domain.IntegerNonnegative, "x31");
-
Decision x32 = new Decision(Domain.IntegerNonnegative, "x32");
-
Decision x33 = new Decision(Domain.IntegerNonnegative, "x33");
-
Decision x34 = new Decision(Domain.IntegerNonnegative, "x34");
-
Decision x35 = new Decision(Domain.IntegerNonnegative, "x35");
-
Decision x41 = new Decision(Domain.IntegerNonnegative, "x41");
-
Decision x42 = new Decision(Domain.IntegerNonnegative, "x42");
-
Decision x43 = new Decision(Domain.IntegerNonnegative, "x43");
-
Decision x44 = new Decision(Domain.IntegerNonnegative, "x44");
-
Decision x45 = new Decision(Domain.IntegerNonnegative, "x45");
-
Decision x51 = new Decision(Domain.IntegerNonnegative, "x51");
-
Decision x52 = new Decision(Domain.IntegerNonnegative, "x52");
-
Decision x53 = new Decision(Domain.IntegerNonnegative, "x53");
-
Decision x54 = new Decision(Domain.IntegerNonnegative, "x54");
-
Decision x55 = new Decision(Domain.IntegerNonnegative, "x55");
-
-
model.AddDecisions(x11, x12, x13, x14, x15,
-
x21, x22, x23, x24, x25,
-
x31, x32, x33, x34, x35,
-
x41, x42, x43, x44, x45,
-
x51, x52, x53, x54, x55 );
-
-
model.AddConstraint("Row1", x11 + x12 + x13 + x14 + x15 >= 70);
-
model.AddConstraint("Row2", x21 + x22 + x23 + x24 + x25 >= 80);
-
model.AddConstraint("Row3", x31 + x32 + x33 + x34 + x35 >= 90);
-
model.AddConstraint("Row4", x41 + x42 + x43 + x44 + x45 >= 85);
-
model.AddConstraint("Row5", x51 + x52 + x53 + x54 + x55 >= 90);
-
model.AddConstraint("Row6", x11 + x21 + x31 + x41 + x51 >= 110);
-
model.AddConstraint("Row7", x12 + x22 + x32 + x42 + x52 >= 120);
-
model.AddConstraint("Row8", x13 + x23 + x33 + x43 + x53 >= 130);
-
model.AddConstraint("Row9", x14 + x24 + x34 + x44 + x54 >= 120);
-
model.AddConstraint("Row10", x15 + x25 + x35 + x45 + x55 >= 100);
-
-
-
model.AddGoal("Goal", GoalKind.Minimize, x11 + x12 + x13 + x14 + x15 +
-
x21 + x22 + x23 + x24 + x25 +
-
x31 + x32 + x33 + x34 + x35 +
-
x41 + x42 + x43 + x44 + x45 +
-
x51 + x52 + x53 + x54 + x55 );
-
-
Solution solution = context.Solve(new SimplexDirective());
-
-
Report report = solution.GetReport();
-
Console.WriteLine("x1: {0}, x2: {1}, x3: {2}", x11, x12, x13, x14, x15,
-
x21, x22, x23, x24, x25,
-
x31, x32, x33, x34, x35,
-
x41, x42, x43, x44, x45,
-
x51, x52, x53, x54, x55);
-
Console.Write("{0}", report);
-
Console.ReadLine();
-
-
-
-
-
-
}
-
}
-
}
-
0 1205 Sign in to post your reply or Sign up for a free account.
Similar topics
by: Chris |
last post by:
I have seen the posts on various places on the internet about .NET
framework mismatch issues and I don't think that is my problem. ; )
When I execute the following C++.NET code:
String...
|
by: Bob |
last post by:
Hi,
I am trying to use BULK INSERT with format file. All of our data has
few bytes of header in the data file which I would like to skip before
doing BULK INSERT.
Is it possible to write...
|
by: amorphous999 |
last post by:
I want to use DTS to load from a flat file. But I can't be sure when
the flat file will arrive. I would like the job to check every 10
minutes or so for a couple of hours. If the file is...
|
by: John Samson |
last post by:
I am building a windows services scheduler that shall fetch file and
import the data into a SQL Server according to the predefined schedule.
My idea is to create two application
1) App 1 -...
|
by: Jon |
last post by:
Hi,
I am testing the scenario to migrate from MSMXL4 to .NET2.0 system.xml. I
experienced xsl file loading problem whenever the xsl file have a user
defined script in it. The error message is as...
|
by: nguyen1105 |
last post by:
Hello,
It seems that the .Net Framework 3.0 Microsoft Presentation Foundation has no UI DataGrid control. I've verified the package System.Windows.Controls in the .Net Framework 3.0 Microsoft...
|
by: Johnny |
last post by:
Hi all:
I have an ASP.NET form that reads an Excel file and populates a datagrid. If
I load the form in IE on the server, and select a local file, the code works
fine. However if I load the form...
|
by: =?Utf-8?B?YzY3NjIyOA==?= |
last post by:
Hi all,
I have a question for you.
I have a .csv file which has many lines of data.
Each line has many data fields which are delimited by ",".
Now I need to extract part of data from this...
|
by: DR |
last post by:
Why is its substantialy slower to load 50GB of gzipped file (20GB gzipped
file) then loading 50GB unzipped data? im using
System.IO.Compression.GZipStream and its not maxing out the cpu while...
|
by: csgirlie |
last post by:
I'm trying to store or arrange three sets of two-dimensional data into three 2xN matrices that are stored as NumPy arrays.
import os # for file handling functions
import numpy as...
|
by: ryjfgjl |
last post by:
ExcelToDatabase: batch import excel into database automatically...
|
by: Vimpel783 |
last post by:
Hello!
Guys, I found this code on the Internet, but I need to modify it a little. It works well, the problem is this: Data is sent from only one cell, in this case B5, but it is necessary that data...
|
by: jfyes |
last post by:
As a hardware engineer, after seeing that CEIWEI recently released a new tool for Modbus RTU Over TCP/UDP filtering and monitoring, I actively went to its official website to take a look. It turned...
|
by: ArrayDB |
last post by:
The error message I've encountered is; ERROR:root:Error generating model response: exception: access violation writing 0x0000000000005140, which seems to be indicative of an access violation...
|
by: CloudSolutions |
last post by:
Introduction:
For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
|
by: Defcon1945 |
last post by:
I'm trying to learn Python using Pycharm but import shutil doesn't work
|
by: Shællîpôpï 09 |
last post by:
If u are using a keypad phone, how do u turn on JavaScript, to access features like WhatsApp, Facebook, Instagram....
|
by: Faith0G |
last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
|
by: isladogs |
last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM).
In this session, we are pleased to welcome former...
| |