473,327 Members | 1,936 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,327 software developers and data experts.

C# Microsoft Solver Foundation loading data from a file or using sets

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!!!!


Expand|Select|Wrap|Line Numbers
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Linq;
  4. using System.Text;
  5. using Microsoft.SolverFoundation.Common;
  6. using Microsoft.SolverFoundation.Services;
  7.  
  8.  
  9. namespace PetroChem
  10. {
  11.     class Program
  12.     {
  13.         static void Main(string[] args)
  14.         {
  15.             SolverContext context = SolverContext.GetContext();
  16.             Model model = context.CreateModel();
  17.  
  18.             Decision x11 = new Decision(Domain.IntegerNonnegative, "x11");
  19.             Decision x12 = new Decision(Domain.IntegerNonnegative, "x12");
  20.             Decision x13 = new Decision(Domain.IntegerNonnegative, "x13");
  21.             Decision x14 = new Decision(Domain.IntegerNonnegative, "x14");
  22.             Decision x15 = new Decision(Domain.IntegerNonnegative, "x15");
  23.             Decision x21 = new Decision(Domain.IntegerNonnegative, "x21");
  24.             Decision x22 = new Decision(Domain.IntegerNonnegative, "x22");
  25.             Decision x23 = new Decision(Domain.IntegerNonnegative, "x23");
  26.             Decision x24 = new Decision(Domain.IntegerNonnegative, "x24");
  27.             Decision x25 = new Decision(Domain.IntegerNonnegative, "x25");
  28.             Decision x31 = new Decision(Domain.IntegerNonnegative, "x31");
  29.             Decision x32 = new Decision(Domain.IntegerNonnegative, "x32");
  30.             Decision x33 = new Decision(Domain.IntegerNonnegative, "x33");
  31.             Decision x34 = new Decision(Domain.IntegerNonnegative, "x34");
  32.             Decision x35 = new Decision(Domain.IntegerNonnegative, "x35");
  33.             Decision x41 = new Decision(Domain.IntegerNonnegative, "x41");
  34.             Decision x42 = new Decision(Domain.IntegerNonnegative, "x42");
  35.             Decision x43 = new Decision(Domain.IntegerNonnegative, "x43");
  36.             Decision x44 = new Decision(Domain.IntegerNonnegative, "x44");
  37.             Decision x45 = new Decision(Domain.IntegerNonnegative, "x45");
  38.             Decision x51 = new Decision(Domain.IntegerNonnegative, "x51");
  39.             Decision x52 = new Decision(Domain.IntegerNonnegative, "x52");
  40.             Decision x53 = new Decision(Domain.IntegerNonnegative, "x53");
  41.             Decision x54 = new Decision(Domain.IntegerNonnegative, "x54");
  42.             Decision x55 = new Decision(Domain.IntegerNonnegative, "x55");
  43.  
  44.             model.AddDecisions(x11, x12, x13, x14, x15,
  45.                                x21, x22, x23, x24, x25,
  46.                                x31, x32, x33, x34, x35,
  47.                                x41, x42, x43, x44, x45,
  48.                                x51, x52, x53, x54, x55 );
  49.  
  50.             model.AddConstraint("Row1", x11 + x12 + x13 + x14 + x15 >= 70);
  51.             model.AddConstraint("Row2", x21 + x22 + x23 + x24 + x25 >= 80);
  52.             model.AddConstraint("Row3", x31 + x32 + x33 + x34 + x35 >= 90);
  53.             model.AddConstraint("Row4", x41 + x42 + x43 + x44 + x45 >= 85);
  54.             model.AddConstraint("Row5", x51 + x52 + x53 + x54 + x55 >= 90);
  55.             model.AddConstraint("Row6", x11 + x21 + x31 + x41 + x51 >= 110);
  56.             model.AddConstraint("Row7", x12 + x22 + x32 + x42 + x52 >= 120);
  57.             model.AddConstraint("Row8", x13 + x23 + x33 + x43 + x53 >= 130);
  58.             model.AddConstraint("Row9", x14 + x24 + x34 + x44 + x54 >= 120);
  59.             model.AddConstraint("Row10", x15 + x25 + x35 + x45 + x55 >= 100);
  60.  
  61.  
  62.             model.AddGoal("Goal", GoalKind.Minimize, x11 + x12 + x13 + x14 + x15 +
  63.                                                      x21 + x22 + x23 + x24 + x25 +
  64.                                                      x31 + x32 + x33 + x34 + x35 +
  65.                                                      x41 + x42 + x43 + x44 + x45 +
  66.                                                      x51 + x52 + x53 + x54 + x55 );
  67.  
  68.             Solution solution = context.Solve(new SimplexDirective());
  69.  
  70.             Report report = solution.GetReport();
  71.             Console.WriteLine("x1: {0}, x2: {1}, x3: {2}", x11, x12, x13, x14, x15,
  72.                                                            x21, x22, x23, x24, x25,
  73.                                                            x31, x32, x33, x34, x35,
  74.                                                            x41, x42, x43, x44, x45,
  75.                                                            x51, x52, x53, x54, x55);
  76.             Console.Write("{0}", report);
  77.             Console.ReadLine();
  78.  
  79.  
  80.  
  81.  
  82.  
  83.         }
  84.     }
  85. }
  86.  
Jul 19 '13 #1
0 1205

Sign in to post your reply or Sign up for a free account.

Similar topics

1
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...
7
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...
3
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...
0
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 -...
2
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...
2
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...
8
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...
3
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...
5
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...
1
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...
0
by: ryjfgjl | last post by:
ExcelToDatabase: batch import excel into database automatically...
0
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...
0
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...
0
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...
1
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...
1
by: Defcon1945 | last post by:
I'm trying to learn Python using Pycharm but import shutil doesn't work
1
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....
0
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...
0
isladogs
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...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.