Lets gooooo

This commit is contained in:
Zastian Pretorius
2022-08-02 12:42:49 +01:00
parent 782f31810c
commit eb9f7c6c67
88 changed files with 3246 additions and 2066 deletions

63
.gitattributes vendored Normal file
View File

@@ -0,0 +1,63 @@
###############################################################################
# Set default behavior to automatically normalize line endings.
###############################################################################
* text=auto
###############################################################################
# Set default behavior for command prompt diff.
#
# This is need for earlier builds of msysgit that does not have it on by
# default for csharp files.
# Note: This is only used by command line
###############################################################################
#*.cs diff=csharp
###############################################################################
# Set the merge driver for project and solution files
#
# Merging from the command prompt will add diff markers to the files if there
# are conflicts (Merging from VS is not affected by the settings below, in VS
# the diff markers are never inserted). Diff markers may cause the following
# file extensions to fail to load in VS. An alternative would be to treat
# these files as binary and thus will always conflict and require user
# intervention with every merge. To do so, just uncomment the entries below
###############################################################################
#*.sln merge=binary
#*.csproj merge=binary
#*.vbproj merge=binary
#*.vcxproj merge=binary
#*.vcproj merge=binary
#*.dbproj merge=binary
#*.fsproj merge=binary
#*.lsproj merge=binary
#*.wixproj merge=binary
#*.modelproj merge=binary
#*.sqlproj merge=binary
#*.wwaproj merge=binary
###############################################################################
# behavior for image files
#
# image files are treated as binary by default.
###############################################################################
#*.jpg binary
#*.png binary
#*.gif binary
###############################################################################
# diff behavior for common document formats
#
# Convert binary document formats to text before diffing them. This feature
# is only available from the command line. Turn it on by uncommenting the
# entries below.
###############################################################################
#*.doc diff=astextplain
#*.DOC diff=astextplain
#*.docx diff=astextplain
#*.DOCX diff=astextplain
#*.dot diff=astextplain
#*.DOT diff=astextplain
#*.pdf diff=astextplain
#*.PDF diff=astextplain
#*.rtf diff=astextplain
#*.RTF diff=astextplain

365
.gitignore vendored
View File

@@ -1,2 +1,363 @@
/.vscode
/bin
## Ignore Visual Studio temporary files, build results, and
## files generated by popular Visual Studio add-ons.
##
## Get latest from https://github.com/github/gitignore/blob/master/VisualStudio.gitignore
# User-specific files
*.rsuser
*.suo
*.user
*.userosscache
*.sln.docstates
# User-specific files (MonoDevelop/Xamarin Studio)
*.userprefs
# Mono auto generated files
mono_crash.*
# Build results
[Dd]ebug/
[Dd]ebugPublic/
[Rr]elease/
[Rr]eleases/
x64/
x86/
[Ww][Ii][Nn]32/
[Aa][Rr][Mm]/
[Aa][Rr][Mm]64/
bld/
[Bb]in/
[Oo]bj/
[Oo]ut/
[Ll]og/
[Ll]ogs/
# Visual Studio 2015/2017 cache/options directory
.vs/
# Uncomment if you have tasks that create the project's static files in wwwroot
#wwwroot/
# Visual Studio 2017 auto generated files
Generated\ Files/
# MSTest test Results
[Tt]est[Rr]esult*/
[Bb]uild[Ll]og.*
# NUnit
*.VisualState.xml
TestResult.xml
nunit-*.xml
# Build Results of an ATL Project
[Dd]ebugPS/
[Rr]eleasePS/
dlldata.c
# Benchmark Results
BenchmarkDotNet.Artifacts/
# .NET Core
project.lock.json
project.fragment.lock.json
artifacts/
# ASP.NET Scaffolding
ScaffoldingReadMe.txt
# StyleCop
StyleCopReport.xml
# Files built by Visual Studio
*_i.c
*_p.c
*_h.h
*.ilk
*.meta
*.obj
*.iobj
*.pch
*.pdb
*.ipdb
*.pgc
*.pgd
*.rsp
*.sbr
*.tlb
*.tli
*.tlh
*.tmp
*.tmp_proj
*_wpftmp.csproj
*.log
*.vspscc
*.vssscc
.builds
*.pidb
*.svclog
*.scc
# Chutzpah Test files
_Chutzpah*
# Visual C++ cache files
ipch/
*.aps
*.ncb
*.opendb
*.opensdf
*.sdf
*.cachefile
*.VC.db
*.VC.VC.opendb
# Visual Studio profiler
*.psess
*.vsp
*.vspx
*.sap
# Visual Studio Trace Files
*.e2e
# TFS 2012 Local Workspace
$tf/
# Guidance Automation Toolkit
*.gpState
# ReSharper is a .NET coding add-in
_ReSharper*/
*.[Rr]e[Ss]harper
*.DotSettings.user
# TeamCity is a build add-in
_TeamCity*
# DotCover is a Code Coverage Tool
*.dotCover
# AxoCover is a Code Coverage Tool
.axoCover/*
!.axoCover/settings.json
# Coverlet is a free, cross platform Code Coverage Tool
coverage*.json
coverage*.xml
coverage*.info
# Visual Studio code coverage results
*.coverage
*.coveragexml
# NCrunch
_NCrunch_*
.*crunch*.local.xml
nCrunchTemp_*
# MightyMoose
*.mm.*
AutoTest.Net/
# Web workbench (sass)
.sass-cache/
# Installshield output folder
[Ee]xpress/
# DocProject is a documentation generator add-in
DocProject/buildhelp/
DocProject/Help/*.HxT
DocProject/Help/*.HxC
DocProject/Help/*.hhc
DocProject/Help/*.hhk
DocProject/Help/*.hhp
DocProject/Help/Html2
DocProject/Help/html
# Click-Once directory
publish/
# Publish Web Output
*.[Pp]ublish.xml
*.azurePubxml
# Note: Comment the next line if you want to checkin your web deploy settings,
# but database connection strings (with potential passwords) will be unencrypted
*.pubxml
*.publishproj
# Microsoft Azure Web App publish settings. Comment the next line if you want to
# checkin your Azure Web App publish settings, but sensitive information contained
# in these scripts will be unencrypted
PublishScripts/
# NuGet Packages
*.nupkg
# NuGet Symbol Packages
*.snupkg
# The packages folder can be ignored because of Package Restore
**/[Pp]ackages/*
# except build/, which is used as an MSBuild target.
!**/[Pp]ackages/build/
# Uncomment if necessary however generally it will be regenerated when needed
#!**/[Pp]ackages/repositories.config
# NuGet v3's project.json files produces more ignorable files
*.nuget.props
*.nuget.targets
# Microsoft Azure Build Output
csx/
*.build.csdef
# Microsoft Azure Emulator
ecf/
rcf/
# Windows Store app package directories and files
AppPackages/
BundleArtifacts/
Package.StoreAssociation.xml
_pkginfo.txt
*.appx
*.appxbundle
*.appxupload
# Visual Studio cache files
# files ending in .cache can be ignored
*.[Cc]ache
# but keep track of directories ending in .cache
!?*.[Cc]ache/
# Others
ClientBin/
~$*
*~
*.dbmdl
*.dbproj.schemaview
*.jfm
*.pfx
*.publishsettings
orleans.codegen.cs
# Including strong name files can present a security risk
# (https://github.com/github/gitignore/pull/2483#issue-259490424)
#*.snk
# Since there are multiple workflows, uncomment next line to ignore bower_components
# (https://github.com/github/gitignore/pull/1529#issuecomment-104372622)
#bower_components/
# RIA/Silverlight projects
Generated_Code/
# Backup & report files from converting an old project file
# to a newer Visual Studio version. Backup files are not needed,
# because we have git ;-)
_UpgradeReport_Files/
Backup*/
UpgradeLog*.XML
UpgradeLog*.htm
ServiceFabricBackup/
*.rptproj.bak
# SQL Server files
*.mdf
*.ldf
*.ndf
# Business Intelligence projects
*.rdl.data
*.bim.layout
*.bim_*.settings
*.rptproj.rsuser
*- [Bb]ackup.rdl
*- [Bb]ackup ([0-9]).rdl
*- [Bb]ackup ([0-9][0-9]).rdl
# Microsoft Fakes
FakesAssemblies/
# GhostDoc plugin setting file
*.GhostDoc.xml
# Node.js Tools for Visual Studio
.ntvs_analysis.dat
node_modules/
# Visual Studio 6 build log
*.plg
# Visual Studio 6 workspace options file
*.opt
# Visual Studio 6 auto-generated workspace file (contains which files were open etc.)
*.vbw
# Visual Studio LightSwitch build output
**/*.HTMLClient/GeneratedArtifacts
**/*.DesktopClient/GeneratedArtifacts
**/*.DesktopClient/ModelManifest.xml
**/*.Server/GeneratedArtifacts
**/*.Server/ModelManifest.xml
_Pvt_Extensions
# Paket dependency manager
.paket/paket.exe
paket-files/
# FAKE - F# Make
.fake/
# CodeRush personal settings
.cr/personal
# Python Tools for Visual Studio (PTVS)
__pycache__/
*.pyc
# Cake - Uncomment if you are using it
# tools/**
# !tools/packages.config
# Tabs Studio
*.tss
# Telerik's JustMock configuration file
*.jmconfig
# BizTalk build output
*.btp.cs
*.btm.cs
*.odx.cs
*.xsd.cs
# OpenCover UI analysis results
OpenCover/
# Azure Stream Analytics local run output
ASALocalRun/
# MSBuild Binary and Structured Log
*.binlog
# NVidia Nsight GPU debugger configuration file
*.nvuser
# MFractors (Xamarin productivity tool) working folder
.mfractor/
# Local History for Visual Studio
.localhistory/
# BeatPulse healthcheck temp database
healthchecksdb
# Backup folder for Package Reference Convert tool in Visual Studio 2017
MigrationBackup/
# Ionide (cross platform F# VS Code tools) working folder
.ionide/
# Fody - auto-generated XML schema
FodyWeavers.xsd

View File

@@ -0,0 +1,15 @@
using Common;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace BusinessLogic.Algorithms
{
public abstract class Algorithm
{
public abstract void PutModelInCanonicalForm(Model model);
public abstract void Solve(Model model);
}
}

View File

@@ -0,0 +1,293 @@
using Common;
using Models;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace BusinessLogic.Algorithms
{
public class BranchAndBoundSimplex : Algorithm
{
private Model model;
public BinaryTree Results { get; set; } = new BinaryTree();
private DualSimplex dualSimplex = new DualSimplex();
private List<List<List<double>>> candidateSolutions = new List<List<List<double>>>();
public override void PutModelInCanonicalForm(Model model)
{
dualSimplex.PutModelInCanonicalForm(model);
Results.Add(model.Result);
}
public override void Solve(Model model)
{
this.model = model;
int level = 1;
while (level <= Results.GetHeight(Results.Root))
{
SolveCurrentLevel(Results.Root, level);
level++;
}
}
private void SolveCurrentLevel(BinaryTreeNode root, int level)
{
if (root == null)
return;
if (level == 1)
{
try
{
Solve(root);
Branch(root);
}
catch (InfeasibleException)
{
return;
}
}
else if (level > 1)
{
SolveCurrentLevel(root.LeftNode, level - 1);
SolveCurrentLevel(root.RightNode, level - 1);
}
}
public List<List<double>> GetBestCandidate()
{
double bestRHS = candidateSolutions[0][0][candidateSolutions[0][0].Count - 1];
List<List<double>> bestSolution = candidateSolutions[0];
for (int i = 1; i < candidateSolutions.Count; i++)
{
if (model.ProblemType == ProblemType.Maximization)
{
if (candidateSolutions[i][0][candidateSolutions[i][0].Count - 1] > bestRHS)
{
bestRHS = candidateSolutions[i][0][candidateSolutions[i][0].Count - 1];
bestSolution = candidateSolutions[i];
}
}
else
{
if (candidateSolutions[i][0][candidateSolutions[i][0].Count - 1] < bestRHS)
{
bestRHS = candidateSolutions[i][0][candidateSolutions[i][0].Count - 1];
bestSolution = candidateSolutions[i];
}
}
}
return bestSolution;
}
private void Solve(BinaryTreeNode root)
{
var model = new Model() { ProblemType = this.model.ProblemType, Result = root.Data };
dualSimplex.Solve(model);
}
private void Branch(BinaryTreeNode root)
{
if (CanBranch(root).Count == 0)
{
candidateSolutions.Add(root.Data[root.Data.Count - 1]);
}
else
{
// Get the variable we need to branch on
int branchVariableIndex = GetBranchVariable(root.Data[root.Data.Count - 1], CanBranch(root));
// Add the new constraints to the old table and add that resulting table to the binary tree
AddSubProblems(root, branchVariableIndex);
}
}
private void AddSubProblems(BinaryTreeNode root, int branchVariableIndex)
{
var table = root.Data[root.Data.Count - 1];
double rhs = GetRhsOfVariable(branchVariableIndex, table);
int constraintOneRhs;
int constraintTwoRhs;
constraintOneRhs = (int)Math.Truncate(rhs);
constraintTwoRhs = constraintOneRhs + 1;
var subProblemOneTable = ListCloner.CloneList(table);
var subProblemTwoTable = ListCloner.CloneList(table);
subProblemOneTable.Add(new List<double>());
subProblemTwoTable.Add(new List<double>());
for (int i = 0; i < subProblemOneTable[0].Count - 1; i++)
{
if (i == branchVariableIndex)
{
subProblemOneTable[subProblemOneTable.Count - 1].Add(1);
subProblemTwoTable[subProblemTwoTable.Count - 1].Add(-1);
}
else
{
subProblemOneTable[subProblemOneTable.Count - 1].Add(0);
subProblemTwoTable[subProblemTwoTable.Count - 1].Add(0);
}
}
subProblemOneTable[subProblemOneTable.Count - 1].Add(constraintOneRhs);
subProblemTwoTable[subProblemTwoTable.Count - 1].Add(constraintTwoRhs * -1);
for (int i = 0; i < subProblemOneTable.Count; i++)
{
var tempOne = subProblemOneTable[i][subProblemOneTable[i].Count - 1];
var tempTwo = subProblemTwoTable[i][subProblemTwoTable[i].Count - 1];
if (i == subProblemOneTable.Count - 1)
{
subProblemOneTable[i][subProblemOneTable[i].Count - 1] = 1;
subProblemTwoTable[i][subProblemTwoTable[i].Count - 1] = 1;
}
else
{
subProblemOneTable[i][subProblemOneTable[i].Count - 1] = 0;
subProblemTwoTable[i][subProblemTwoTable[i].Count - 1] = 0;
}
subProblemOneTable[i].Add(tempOne);
subProblemTwoTable[i].Add(tempTwo);
}
int subProblemBasicRow = GetBasicRow(table, branchVariableIndex);
for (int i = 0; i < subProblemOneTable[subProblemBasicRow].Count; i++)
{
subProblemOneTable[subProblemOneTable.Count - 1][i] -= subProblemOneTable[subProblemBasicRow][i];
subProblemTwoTable[subProblemTwoTable.Count - 1][i] += subProblemTwoTable[subProblemBasicRow][i];
}
Results.Add(new List<List<List<double>>>() { subProblemOneTable }, root.Data);
Results.Add(new List<List<List<double>>>() { subProblemTwoTable }, root.Data);
}
private int GetBasicRow(List<List<double>> table, int branchVariableIndex)
{
int basicRow = -1;
for (int i = 1; i < table.Count; i++)
{
if (table[i][branchVariableIndex] == 1)
{
basicRow = i;
break;
}
}
return basicRow;
}
private int GetBranchVariable(List<List<double>> table, List<int> intBinVarIndexes)
{
if (intBinVarIndexes.Count == 1)
return intBinVarIndexes[0];
int branchVariableIndex = -1;
decimal smallestFractionalPart = 1;
foreach (var intBinVar in intBinVarIndexes)
{
var rhs = (Decimal)GetRhsOfVariable(intBinVar, table);
decimal fractionalPart = rhs - Math.Truncate(rhs);
if (Math.Abs(0.5m - fractionalPart) < smallestFractionalPart)
{
smallestFractionalPart = Math.Abs(0.5m - fractionalPart);
branchVariableIndex = intBinVar;
}
}
return branchVariableIndex;
}
private List<int> CanBranch(BinaryTreeNode root)
{
var intBinVarIndexes = new List<int>();
var indexesToDiscard = new List<int>();
for (int i = 0; i < model.SignRestrictions.Count; i++)
{
if (model.SignRestrictions[i] == SignRestriction.Integer || model.SignRestrictions[i] == SignRestriction.Binary)
{
intBinVarIndexes.Add(i);
}
}
var table = root.Data[root.Data.Count - 1];
foreach (var intBinVar in intBinVarIndexes)
{
if (!IsVariableBasic(intBinVar, table))
{
indexesToDiscard.Add(intBinVar);
}
else
{
double rhs = GetRhsOfVariable(intBinVar, table);
if (rhs - Math.Truncate(rhs) < 0.00001)
{
indexesToDiscard.Add(intBinVar);
}
}
}
intBinVarIndexes.RemoveAll(v => indexesToDiscard.Contains(v) == true);
return intBinVarIndexes;
}
private double GetRhsOfVariable(int intBinVar, List<List<double>> table)
{
if (!IsVariableBasic(intBinVar, table))
return 0;
double rhs = 0;
for (int i = 1; i < table.Count; i++)
{
if (table[i][intBinVar] == 1)
{
rhs = table[i][table[i].Count - 1];
break;
}
}
return rhs;
}
private bool IsVariableBasic(int intBinVar, List<List<double>> table)
{
bool isBasic = true;
for (int i = 0; i < table.Count; i++)
{
int numberOfOnes = 0;
if (table[i][intBinVar] == 1)
numberOfOnes++;
if ((table[i][intBinVar] != 0 && table[i][intBinVar] != 1) || numberOfOnes > 1)
{
isBasic = false;
break;
}
}
return isBasic;
}
}
}

View File

@@ -0,0 +1,203 @@
using Common;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace BusinessLogic.Algorithms
{
public class CuttingPlane : Algorithm
{
private DualSimplex dualSimplex = new DualSimplex();
public override void PutModelInCanonicalForm(Model model)
{
dualSimplex.PutModelInCanonicalForm(model);
dualSimplex.Solve(model);
}
public override void Solve(Model model)
{
while (CanCut(model).Count > 0)
{
Cut(model);
dualSimplex.Solve(model);
}
}
private void Cut(Model model)
{
var table = model.Result[model.Result.Count - 1];
int cutVariableIndex = GetCutVariable(table, CanCut(model));
int basicRow = GetBasicRow(table, cutVariableIndex);
List<double> cutConstraint = GetCutConstraint(table, basicRow);
var newTable = ListCloner.CloneList(table);
newTable.Add(cutConstraint);
for (int i = 0; i < newTable.Count; i++)
{
if (i == newTable.Count - 1)
{
newTable[i].Insert(newTable[i].Count - 1, 1);
}
else
{
newTable[i].Insert(newTable[i].Count - 1, 0);
}
}
model.Result.Add(newTable);
}
private List<double> GetCutConstraint(List<List<double>> table, int basicRow)
{
List<double> cutConstraint = new List<double>();
for (int i = 0; i < table[basicRow].Count; i++)
{
if (table[basicRow][i] == Math.Truncate(table[basicRow][i]))
{
cutConstraint.Add(0);
}
else
{
double fractionalPart = Math.Abs(Math.Floor(table[basicRow][i]) - table[basicRow][i]);
cutConstraint.Add(-1 * fractionalPart);
}
}
return cutConstraint;
}
private List<int> CanCut(Model model)
{
List<int> intBinVarIndexes = new List<int>();
List<int> indexesToDiscard = new List<int>();
var lastTable = model.Result[model.Result.Count - 1];
for (int i = 0; i < model.SignRestrictions.Count; i++)
{
if (model.SignRestrictions[i] == SignRestriction.Integer || model.SignRestrictions[i] == SignRestriction.Binary)
{
intBinVarIndexes.Add(i);
}
}
foreach (var intBinVar in intBinVarIndexes)
{
if (!IsVariableBasic(intBinVar, lastTable))
{
indexesToDiscard.Add(intBinVar);
}
else
{
double rhs = GetRhsOfVariable(intBinVar, lastTable);
if (rhs - Math.Truncate(rhs) < 0.00001)
{
indexesToDiscard.Add(intBinVar);
}
}
}
intBinVarIndexes.RemoveAll(v => indexesToDiscard.Contains(v) == true);
return intBinVarIndexes;
}
private double GetRhsOfVariable(int intBinVar, List<List<double>> table)
{
if (!IsVariableBasic(intBinVar, table))
return 0;
double rhs = 0;
for (int i = 1; i < table.Count; i++)
{
if (table[i][intBinVar] == 1)
{
rhs = table[i][table[i].Count - 1];
break;
}
}
return rhs;
}
private bool IsVariableBasic(int intBinVar, List<List<double>> table)
{
bool isBasic = true;
for (int i = 0; i < table.Count; i++)
{
int numberOfOnes = 0;
if (table[i][intBinVar] == 1)
numberOfOnes++;
if ((table[i][intBinVar] != 0 && table[i][intBinVar] != 1) || numberOfOnes > 1)
{
isBasic = false;
break;
}
}
return isBasic;
}
private int GetCutVariable(List<List<double>> table, List<int> intBinVarIndexes)
{
if (intBinVarIndexes.Count == 1)
return intBinVarIndexes[0];
int branchVariableIndex = -1;
decimal smallestFractionalPart = 1;
foreach (var intBinVar in intBinVarIndexes)
{
var rhs = (Decimal)GetRhsOfVariable(intBinVar, table);
decimal fractionalPart = rhs - Math.Truncate(rhs);
if (Math.Abs(0.5m - fractionalPart) < smallestFractionalPart)
{
smallestFractionalPart = Math.Abs(0.5m - fractionalPart);
branchVariableIndex = intBinVar;
}
}
return branchVariableIndex;
}
private int GetBasicRow(List<List<double>> table, int variableIndex)
{
int basicRow = -1;
for (int i = 1; i < table.Count; i++)
{
if (table[i][variableIndex] == 1)
{
basicRow = i;
break;
}
}
return basicRow;
}
}
}

View File

@@ -0,0 +1,223 @@
using Common;
using Models;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace BusinessLogic.Algorithms
{
public class DualSimplex : Algorithm
{
public override void PutModelInCanonicalForm(Model model)
{
List<List<double>> tableZero = new List<List<double>>();
tableZero.Add(new List<double>());
foreach (var decVar in model.ObjectiveFunction.DecisionVariables)
{
tableZero[0].Add(decVar.Coefficient * -1);
}
for (int i = 0; i < model.Constraints.Count; i++)
{
tableZero[0].Add(0);
if (model.Constraints[i].InequalitySign == InequalitySign.EqualTo)
tableZero[0].Add(0);
}
tableZero[0].Add(0);
var equalsConstraints = model.Constraints.Where(c => c.InequalitySign == InequalitySign.EqualTo).ToList();
if (equalsConstraints?.Count() > 0)
{
for (int i = 0; i < equalsConstraints.Count(); i++)
{
model.Constraints[model.Constraints.FindIndex(c => c == equalsConstraints[i])].InequalitySign = InequalitySign.LessThanOrEqualTo;
var newConstraint = new Constraint();
newConstraint.InequalitySign = InequalitySign.GreaterThanOrEqualTo;
newConstraint.RightHandSide = equalsConstraints[i].RightHandSide;
foreach (var decVar in equalsConstraints[i].DecisionVariables)
{
newConstraint.DecisionVariables.Add(new DecisionVariable() { Coefficient = decVar.Coefficient });
}
model.Constraints.Add(newConstraint);
}
}
for (int i = 0; i < model.Constraints.Count; i++)
{
List<double> constraintValues = new List<double>();
foreach (var decVar in model.Constraints[i].DecisionVariables)
{
if (model.Constraints[i].InequalitySign == InequalitySign.LessThanOrEqualTo)
{
constraintValues.Add(decVar.Coefficient);
}
else
{
constraintValues.Add(decVar.Coefficient * -1);
}
}
for (int j = 0; j < model.Constraints.Count; j++)
{
if (j == i)
{
constraintValues.Add(1);
}
else
{
constraintValues.Add(0);
}
}
if (model.Constraints[i].InequalitySign == InequalitySign.LessThanOrEqualTo)
{
constraintValues.Add(model.Constraints[i].RightHandSide);
}
else
{
constraintValues.Add(model.Constraints[i].RightHandSide * -1);
}
tableZero.Add(constraintValues);
}
model.Result.Add(tableZero);
}
public override void Solve(Model model)
{
Iterate(model);
var primalSimplex = new PrimalSimplex();
primalSimplex.Solve(model);
}
private void Iterate(Model model)
{
if (!CanPivot(model))
return;
int pivotRow = GetPivotRow(model);
int pivotColumn = GetPivotColumn(model, pivotRow);
if (pivotColumn == -1)
throw new InfeasibleException("There is no suitable column to pivot on - the problem is infeasible");
Pivot(model, pivotRow, pivotColumn);
Iterate(model);
}
private bool CanPivot(Model model)
{
bool canPivot = false;
var table = model.Result[model.Result.Count - 1];
for (int i = 1; i < table.Count; i++)
{
if (table[i][table[i].Count - 1] < -0.000000000001)
{
canPivot = true;
break;
}
}
return canPivot;
}
private int GetPivotRow(Model model)
{
int pivotRow = -1;
var table = model.Result[model.Result.Count - 1];
double mostNegative = 0;
for (int i = 1; i < table.Count; i++)
{
if (table[i][table[i].Count - 1] < 0 && table[i][table[i].Count - 1] < mostNegative)
{
mostNegative = table[i][table[i].Count - 1];
pivotRow = i;
}
}
return pivotRow;
}
private int GetPivotColumn(Model model, int pivotRow)
{
int pivotColumn = -1;
var table = model.Result[model.Result.Count - 1];
double lowestRatio = double.MaxValue;
for (int i = 0; i < table[0].Count - 1; i++)
{
if (table[pivotRow][i] < 0)
{
double ratio = Math.Abs(table[0][i] / table[pivotRow][i]);
if (ratio < lowestRatio)
{
lowestRatio = ratio;
pivotColumn = i;
}
}
}
return pivotColumn;
}
private void Pivot(Model model, int pivotRow, int pivotColumn)
{
var previousTable = model.Result[model.Result.Count - 1];
var newTable = new List<List<double>>();
for (int i = 0; i < previousTable.Count; i++)
{
newTable.Add(new List<double>());
for (int j = 0; j < previousTable[i].Count; j++)
{
newTable[i].Add(previousTable[i][j]);
}
}
double factor = 1 / newTable[pivotRow][pivotColumn];
for (int i = 0; i < newTable[pivotRow].Count; i++)
{
newTable[pivotRow][i] *= factor;
}
double pivotColumnValue;
for (int i = 0; i < newTable.Count; i++)
{
pivotColumnValue = newTable[i][pivotColumn];
if (i != pivotRow && pivotColumnValue != 0)
{
for (int j = 0; j < newTable[i].Count; j++)
{
newTable[i][j] += (-1 * pivotColumnValue * newTable[pivotRow][j]);
}
}
}
model.Result.Add(newTable);
}
}
}

View File

@@ -0,0 +1,212 @@
using Common;
using Models;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace BusinessLogic.Algorithms
{
public class PrimalSimplex : Algorithm
{
public override void PutModelInCanonicalForm(Model model)
{
List<List<double>> tableZero = new List<List<double>>();
tableZero.Add(new List<double>());
foreach (var decVar in model.ObjectiveFunction.DecisionVariables)
{
tableZero[0].Add(decVar.Coefficient * -1);
}
for (int i = 0; i <= model.Constraints.Count; i++)
{
tableZero[0].Add(0);
}
for (int i = 0; i < model.Constraints.Count; i++)
{
List<double> constraintValues = new List<double>();
foreach (var decVar in model.Constraints[i].DecisionVariables)
{
constraintValues.Add(decVar.Coefficient);
}
for (int j = 0; j < model.Constraints.Count; j++)
{
if (j == i)
{
constraintValues.Add(1);
}
else
{
constraintValues.Add(0);
}
}
constraintValues.Add(model.Constraints[i].RightHandSide);
tableZero.Add(constraintValues);
}
model.Result.Add(tableZero);
}
public override void Solve(Model model)
{
Iterate(model);
}
private bool IsOptimal(Model model)
{
bool isOptimal = true;
var table = model.Result[model.Result.Count - 1];
if (model.ProblemType == ProblemType.Maximization)
{
for (int i = 0; i < table[0].Count - 1; i++)
{
if (table[0][i] < 0)
{
isOptimal = false;
break;
}
}
}
else
{
for (int i = 0; i < table[0].Count - 1; i++)
{
if (table[0][i] > 0)
{
isOptimal = false;
break;
}
}
}
return isOptimal;
}
private void Iterate(Model model)
{
if (IsOptimal(model))
return;
int pivotColumn = GetPivotColumn(model);
// Then get the pivot row
int pivotRow = GetPivotRow(model, pivotColumn);
if (pivotRow == -1)
throw new InfeasibleException("There is no suitable row to pivot on - the problem is infeasible");
Pivot(model, pivotRow, pivotColumn);
Iterate(model);
}
private void Pivot(Model model, int pivotRow, int pivotColumn)
{
var previousTable = model.Result[model.Result.Count - 1];
var newTable = new List<List<double>>();
for (int i = 0; i < previousTable.Count; i++)
{
newTable.Add(new List<double>());
for (int j = 0; j < previousTable[i].Count; j++)
{
newTable[i].Add(previousTable[i][j]);
}
}
double factor = 1 / newTable[pivotRow][pivotColumn];
for (int i = 0; i < newTable[pivotRow].Count; i++)
{
newTable[pivotRow][i] *= factor;
}
double pivotColumnValue;
for (int i = 0; i < newTable.Count; i++)
{
pivotColumnValue = newTable[i][pivotColumn];
if (i != pivotRow && pivotColumnValue != 0)
{
for (int j = 0; j < newTable[i].Count; j++)
{
newTable[i][j] += (-1 * pivotColumnValue * newTable[pivotRow][j]);
}
}
}
model.Result.Add(newTable);
}
private int GetPivotColumn(Model model)
{
int colIndex = -1;
var table = model.Result[model.Result.Count - 1];
if (model.ProblemType == ProblemType.Maximization)
{
double mostNegative = 0;
for (int i = 0; i < table[0].Count - 1; i++)
{
if (table[0][i] < 0 && table[0][i] < mostNegative)
{
mostNegative = table[0][i];
colIndex = i;
}
}
}
else
{
double mostPositive = 0;
for (int i = 0; i < table[0].Count - 1; i++)
{
if (table[0][i] > 0 && table[0][i] > mostPositive)
{
mostPositive = table[0][i];
colIndex = i;
}
}
}
return colIndex;
}
private int GetPivotRow(Model model, int pivotColumn)
{
int rowIndex = -1;
var table = model.Result[model.Result.Count - 1];
double lowestRatio = double.MaxValue;
for (int i = 1; i < table.Count; i++)
{
if (table[i][pivotColumn] > 0)
{
double ratio = table[i][table[i].Count - 1] / table[i][pivotColumn];
if (ratio < lowestRatio && ratio >= 0)
{
lowestRatio = ratio;
rowIndex = i;
}
}
}
return rowIndex;
}
}
}

View File

@@ -0,0 +1,346 @@
using Common;
using Models;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace BusinessLogic.Algorithms
{
public class TwoPhaseSimplex : Algorithm
{
private int numberOfArtificialVars = 0;
public override void PutModelInCanonicalForm(Model model)
{
for (int i = 0; i < model.Constraints.Count; i++)
{
if (model.Constraints[i].RightHandSide < 0)
{
for (int j = 0; j < model.Constraints[i].DecisionVariables.Count; j++)
{
model.Constraints[i].DecisionVariables[j].Coefficient *= -1;
}
model.Constraints[i].RightHandSide *= -1;
if (model.Constraints[i].InequalitySign == InequalitySign.LessThanOrEqualTo)
{
model.Constraints[i].InequalitySign = InequalitySign.GreaterThanOrEqualTo;
}
else if (model.Constraints[i].InequalitySign == InequalitySign.GreaterThanOrEqualTo)
{
model.Constraints[i].InequalitySign = InequalitySign.LessThanOrEqualTo;
}
}
}
List<List<double>> tableZero = new List<List<double>>();
tableZero.Add(new List<double>());
foreach (var decVar in model.ObjectiveFunction.DecisionVariables)
{
tableZero[0].Add(decVar.Coefficient * -1);
}
foreach (var constraint in model.Constraints)
{
if (constraint.InequalitySign == InequalitySign.LessThanOrEqualTo ||
constraint.InequalitySign == InequalitySign.GreaterThanOrEqualTo)
{
tableZero[0].Add(0);
}
if (constraint.InequalitySign == InequalitySign.EqualTo ||
constraint.InequalitySign == InequalitySign.GreaterThanOrEqualTo)
{
tableZero[0].Add(0);
}
}
tableZero[0].Add(0);
for (int i = 0; i < model.Constraints.Count; i++)
{
List<double> constraintValues = new List<double>();
foreach (var decVar in model.Constraints[i].DecisionVariables)
{
constraintValues.Add(decVar.Coefficient);
}
for (int j = 0; j < model.Constraints.Count; j++)
{
if (model.Constraints[j].InequalitySign == InequalitySign.LessThanOrEqualTo)
{
if (j == i)
{
constraintValues.Add(1);
}
else
{
constraintValues.Add(0);
}
}
else if (model.Constraints[j].InequalitySign == InequalitySign.GreaterThanOrEqualTo)
{
if (j == i)
{
constraintValues.Add(-1);
}
else
{
constraintValues.Add(0);
}
}
}
constraintValues.Add(model.Constraints[i].RightHandSide);
for (int j = 0; j < model.Constraints.Count; j++)
{
if (model.Constraints[j].InequalitySign == InequalitySign.EqualTo ||
model.Constraints[j].InequalitySign == InequalitySign.GreaterThanOrEqualTo)
{
if (j == i)
{
constraintValues.Insert(constraintValues.Count - 1, 1);
}
else
{
constraintValues.Insert(constraintValues.Count - 1, 0);
}
}
}
tableZero.Add(constraintValues);
}
numberOfArtificialVars = model.Constraints.Where(c => c.InequalitySign ==
InequalitySign.EqualTo || c.InequalitySign == InequalitySign.GreaterThanOrEqualTo).Count();
List<double> wRow = new List<double>();
for (int i = 0; i < tableZero[0].Count; i++)
{
wRow.Add(0);
}
for (int i = 1; i < tableZero.Count; i++)
{
if (model.Constraints[i - 1].InequalitySign == InequalitySign.EqualTo ||
model.Constraints[i - 1].InequalitySign == InequalitySign.GreaterThanOrEqualTo)
{
for (int j = 0; j < (tableZero[i].Count - numberOfArtificialVars - 1); j++)
{
wRow[j] += tableZero[i][j];
}
wRow[wRow.Count - 1] += tableZero[i][tableZero[i].Count - 1];
}
}
tableZero.Insert(0, wRow);
model.Result.Add(tableZero);
}
public override void Solve(Model model)
{
Iterate(model);
var lastTable = model.Result[model.Result.Count - 1];
if (lastTable[0][lastTable[0].Count - 1] > 0)
{
throw new InfeasibleException("The problem is infeasible");
}
bool allArtificialsNonBasic = true;
for (int i = lastTable[0].Count - (numberOfArtificialVars + 1); i < lastTable[0].Count - 1; i++)
{
if (IsVariableBasic(i, lastTable))
{
allArtificialsNonBasic = false;
break;
}
}
if (allArtificialsNonBasic)
{
lastTable.RemoveAt(0);
for (int i = 0; i < lastTable.Count; i++)
{
for (int j = 0; j < numberOfArtificialVars; j++)
{
lastTable[i].RemoveAt(lastTable[i].Count - 2);
}
}
}
else
{
for (int i = 0; i < model.ObjectiveFunction.DecisionVariables.Count; i++)
{
if (lastTable[0][i] < 0)
{
for (int j = 0; j < lastTable.Count; j++)
{
lastTable[j].RemoveAt(i);
}
}
}
for (int i = lastTable[0].Count - (numberOfArtificialVars + 1); i < lastTable[0].Count - 1; i++)
{
if (!IsVariableBasic(i, lastTable))
{
for (int j = 0; j < lastTable.Count; j++)
{
lastTable[j].RemoveAt(i);
}
}
}
lastTable.RemoveAt(0);
}
var primalSimplex = new PrimalSimplex();
primalSimplex.Solve(model);
}
private bool IsOptimal(Model model)
{
bool isOptimal = true;
var table = model.Result[model.Result.Count - 1];
for (int i = 0; i < table[0].Count - 1; i++)
{
if (table[0][i] > 0)
{
isOptimal = false;
break;
}
}
return isOptimal;
}
private void Iterate(Model model)
{
if (IsOptimal(model))
return;
int pivotColumn = GetPivotColumn(model);
int pivotRow = GetPivotRow(model, pivotColumn);
if (pivotRow == -1)
throw new InfeasibleException("There is no suitable row to pivot on - the problem is infeasible");
Pivot(model, pivotRow, pivotColumn);
Iterate(model);
}
private void Pivot(Model model, int pivotRow, int pivotColumn)
{
var previousTable = model.Result[model.Result.Count - 1];
var newTable = new List<List<double>>();
for (int i = 0; i < previousTable.Count; i++)
{
newTable.Add(new List<double>());
for (int j = 0; j < previousTable[i].Count; j++)
{
newTable[i].Add(previousTable[i][j]);
}
}
double factor = 1 / newTable[pivotRow][pivotColumn];
for (int i = 0; i < newTable[pivotRow].Count; i++)
{
newTable[pivotRow][i] *= factor;
}
double pivotColumnValue;
for (int i = 0; i < newTable.Count; i++)
{
pivotColumnValue = newTable[i][pivotColumn];
if (i != pivotRow && pivotColumnValue != 0)
{
for (int j = 0; j < newTable[i].Count; j++)
{
newTable[i][j] += (-1 * pivotColumnValue * newTable[pivotRow][j]);
}
}
}
model.Result.Add(newTable);
}
private int GetPivotColumn(Model model)
{
int colIndex = -1;
var table = model.Result[model.Result.Count - 1];
double mostPositive = 0;
for (int i = 0; i < table[0].Count - 1; i++)
{
if (table[0][i] > 0 && table[0][i] > mostPositive)
{
mostPositive = table[0][i];
colIndex = i;
}
}
return colIndex;
}
private int GetPivotRow(Model model, int pivotColumn)
{
int rowIndex = -1;
var table = model.Result[model.Result.Count - 1];
double lowestRatio = double.MaxValue;
for (int i = 1; i < table.Count; i++)
{
if (table[i][pivotColumn] > 0)
{
double ratio = table[i][table[i].Count - 1] / table[i][pivotColumn];
if (ratio < lowestRatio && ratio >= 0)
{
lowestRatio = ratio;
rowIndex = i;
}
}
}
return rowIndex;
}
private bool IsVariableBasic(int index, List<List<double>> table)
{
bool isBasic = true;
for (int i = 0; i < table.Count; i++)
{
int numberOfOnes = 0;
if (table[i][index] == 1)
numberOfOnes++;
if ((table[i][index] != 0 && table[i][index] != 1) || numberOfOnes > 1)
{
isBasic = false;
break;
}
}
return isBasic;
}
}
}

View File

@@ -0,0 +1,69 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace BusinessLogic
{
public class BinaryTree
{
public BinaryTreeNode Root { get; set; }
public void Add(List<List<List<double>>> subProblem, List<List<List<double>>> parentProblem = null)
{
BinaryTreeNode newNode = new BinaryTreeNode();
newNode.Data = subProblem;
if (Root == null)
{
Root = newNode;
return;
}
if (parentProblem != null)
{
BinaryTreeNode parentNode = Find(parentProblem);
if (parentNode != null && parentNode.LeftNode == null)
{
parentNode.LeftNode = newNode;
return;
}
if (parentNode != null && parentNode.RightNode == null)
{
parentNode.RightNode = newNode;
}
}
}
public BinaryTreeNode Find(List<List<List<double>>> subProblem)
{
return this.Find(subProblem, this.Root);
}
private BinaryTreeNode Find(List<List<List<double>>> subProblem, BinaryTreeNode parent)
{
if (parent == null)
return null;
if (parent.Data == subProblem)
{
return parent;
}
return Find(subProblem, parent.LeftNode) == null ? Find(subProblem, parent.RightNode) : Find(subProblem, parent.LeftNode);
}
public int GetHeight(BinaryTreeNode root)
{
if (root == null)
return 0;
int leftHeight = GetHeight(root.LeftNode);
int rightHeight = GetHeight(root.RightNode);
return leftHeight > rightHeight ? leftHeight + 1 : rightHeight + 1;
}
}
}

View File

@@ -0,0 +1,15 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace BusinessLogic
{
public class BinaryTreeNode
{
public BinaryTreeNode LeftNode { get; set; }
public BinaryTreeNode RightNode { get; set; }
public List<List<List<double>>> Data { get; set; }
}
}

View File

@@ -0,0 +1,67 @@
<?xml version="1.0" encoding="utf-8"?>
<Project ToolsVersion="15.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<Import Project="$(MSBuildExtensionsPath)\$(MSBuildToolsVersion)\Microsoft.Common.props" Condition="Exists('$(MSBuildExtensionsPath)\$(MSBuildToolsVersion)\Microsoft.Common.props')" />
<PropertyGroup>
<Configuration Condition=" '$(Configuration)' == '' ">Debug</Configuration>
<Platform Condition=" '$(Platform)' == '' ">AnyCPU</Platform>
<ProjectGuid>{F904DA9B-8BA5-4803-88C1-24A6471C7FEF}</ProjectGuid>
<OutputType>Library</OutputType>
<AppDesignerFolder>Properties</AppDesignerFolder>
<RootNamespace>BusinessLogic</RootNamespace>
<AssemblyName>BusinessLogic</AssemblyName>
<TargetFrameworkVersion>v4.8</TargetFrameworkVersion>
<FileAlignment>512</FileAlignment>
<Deterministic>true</Deterministic>
</PropertyGroup>
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|AnyCPU' ">
<DebugSymbols>true</DebugSymbols>
<DebugType>full</DebugType>
<Optimize>false</Optimize>
<OutputPath>bin\Debug\</OutputPath>
<DefineConstants>DEBUG;TRACE</DefineConstants>
<ErrorReport>prompt</ErrorReport>
<WarningLevel>4</WarningLevel>
</PropertyGroup>
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Release|AnyCPU' ">
<DebugType>pdbonly</DebugType>
<Optimize>true</Optimize>
<OutputPath>bin\Release\</OutputPath>
<DefineConstants>TRACE</DefineConstants>
<ErrorReport>prompt</ErrorReport>
<WarningLevel>4</WarningLevel>
</PropertyGroup>
<ItemGroup>
<Reference Include="System" />
<Reference Include="System.Core" />
<Reference Include="System.Xml.Linq" />
<Reference Include="System.Data.DataSetExtensions" />
<Reference Include="Microsoft.CSharp" />
<Reference Include="System.Data" />
<Reference Include="System.Net.Http" />
<Reference Include="System.Xml" />
</ItemGroup>
<ItemGroup>
<Compile Include="Algorithms\Algorithm.cs" />
<Compile Include="Algorithms\BranchAndBoundSimplex.cs" />
<Compile Include="Algorithms\CuttingPlane.cs" />
<Compile Include="Algorithms\DualSimplex.cs" />
<Compile Include="Algorithms\PrimalSimplex.cs" />
<Compile Include="Algorithms\TwoPhaseSimplex.cs" />
<Compile Include="BinaryTree.cs" />
<Compile Include="BinaryTreeNode.cs" />
<Compile Include="ListCloner.cs" />
<Compile Include="ModelSolver.cs" />
<Compile Include="Properties\AssemblyInfo.cs" />
</ItemGroup>
<ItemGroup>
<ProjectReference Include="..\DataAccess\DataAccess.csproj">
<Project>{02E85643-5DA8-4A1E-AF07-10184FC132A0}</Project>
<Name>DataAccess</Name>
</ProjectReference>
<ProjectReference Include="..\Models\Common.csproj">
<Project>{04C11623-F02E-45C6-8C51-82244CFF4780}</Project>
<Name>Common</Name>
</ProjectReference>
</ItemGroup>
<Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" />
</Project>

View File

@@ -0,0 +1,57 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace BusinessLogic
{
public class ListCloner
{
public static List<List<List<double>>> CloneList(List<List<List<double>>> oldList)
{
List<List<List<double>>> newList = new List<List<List<double>>>();
int iterationCount = oldList.Count;
int rowCount = oldList[0].Count;
int colCount = oldList[0][0].Count;
for (int i = 0; i < iterationCount; i++)
{
var table = new List<List<double>>();
for (int j = 0; j < rowCount; j++)
{
var row = new List<double>();
for (int k = 0; k < colCount; k++)
{
row.Add(oldList[i][j][k]);
}
table.Add(row);
}
newList.Add(table);
}
return newList;
}
public static List<List<double>> CloneList(List<List<double>> oldList)
{
List<List<double>> newList = new List<List<double>>();
int rowCount = oldList.Count;
int colCount = oldList[0].Count;
for (int i = 0; i < rowCount; i++)
{
var newRow = new List<double>();
for (int j = 0; j < colCount; j++)
{
newRow.Add(oldList[i][j]);
}
newList.Add(newRow);
}
return newList;
}
}
}

View File

@@ -0,0 +1,25 @@
using BusinessLogic.Algorithms;
using Common;
using DataAccess;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace BusinessLogic
{
public class ModelSolver
{
public static void Solve(Model model, Algorithm algorithm)
{
algorithm.PutModelInCanonicalForm(model);
algorithm.Solve(model);
Console.Clear();
Console.WriteLine("Here is the solution:");
Console.WriteLine("=========================================================================================================");
}
}
}

View File

@@ -0,0 +1,36 @@
using System.Reflection;
using System.Runtime.CompilerServices;
using System.Runtime.InteropServices;
// General Information about an assembly is controlled through the following
// set of attributes. Change these attribute values to modify the information
// associated with an assembly.
[assembly: AssemblyTitle("BusinessLogic")]
[assembly: AssemblyDescription("")]
[assembly: AssemblyConfiguration("")]
[assembly: AssemblyCompany("")]
[assembly: AssemblyProduct("BusinessLogic")]
[assembly: AssemblyCopyright("Copyright © 2021")]
[assembly: AssemblyTrademark("")]
[assembly: AssemblyCulture("")]
// Setting ComVisible to false makes the types in this assembly not visible
// to COM components. If you need to access a type in this assembly from
// COM, set the ComVisible attribute to true on that type.
[assembly: ComVisible(false)]
// The following GUID is for the ID of the typelib if this project is exposed to COM
[assembly: Guid("f904da9b-8ba5-4803-88c1-24a6471c7fef")]
// Version information for an assembly consists of the following four values:
//
// Major Version
// Minor Version
// Build Number
// Revision
//
// You can specify all the values or you can default the Build and Revision Numbers
// by using the '*' as shown below:
// [assembly: AssemblyVersion("1.0.*")]
[assembly: AssemblyVersion("1.0.0.0")]
[assembly: AssemblyFileVersion("1.0.0.0")]

View File

@@ -0,0 +1,77 @@
<?xml version="1.0" encoding="utf-8"?>
<Project ToolsVersion="15.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<Import Project="$(MSBuildExtensionsPath)\$(MSBuildToolsVersion)\Microsoft.Common.props" Condition="Exists('$(MSBuildExtensionsPath)\$(MSBuildToolsVersion)\Microsoft.Common.props')" />
<PropertyGroup>
<Configuration Condition=" '$(Configuration)' == '' ">Debug</Configuration>
<Platform Condition=" '$(Platform)' == '' ">AnyCPU</Platform>
<ProjectGuid>{02E85643-5DA8-4A1E-AF07-10184FC132A0}</ProjectGuid>
<OutputType>Library</OutputType>
<AppDesignerFolder>Properties</AppDesignerFolder>
<RootNamespace>DataAccess</RootNamespace>
<AssemblyName>DataAccess</AssemblyName>
<TargetFrameworkVersion>v4.8</TargetFrameworkVersion>
<FileAlignment>512</FileAlignment>
<Deterministic>true</Deterministic>
</PropertyGroup>
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|AnyCPU' ">
<DebugSymbols>true</DebugSymbols>
<DebugType>full</DebugType>
<Optimize>false</Optimize>
<OutputPath>bin\Debug\</OutputPath>
<DefineConstants>DEBUG;TRACE</DefineConstants>
<ErrorReport>prompt</ErrorReport>
<WarningLevel>4</WarningLevel>
</PropertyGroup>
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Release|AnyCPU' ">
<DebugType>pdbonly</DebugType>
<Optimize>true</Optimize>
<OutputPath>bin\Release\</OutputPath>
<DefineConstants>TRACE</DefineConstants>
<ErrorReport>prompt</ErrorReport>
<WarningLevel>4</WarningLevel>
</PropertyGroup>
<ItemGroup>
<Reference Include="System" />
<Reference Include="System.Core" />
<Reference Include="System.Xml.Linq" />
<Reference Include="System.Data.DataSetExtensions" />
<Reference Include="Microsoft.CSharp" />
<Reference Include="System.Data" />
<Reference Include="System.Net.Http" />
<Reference Include="System.Xml" />
</ItemGroup>
<ItemGroup>
<Compile Include="ModelReader.cs" />
<Compile Include="Properties\AssemblyInfo.cs" />
</ItemGroup>
<ItemGroup>
<ProjectReference Include="..\Models\Common.csproj">
<Project>{04C11623-F02E-45C6-8C51-82244CFF4780}</Project>
<Name>Common</Name>
</ProjectReference>
</ItemGroup>
<ItemGroup>
<Content Include="acme.txt">
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
</Content>
<Content Include="branch.txt">
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
</Content>
<Content Include="cut.txt">
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
</Content>
<Content Include="farmer.txt">
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
</Content>
<Content Include="korean.txt">
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
</Content>
<Content Include="limpopo.txt">
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
</Content>
<Content Include="santa.txt">
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
</Content>
</ItemGroup>
<Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" />
</Project>

164
DataAccess/ModelReader.cs Normal file
View File

@@ -0,0 +1,164 @@
using Common;
using Models;
using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace DataAccess
{
public class ModelReader
{
public static Model ReadModelFromFile(string path)
{
List<string> lines = new List<string>();
try
{
using (FileStream fileStream = new FileStream(path, FileMode.Open, FileAccess.Read))
{
using (StreamReader reader = new StreamReader(fileStream))
{
while (!reader.EndOfStream)
{
lines.Add(reader.ReadLine());
}
}
}
return ConvertToModel(lines);
}
catch (FileNotFoundException)
{
throw new CustomException("Could not find the specified file");
}
catch (DirectoryNotFoundException)
{
throw new CustomException("Could not find the specified directory");
}
catch (ArgumentException)
{
throw new CustomException("The specified path was invalid");
}
catch (IOException)
{
throw new CustomException("There was an error reading the specified file");
}
}
private static Model ConvertToModel(List<string> lines)
{
Model model = new Model();
try
{
if (lines.Count < 1)
{
throw new CustomException("The specified file is empty");
}
string[] objectiveFunction = lines[0].Split(' ');
if (!(objectiveFunction[0].ToLower().Equals("max") || objectiveFunction[0].ToLower().Equals("min")))
{
throw new CustomException("The given problem does not specify whether to maximize or minimize the objective function");
}
model.ProblemType = objectiveFunction[0].ToLower().Equals("max") ? ProblemType.Maximization : ProblemType.Minimization;
for (int i = 1; i < objectiveFunction.Length; i++)
{
model.ObjectiveFunction.DecisionVariables.Add(new DecisionVariable() { Coefficient = double.Parse(objectiveFunction[i]) });
}
if (lines.Count < 2)
{
throw new CustomException("The given problem does not contain any constraints");
}
for (int i = 1; i < lines.Count - 1; i++)
{
string[] constraintArr = lines[i].Split(' ');
Constraint constraint = new Constraint();
for (int j = 0; j < constraintArr.Length - 2; j++)
{
constraint.DecisionVariables.Add(new DecisionVariable() { Coefficient = double.Parse(constraintArr[j]) });
}
switch (constraintArr[constraintArr.Length - 2])
{
case "=":
{
constraint.InequalitySign = InequalitySign.EqualTo;
}
break;
case "<=":
{
constraint.InequalitySign = InequalitySign.LessThanOrEqualTo;
}
break;
case ">=":
{
constraint.InequalitySign = InequalitySign.GreaterThanOrEqualTo;
}
break;
default:
{
throw new CustomException($"Constraint {model.Constraints.Count + 1} does not have a valid inequality symbol");
}
}
constraint.RightHandSide = double.Parse(constraintArr[constraintArr.Length - 1]);
model.Constraints.Add(constraint);
}
string[] signRestrictions = lines[lines.Count - 1].Split(' ');
foreach (var restriction in signRestrictions)
{
switch (restriction.ToLower())
{
case "+":
{
model.SignRestrictions.Add(SignRestriction.Positive);
}
break;
case "-":
{
model.SignRestrictions.Add(SignRestriction.Negative);
}
break;
case "urs":
{
model.SignRestrictions.Add(SignRestriction.Unrestricted);
}
break;
case "int":
{
model.SignRestrictions.Add(SignRestriction.Integer);
}
break;
case "bin":
{
model.SignRestrictions.Add(SignRestriction.Binary);
}
break;
default:
{
throw new CustomException("Invalid sign restriction found");
}
}
}
}
catch (FormatException)
{
throw new CustomException("One of the decision variables has an invalid coefficient");
}
return model;
}
}
}

View File

@@ -0,0 +1,36 @@
using System.Reflection;
using System.Runtime.CompilerServices;
using System.Runtime.InteropServices;
// General Information about an assembly is controlled through the following
// set of attributes. Change these attribute values to modify the information
// associated with an assembly.
[assembly: AssemblyTitle("DataAccess")]
[assembly: AssemblyDescription("")]
[assembly: AssemblyConfiguration("")]
[assembly: AssemblyCompany("")]
[assembly: AssemblyProduct("DataAccess")]
[assembly: AssemblyCopyright("Copyright © 2021")]
[assembly: AssemblyTrademark("")]
[assembly: AssemblyCulture("")]
// Setting ComVisible to false makes the types in this assembly not visible
// to COM components. If you need to access a type in this assembly from
// COM, set the ComVisible attribute to true on that type.
[assembly: ComVisible(false)]
// The following GUID is for the ID of the typelib if this project is exposed to COM
[assembly: Guid("02e85643-5da8-4a1e-af07-10184fc132a0")]
// Version information for an assembly consists of the following four values:
//
// Major Version
// Minor Version
// Build Number
// Revision
//
// You can specify all the values or you can default the Build and Revision Numbers
// by using the '*' as shown below:
// [assembly: AssemblyVersion("1.0.*")]
[assembly: AssemblyVersion("1.0.0.0")]
[assembly: AssemblyFileVersion("1.0.0.0")]

5
DataAccess/acme.txt Normal file
View File

@@ -0,0 +1,5 @@
min +4 +1
+3 +1 >= 10
+1 +1 >= 5
+1 +0 >= 3
+ +

4
DataAccess/branch.txt Normal file
View File

@@ -0,0 +1,4 @@
max +8 +5
+1 +1 <= +6
+9 +5 <= +45
int int

4
DataAccess/cut.txt Normal file
View File

@@ -0,0 +1,4 @@
min +6 +8
+3 +1 >= 4
+1 +2 >= 4
int int

5
DataAccess/farmer.txt Normal file
View File

@@ -0,0 +1,5 @@
max +100 +30
+1 +1 <= +7
+10 +4 <= 40
+0 +1 >= 3
+ +

4
DataAccess/korean.txt Normal file
View File

@@ -0,0 +1,4 @@
min +50 +100
+7 +2 >= +28
+2 +12 >= +24
+ +

6
DataAccess/limpopo.txt Normal file
View File

@@ -0,0 +1,6 @@
max +60 +30 +20
+8 +6 +1 <= +48
+4 +2 +1,5 <= +20
+2 +1,5 +0,5 <= +8
+0 +1 +0 <= +5
+ + +

5
DataAccess/santa.txt Normal file
View File

@@ -0,0 +1,5 @@
max +3 +2
+2 +1 <= 100
+1 +1 <= 80
+1 +0 <= 40
+ +

49
LPR381_Project.sln Normal file
View File

@@ -0,0 +1,49 @@

Microsoft Visual Studio Solution File, Format Version 12.00
# Visual Studio Version 16
VisualStudioVersion = 16.0.31624.102
MinimumVisualStudioVersion = 10.0.40219.1
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Solve", "LPR381_Project\Solve.csproj", "{00C7750A-2297-460E-AABD-2AC53FFD1F17}"
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "BusinessLogic", "BusinessLogic\BusinessLogic.csproj", "{F904DA9B-8BA5-4803-88C1-24A6471C7FEF}"
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Presentation", "Presentation\Presentation.csproj", "{377D38FE-AA9D-4AB0-B743-9E80AA0C82C4}"
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "DataAccess", "DataAccess\DataAccess.csproj", "{02E85643-5DA8-4A1E-AF07-10184FC132A0}"
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Common", "Models\Common.csproj", "{04C11623-F02E-45C6-8C51-82244CFF4780}"
EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
Debug|Any CPU = Debug|Any CPU
Release|Any CPU = Release|Any CPU
EndGlobalSection
GlobalSection(ProjectConfigurationPlatforms) = postSolution
{00C7750A-2297-460E-AABD-2AC53FFD1F17}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{00C7750A-2297-460E-AABD-2AC53FFD1F17}.Debug|Any CPU.Build.0 = Debug|Any CPU
{00C7750A-2297-460E-AABD-2AC53FFD1F17}.Release|Any CPU.ActiveCfg = Release|Any CPU
{00C7750A-2297-460E-AABD-2AC53FFD1F17}.Release|Any CPU.Build.0 = Release|Any CPU
{F904DA9B-8BA5-4803-88C1-24A6471C7FEF}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{F904DA9B-8BA5-4803-88C1-24A6471C7FEF}.Debug|Any CPU.Build.0 = Debug|Any CPU
{F904DA9B-8BA5-4803-88C1-24A6471C7FEF}.Release|Any CPU.ActiveCfg = Release|Any CPU
{F904DA9B-8BA5-4803-88C1-24A6471C7FEF}.Release|Any CPU.Build.0 = Release|Any CPU
{377D38FE-AA9D-4AB0-B743-9E80AA0C82C4}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{377D38FE-AA9D-4AB0-B743-9E80AA0C82C4}.Debug|Any CPU.Build.0 = Debug|Any CPU
{377D38FE-AA9D-4AB0-B743-9E80AA0C82C4}.Release|Any CPU.ActiveCfg = Release|Any CPU
{377D38FE-AA9D-4AB0-B743-9E80AA0C82C4}.Release|Any CPU.Build.0 = Release|Any CPU
{02E85643-5DA8-4A1E-AF07-10184FC132A0}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{02E85643-5DA8-4A1E-AF07-10184FC132A0}.Debug|Any CPU.Build.0 = Debug|Any CPU
{02E85643-5DA8-4A1E-AF07-10184FC132A0}.Release|Any CPU.ActiveCfg = Release|Any CPU
{02E85643-5DA8-4A1E-AF07-10184FC132A0}.Release|Any CPU.Build.0 = Release|Any CPU
{04C11623-F02E-45C6-8C51-82244CFF4780}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{04C11623-F02E-45C6-8C51-82244CFF4780}.Debug|Any CPU.Build.0 = Debug|Any CPU
{04C11623-F02E-45C6-8C51-82244CFF4780}.Release|Any CPU.ActiveCfg = Release|Any CPU
{04C11623-F02E-45C6-8C51-82244CFF4780}.Release|Any CPU.Build.0 = Release|Any CPU
EndGlobalSection
GlobalSection(SolutionProperties) = preSolution
HideSolutionNode = FALSE
EndGlobalSection
GlobalSection(ExtensibilityGlobals) = postSolution
SolutionGuid = {9EF1E2C9-7C61-4DE5-8087-F1E388B2B976}
EndGlobalSection
EndGlobal

View File

@@ -0,0 +1,6 @@
<?xml version="1.0" encoding="utf-8" ?>
<configuration>
<startup>
<supportedRuntime version="v4.0" sku=".NETFramework,Version=v4.8" />
</startup>
</configuration>

20
LPR381_Project/Program.cs Normal file
View File

@@ -0,0 +1,20 @@
using DataAccess;
using Models;
using Presentation;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace LPR381_Project
{
class Program
{
static void Main(string[] args)
{
MainMenu.Run();
Console.ReadKey();
}
}
}

View File

@@ -0,0 +1,36 @@
using System.Reflection;
using System.Runtime.CompilerServices;
using System.Runtime.InteropServices;
// General Information about an assembly is controlled through the following
// set of attributes. Change these attribute values to modify the information
// associated with an assembly.
[assembly: AssemblyTitle("LPR381_Project")]
[assembly: AssemblyDescription("")]
[assembly: AssemblyConfiguration("")]
[assembly: AssemblyCompany("")]
[assembly: AssemblyProduct("LPR381_Project")]
[assembly: AssemblyCopyright("Copyright © 2021")]
[assembly: AssemblyTrademark("")]
[assembly: AssemblyCulture("")]
// Setting ComVisible to false makes the types in this assembly not visible
// to COM components. If you need to access a type in this assembly from
// COM, set the ComVisible attribute to true on that type.
[assembly: ComVisible(false)]
// The following GUID is for the ID of the typelib if this project is exposed to COM
[assembly: Guid("00c7750a-2297-460e-aabd-2ac53ffd1f17")]
// Version information for an assembly consists of the following four values:
//
// Major Version
// Minor Version
// Build Number
// Revision
//
// You can specify all the values or you can default the Build and Revision Numbers
// by using the '*' as shown below:
// [assembly: AssemblyVersion("1.0.*")]
[assembly: AssemblyVersion("1.0.0.0")]
[assembly: AssemblyFileVersion("1.0.0.0")]

View File

@@ -0,0 +1,67 @@
<?xml version="1.0" encoding="utf-8"?>
<Project ToolsVersion="15.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<Import Project="$(MSBuildExtensionsPath)\$(MSBuildToolsVersion)\Microsoft.Common.props" Condition="Exists('$(MSBuildExtensionsPath)\$(MSBuildToolsVersion)\Microsoft.Common.props')" />
<PropertyGroup>
<Configuration Condition=" '$(Configuration)' == '' ">Debug</Configuration>
<Platform Condition=" '$(Platform)' == '' ">AnyCPU</Platform>
<ProjectGuid>{00C7750A-2297-460E-AABD-2AC53FFD1F17}</ProjectGuid>
<OutputType>Exe</OutputType>
<RootNamespace>LPR381_Project</RootNamespace>
<AssemblyName>LPR381_Project</AssemblyName>
<TargetFrameworkVersion>v4.8</TargetFrameworkVersion>
<FileAlignment>512</FileAlignment>
<AutoGenerateBindingRedirects>true</AutoGenerateBindingRedirects>
<Deterministic>true</Deterministic>
</PropertyGroup>
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|AnyCPU' ">
<PlatformTarget>AnyCPU</PlatformTarget>
<DebugSymbols>true</DebugSymbols>
<DebugType>full</DebugType>
<Optimize>false</Optimize>
<OutputPath>bin\Debug\</OutputPath>
<DefineConstants>DEBUG;TRACE</DefineConstants>
<ErrorReport>prompt</ErrorReport>
<WarningLevel>4</WarningLevel>
</PropertyGroup>
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Release|AnyCPU' ">
<PlatformTarget>AnyCPU</PlatformTarget>
<DebugType>pdbonly</DebugType>
<Optimize>true</Optimize>
<OutputPath>bin\Release\</OutputPath>
<DefineConstants>TRACE</DefineConstants>
<ErrorReport>prompt</ErrorReport>
<WarningLevel>4</WarningLevel>
</PropertyGroup>
<ItemGroup>
<Reference Include="System" />
<Reference Include="System.Core" />
<Reference Include="System.Xml.Linq" />
<Reference Include="System.Data.DataSetExtensions" />
<Reference Include="Microsoft.CSharp" />
<Reference Include="System.Data" />
<Reference Include="System.Net.Http" />
<Reference Include="System.Xml" />
</ItemGroup>
<ItemGroup>
<Compile Include="Program.cs" />
<Compile Include="Properties\AssemblyInfo.cs" />
</ItemGroup>
<ItemGroup>
<None Include="App.config" />
</ItemGroup>
<ItemGroup>
<ProjectReference Include="..\DataAccess\DataAccess.csproj">
<Project>{02E85643-5DA8-4A1E-AF07-10184FC132A0}</Project>
<Name>DataAccess</Name>
</ProjectReference>
<ProjectReference Include="..\Models\Common.csproj">
<Project>{04C11623-F02E-45C6-8C51-82244CFF4780}</Project>
<Name>Common</Name>
</ProjectReference>
<ProjectReference Include="..\Presentation\Presentation.csproj">
<Project>{377D38FE-AA9D-4AB0-B743-9E80AA0C82C4}</Project>
<Name>Presentation</Name>
</ProjectReference>
</ItemGroup>
<Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" />
</Project>

56
Models/Common.csproj Normal file
View File

@@ -0,0 +1,56 @@
<?xml version="1.0" encoding="utf-8"?>
<Project ToolsVersion="15.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<Import Project="$(MSBuildExtensionsPath)\$(MSBuildToolsVersion)\Microsoft.Common.props" Condition="Exists('$(MSBuildExtensionsPath)\$(MSBuildToolsVersion)\Microsoft.Common.props')" />
<PropertyGroup>
<Configuration Condition=" '$(Configuration)' == '' ">Debug</Configuration>
<Platform Condition=" '$(Platform)' == '' ">AnyCPU</Platform>
<ProjectGuid>{04C11623-F02E-45C6-8C51-82244CFF4780}</ProjectGuid>
<OutputType>Library</OutputType>
<AppDesignerFolder>Properties</AppDesignerFolder>
<RootNamespace>Models</RootNamespace>
<AssemblyName>Models</AssemblyName>
<TargetFrameworkVersion>v4.8</TargetFrameworkVersion>
<FileAlignment>512</FileAlignment>
<Deterministic>true</Deterministic>
</PropertyGroup>
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|AnyCPU' ">
<DebugSymbols>true</DebugSymbols>
<DebugType>full</DebugType>
<Optimize>false</Optimize>
<OutputPath>bin\Debug\</OutputPath>
<DefineConstants>DEBUG;TRACE</DefineConstants>
<ErrorReport>prompt</ErrorReport>
<WarningLevel>4</WarningLevel>
</PropertyGroup>
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Release|AnyCPU' ">
<DebugType>pdbonly</DebugType>
<Optimize>true</Optimize>
<OutputPath>bin\Release\</OutputPath>
<DefineConstants>TRACE</DefineConstants>
<ErrorReport>prompt</ErrorReport>
<WarningLevel>4</WarningLevel>
</PropertyGroup>
<ItemGroup>
<Reference Include="System" />
<Reference Include="System.Core" />
<Reference Include="System.Xml.Linq" />
<Reference Include="System.Data.DataSetExtensions" />
<Reference Include="Microsoft.CSharp" />
<Reference Include="System.Data" />
<Reference Include="System.Net.Http" />
<Reference Include="System.Xml" />
</ItemGroup>
<ItemGroup>
<Compile Include="Constraint.cs" />
<Compile Include="CustomException.cs" />
<Compile Include="DecisionVariable.cs" />
<Compile Include="InequalitySign.cs" />
<Compile Include="InfeasibleException.cs" />
<Compile Include="Model.cs" />
<Compile Include="ObjectiveFunction.cs" />
<Compile Include="ProblemType.cs" />
<Compile Include="Properties\AssemblyInfo.cs" />
<Compile Include="SignRestriction.cs" />
</ItemGroup>
<Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" />
</Project>

15
Models/Constraint.cs Normal file
View File

@@ -0,0 +1,15 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace Common
{
public class Constraint
{
public List<DecisionVariable> DecisionVariables { get; set; } = new List<DecisionVariable>();
public InequalitySign InequalitySign { get; set; }
public double RightHandSide { get; set; }
}
}

20
Models/CustomException.cs Normal file
View File

@@ -0,0 +1,20 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace Models
{
[Serializable]
public class CustomException : Exception
{
public CustomException() { }
public CustomException(string message) : base(message) { }
public CustomException(string message, Exception inner) : base(message, inner) { }
protected CustomException(
System.Runtime.Serialization.SerializationInfo info,
System.Runtime.Serialization.StreamingContext context) : base(info, context) { }
}
}

View File

@@ -0,0 +1,13 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace Common
{
public class DecisionVariable
{
public double Coefficient { get; set; }
}
}

15
Models/InequalitySign.cs Normal file
View File

@@ -0,0 +1,15 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace Common
{
public enum InequalitySign
{
EqualTo,
LessThanOrEqualTo,
GreaterThanOrEqualTo
}
}

View File

@@ -0,0 +1,20 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace Models
{
[Serializable]
public class InfeasibleException : Exception
{
public InfeasibleException() { }
public InfeasibleException(string message) : base(message) { }
public InfeasibleException(string message, Exception inner) : base(message, inner) { }
protected InfeasibleException(
System.Runtime.Serialization.SerializationInfo info,
System.Runtime.Serialization.StreamingContext context) : base(info, context) { }
}
}

29
Models/Model.cs Normal file
View File

@@ -0,0 +1,29 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace Common
{
public class Model
{
public Model() { }
// A copy constructor so that we can clone Model objects without reference
public Model(Model model)
{
this.ProblemType = model.ProblemType;
this.ObjectiveFunction = model.ObjectiveFunction;
this.Constraints = model.Constraints;
this.SignRestrictions = model.SignRestrictions;
this.Result = model.Result;
}
public ProblemType ProblemType { get; set; }
public ObjectiveFunction ObjectiveFunction { get; set; } = new ObjectiveFunction();
public List<Constraint> Constraints { get; set; } = new List<Constraint>();
public List<SignRestriction> SignRestrictions { get; set; } = new List<SignRestriction>();
public List<List<List<double>>> Result { get; set; } = new List<List<List<double>>>();
}
}

View File

@@ -0,0 +1,13 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace Common
{
public class ObjectiveFunction
{
public List<DecisionVariable> DecisionVariables { get; set; } = new List<DecisionVariable>();
}
}

14
Models/ProblemType.cs Normal file
View File

@@ -0,0 +1,14 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace Common
{
public enum ProblemType
{
Maximization,
Minimization
}
}

View File

@@ -0,0 +1,36 @@
using System.Reflection;
using System.Runtime.CompilerServices;
using System.Runtime.InteropServices;
// General Information about an assembly is controlled through the following
// set of attributes. Change these attribute values to modify the information
// associated with an assembly.
[assembly: AssemblyTitle("Models")]
[assembly: AssemblyDescription("")]
[assembly: AssemblyConfiguration("")]
[assembly: AssemblyCompany("")]
[assembly: AssemblyProduct("Models")]
[assembly: AssemblyCopyright("Copyright © 2021")]
[assembly: AssemblyTrademark("")]
[assembly: AssemblyCulture("")]
// Setting ComVisible to false makes the types in this assembly not visible
// to COM components. If you need to access a type in this assembly from
// COM, set the ComVisible attribute to true on that type.
[assembly: ComVisible(false)]
// The following GUID is for the ID of the typelib if this project is exposed to COM
[assembly: Guid("04c11623-f02e-45c6-8c51-82244cff4780")]
// Version information for an assembly consists of the following four values:
//
// Major Version
// Minor Version
// Build Number
// Revision
//
// You can specify all the values or you can default the Build and Revision Numbers
// by using the '*' as shown below:
// [assembly: AssemblyVersion("1.0.*")]
[assembly: AssemblyVersion("1.0.0.0")]
[assembly: AssemblyFileVersion("1.0.0.0")]

17
Models/SignRestriction.cs Normal file
View File

@@ -0,0 +1,17 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace Common
{
public enum SignRestriction
{
Positive,
Negative,
Unrestricted,
Integer,
Binary
}
}

180
Presentation/MainMenu.cs Normal file
View File

@@ -0,0 +1,180 @@
using BusinessLogic;
using BusinessLogic.Algorithms;
using Common;
using DataAccess;
using Models;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace Presentation
{
public class MainMenu
{
public static void Run()
{
Model model = new Model();
try
{
Console.Clear();
Console.WriteLine("Welcome to the solver");
Console.WriteLine("=========================================================================================================");
Console.WriteLine("To get started, choose a premade text file that contains the model you would like to solve:");
Console.WriteLine("\nlimpopo.txt\nsanta.txt\nkorean.txt\nfarmer.txt\nbranch.txt\ncut.txt\nacme.txt\n");
string modelPath = Console.ReadLine();
Console.WriteLine("=========================================================================================================");
model = ModelReader.ReadModelFromFile(modelPath);
SolveModelUsingAlgorithm(model);
}
catch (CustomException ex)
{
Console.WriteLine($"There was an error. Details: {ex.Message}.");
Console.WriteLine("\nHere are the tables that were calculated before we ran into that error:");
SolvedModelPrinter.Print(model);
Console.WriteLine("\n\nPress any key to continue. . .");
Console.ReadKey();
Run();
}
catch (InfeasibleException ex)
{
Console.WriteLine($"There was an error. Details: {ex.Message}.");
Console.WriteLine("\nHere are the tables that were calculated before we ran into that error:");
SolvedModelPrinter.Print(model);
Console.WriteLine("\n\nPress any key to continue. . .");
Console.ReadKey();
Run();
}
catch (Exception ex)
{
Console.WriteLine($"There was an error. Details: {ex.Message}.");
Console.WriteLine("\nHere are the tables that were calculated before we ran into that error:");
SolvedModelPrinter.Print(model);
Console.WriteLine("\n\nPress any key to continue. . .");
Console.ReadKey();
Run();
}
}
private static void SolveModelUsingAlgorithm(Model model)
{
Console.Clear();
Console.WriteLine("Great! Now that we have your model, the next step is to choose an algorithm to solve it with.");
Console.WriteLine("Based on factors in your model, these are the available algorithms you can use:");
Console.WriteLine("=========================================================================================================");
string userInput;
Algorithm algorithm;
if (model.SignRestrictions.Contains(SignRestriction.Binary) || model.SignRestrictions.Contains(SignRestriction.Integer))
{
Console.WriteLine("BNB - Branch and Bound Simplex Algorithm");
Console.WriteLine("CP - Cutting Plane Algorithm");
userInput = Console.ReadLine();
switch (userInput.ToUpper())
{
case "BNB":
{
algorithm = new BranchAndBoundSimplex();
}
break;
case "CP":
{
algorithm = new CuttingPlane();
}
break;
default:
{
throw new CustomException("Invalid selection made");
}
}
}
else if (model.ProblemType == ProblemType.Minimization)
{
Console.WriteLine("DS - Dual Simplex Algorithm");
Console.WriteLine("TPS - Two Phase Simplex Algorithm");
userInput = Console.ReadLine();
switch (userInput.ToUpper())
{
case "DS":
{
algorithm = new DualSimplex();
}
break;
case "TPS":
{
algorithm = new TwoPhaseSimplex();
}
break;
default:
{
throw new CustomException("Invalid selection made");
}
}
}
else
{
if (!(model.Constraints.Any(c => c.InequalitySign == InequalitySign.EqualTo) ||
model.Constraints.Any(c => c.InequalitySign == InequalitySign.GreaterThanOrEqualTo)))
{
Console.WriteLine("PS - Primal Simplex");
userInput = Console.ReadLine();
switch (userInput.ToUpper())
{
case "PS":
{
algorithm = new PrimalSimplex();
}
break;
default:
{
throw new CustomException("Invalid selection made");
}
}
}
else
{
Console.WriteLine("DS - Dual Simplex Algorithm");
Console.WriteLine("TPS - Two Phase Simplex Algorithm");
userInput = Console.ReadLine();
switch (userInput.ToUpper())
{
case "DS":
{
algorithm = new DualSimplex();
}
break;
case "TPS":
{
algorithm = new TwoPhaseSimplex();
}
break;
default:
{
throw new CustomException("Invalid selection made");
}
}
}
}
ModelSolver.Solve(model, algorithm);
if (algorithm.GetType() == typeof(BranchAndBoundSimplex))
{
SolvedModelPrinter.Print((BranchAndBoundSimplex)algorithm);
ModelWriter.WriteResultsToFile((BranchAndBoundSimplex)algorithm);
}
else
{
SolvedModelPrinter.Print(model);
ModelWriter.WriteResultsToFile(model);
}
}
}
}

121
Presentation/ModelWriter.cs Normal file
View File

@@ -0,0 +1,121 @@
using BusinessLogic.Algorithms;
using Common;
using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace Presentation
{
public class ModelWriter
{
public static void WriteResultsToFile(Model model)
{
var fileName = Guid.NewGuid().ToString() + ".txt";
using (FileStream stream = new FileStream(fileName, FileMode.Create, FileAccess.Write))
{
using (StreamWriter writer = new StreamWriter(stream))
{
int iteration = 0;
foreach (var table in model.Result)
{
writer.WriteLine($"\n\nTable {iteration}:");
for (int i = 0; i < table.Count; i++)
{
for (int j = 0; j < table[0].Count; j++)
{
writer.Write($"\t{table[i][j]:0.###}");
}
writer.WriteLine();
}
iteration++;
}
}
}
Console.WriteLine($"\n\nThe results have been written to the file: {fileName}");
}
public static void WriteResultsToFile(BranchAndBoundSimplex branchAndBoundSimplex)
{
var fileName = Guid.NewGuid().ToString() + ".txt";
using (FileStream stream = new FileStream(fileName, FileMode.Create, FileAccess.Write))
{
using (StreamWriter writer = new StreamWriter(stream))
{
var tree = branchAndBoundSimplex.Results;
WriteBranchResults(tree.Root, writer);
List<List<double>> bestCandidate = branchAndBoundSimplex.GetBestCandidate();
writer.WriteLine("\n\nThis is the best solution of all the candidates:\n");
for (int i = 0; i < bestCandidate.Count; i++)
{
for (int j = 0; j < bestCandidate[i].Count; j++)
{
writer.Write($"\t{bestCandidate[i][j]:0.###}");
}
writer.WriteLine();
}
}
}
Console.WriteLine($"\n\nThe results have been written to the file: {fileName}");
}
private static void WriteBranchResults(BusinessLogic.BinaryTreeNode root, StreamWriter writer, string previousProblem = "0")
{
if (root == null)
return;
if (previousProblem.Equals("0"))
{
writer.WriteLine("\n\n");
writer.WriteLine("Sub-Problem 0");
for (int i = 0; i < root.Data.Count; i++)
{
for (int j = 0; j < root.Data[i].Count; j++)
{
for (int k = 0; k < root.Data[i][j].Count; k++)
{
writer.Write($"\t{root.Data[i][j][k]:0.###}");
}
writer.WriteLine();
}
writer.WriteLine("\n\n");
}
WriteBranchResults(root.LeftNode, writer, "1");
WriteBranchResults(root.RightNode, writer, "2");
}
else
{
writer.WriteLine("\n\n");
writer.WriteLine($"Sub-Problem {previousProblem}");
for (int i = 0; i < root.Data.Count; i++)
{
for (int j = 0; j < root.Data[i].Count; j++)
{
for (int k = 0; k < root.Data[i][j].Count; k++)
{
writer.Write($"\t{root.Data[i][j][k]:0.###}");
}
writer.WriteLine();
}
writer.WriteLine("\n\n");
}
WriteBranchResults(root.LeftNode, writer, previousProblem + ".1");
WriteBranchResults(root.RightNode, writer, previousProblem + ".2");
}
}
}
}

View File

@@ -0,0 +1,70 @@
<?xml version="1.0" encoding="utf-8"?>
<Project ToolsVersion="15.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<Import Project="$(MSBuildExtensionsPath)\$(MSBuildToolsVersion)\Microsoft.Common.props" Condition="Exists('$(MSBuildExtensionsPath)\$(MSBuildToolsVersion)\Microsoft.Common.props')" />
<PropertyGroup>
<Configuration Condition=" '$(Configuration)' == '' ">Debug</Configuration>
<Platform Condition=" '$(Platform)' == '' ">AnyCPU</Platform>
<ProjectGuid>{377D38FE-AA9D-4AB0-B743-9E80AA0C82C4}</ProjectGuid>
<OutputType>Library</OutputType>
<AppDesignerFolder>Properties</AppDesignerFolder>
<RootNamespace>Presentation</RootNamespace>
<AssemblyName>Presentation</AssemblyName>
<TargetFrameworkVersion>v4.8</TargetFrameworkVersion>
<FileAlignment>512</FileAlignment>
<Deterministic>true</Deterministic>
</PropertyGroup>
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|AnyCPU' ">
<DebugSymbols>true</DebugSymbols>
<DebugType>full</DebugType>
<Optimize>false</Optimize>
<OutputPath>bin\Debug\</OutputPath>
<DefineConstants>DEBUG;TRACE</DefineConstants>
<ErrorReport>prompt</ErrorReport>
<WarningLevel>4</WarningLevel>
</PropertyGroup>
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Release|AnyCPU' ">
<DebugType>pdbonly</DebugType>
<Optimize>true</Optimize>
<OutputPath>bin\Release\</OutputPath>
<DefineConstants>TRACE</DefineConstants>
<ErrorReport>prompt</ErrorReport>
<WarningLevel>4</WarningLevel>
</PropertyGroup>
<ItemGroup>
<Reference Include="ConsoleTables, Version=2.0.0.0, Culture=neutral, processorArchitecture=MSIL">
<HintPath>..\packages\ConsoleTables.2.4.2\lib\net40\ConsoleTables.dll</HintPath>
</Reference>
<Reference Include="System" />
<Reference Include="System.Core" />
<Reference Include="System.Xml.Linq" />
<Reference Include="System.Data.DataSetExtensions" />
<Reference Include="Microsoft.CSharp" />
<Reference Include="System.Data" />
<Reference Include="System.Net.Http" />
<Reference Include="System.Xml" />
</ItemGroup>
<ItemGroup>
<Compile Include="MainMenu.cs" />
<Compile Include="ModelWriter.cs" />
<Compile Include="Properties\AssemblyInfo.cs" />
<Compile Include="SolvedModelPrinter.cs" />
</ItemGroup>
<ItemGroup>
<ProjectReference Include="..\BusinessLogic\BusinessLogic.csproj">
<Project>{F904DA9B-8BA5-4803-88C1-24A6471C7FEF}</Project>
<Name>BusinessLogic</Name>
</ProjectReference>
<ProjectReference Include="..\DataAccess\DataAccess.csproj">
<Project>{02E85643-5DA8-4A1E-AF07-10184FC132A0}</Project>
<Name>DataAccess</Name>
</ProjectReference>
<ProjectReference Include="..\Models\Common.csproj">
<Project>{04C11623-F02E-45C6-8C51-82244CFF4780}</Project>
<Name>Common</Name>
</ProjectReference>
</ItemGroup>
<ItemGroup>
<None Include="packages.config" />
</ItemGroup>
<Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" />
</Project>

View File

@@ -0,0 +1,36 @@
using System.Reflection;
using System.Runtime.CompilerServices;
using System.Runtime.InteropServices;
// General Information about an assembly is controlled through the following
// set of attributes. Change these attribute values to modify the information
// associated with an assembly.
[assembly: AssemblyTitle("Presentation")]
[assembly: AssemblyDescription("")]
[assembly: AssemblyConfiguration("")]
[assembly: AssemblyCompany("")]
[assembly: AssemblyProduct("Presentation")]
[assembly: AssemblyCopyright("Copyright © 2021")]
[assembly: AssemblyTrademark("")]
[assembly: AssemblyCulture("")]
// Setting ComVisible to false makes the types in this assembly not visible
// to COM components. If you need to access a type in this assembly from
// COM, set the ComVisible attribute to true on that type.
[assembly: ComVisible(false)]
// The following GUID is for the ID of the typelib if this project is exposed to COM
[assembly: Guid("377d38fe-aa9d-4ab0-b743-9e80aa0c82c4")]
// Version information for an assembly consists of the following four values:
//
// Major Version
// Minor Version
// Build Number
// Revision
//
// You can specify all the values or you can default the Build and Revision Numbers
// by using the '*' as shown below:
// [assembly: AssemblyVersion("1.0.*")]
[assembly: AssemblyVersion("1.0.0.0")]
[assembly: AssemblyFileVersion("1.0.0.0")]

View File

@@ -0,0 +1,112 @@
using BusinessLogic;
using BusinessLogic.Algorithms;
using Common;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using ConsoleTables;
namespace Presentation
{
public class SolvedModelPrinter
{
public static void Print(Model model)
{
int iteration = 0;
foreach (var table in model.Result)
{
Console.WriteLine($"\n\nTable {iteration}:");
string[] headers = new string[table[0].Count];
string temp = "";
for (int j = 0; j < table[0].Count; j++)
{
temp = table[0][j].ToString();
headers[j] = temp;
}
table.RemoveAt(0);
var conTable = new ConsoleTable(headers);
foreach (List<double> row in table)
{
object[] rowArray = new object[row.Count];
for (int i = 0; i < row.Count; i++)
{
rowArray[i] = row[i];
}
conTable.AddRow(rowArray);
}
Console.WriteLine();
iteration++;
conTable.Write(Format.Alternative);
}
}
public static void Print(BranchAndBoundSimplex branchAndBoundSimplex)
{
var tree = branchAndBoundSimplex.Results;
PrintBranchResults(tree.Root);
List<List<double>> bestCandidate = branchAndBoundSimplex.GetBestCandidate();
Console.WriteLine("\n\nThis is the best solution of all the candidates:\n");
for (int i = 0; i < bestCandidate.Count; i++)
{
for (int j = 0; j < bestCandidate[i].Count; j++)
{
Console.Write($"\t{bestCandidate[i][j]:0.###}");
}
Console.WriteLine();
}
}
private static void PrintBranchResults(BinaryTreeNode root, string previousProblem = "0")
{
if (root == null)
return;
if (previousProblem.Equals("0"))
{
Console.WriteLine("\n\n");
Console.WriteLine("Sub-Problem 0");
for (int i = 0; i < root.Data.Count; i++)
{
for (int j = 0; j < root.Data[i].Count; j++)
{
for (int k = 0; k < root.Data[i][j].Count; k++)
{
Console.Write($"\t{root.Data[i][j][k]:0.###}");
}
Console.WriteLine();
}
Console.WriteLine("\n\n");
}
PrintBranchResults(root.LeftNode, "1");
PrintBranchResults(root.RightNode, "2");
}
else
{
Console.WriteLine("\n\n");
Console.WriteLine($"Sub-Problem {previousProblem}");
for (int i = 0; i < root.Data.Count; i++)
{
for (int j = 0; j < root.Data[i].Count; j++)
{
for (int k = 0; k < root.Data[i][j].Count; k++)
{
Console.Write($"\t{root.Data[i][j][k]:0.###}");
}
Console.WriteLine();
}
Console.WriteLine("\n\n");
}
PrintBranchResults(root.LeftNode, previousProblem + ".1");
PrintBranchResults(root.RightNode, previousProblem + ".2");
}
}
}
}

View File

@@ -0,0 +1,4 @@
<?xml version="1.0" encoding="utf-8"?>
<packages>
<package id="ConsoleTables" version="2.4.2" targetFramework="net48" />
</packages>

View File

@@ -1,16 +0,0 @@

class lpr381
{
static void Main()
{
//simplex simplex = new simplex();
//simplex.simplexAlgo();
//twoPhaseSimplex twoPhaseSimplex = new twoPhaseSimplex();
//twoPhaseSimplex.twoPhaseSimplexAlgo();
//chesssolver chesssolver = new chesssolver();
//chesssolver.chessAlgo();
dualSimplex dualSimplex = new dualSimplex();
dualSimplex.dualSimplexAlgo();
}
}

View File

@@ -1,65 +0,0 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
class chesssolver
{
static int N;
static void printBoard(int[,] board)
{
for (int i = 0; i < N; i++)
{
for (int j = 0; j < N; j++)
{
Console.Write(board[i, j] + " ");
}
Console.Write("\n");
}
}
static Boolean toPlaceOrNotToPlace(int[,] board, int row, int col)
{
int i, j;
for (i = 0; i < col; i++)
{
if (board[row, i] == 1) return false;
}
for (i = row, j = col; i >= 0 && j >= 0; i--, j--)
{
if (board[i, j] == 1) return false;
}
for (i = row, j = col; j >= 0 && i < N; i++, j--)
{
if (board[i, j] == 1) return false;
}
return true;
}
static Boolean theBoardSolver(int[,] board, int col)
{
if (col >= N) return true;
for (int i = 0; i < N; i++)
{
if (toPlaceOrNotToPlace(board, i, col))
{
board[i, col] = 1;
if (theBoardSolver(board, col + 1)) return true;
board[i, col] = 0;
}
}
return false;
}
public void chessAlgo()
{
Console.WriteLine("state size of chess table example: 4");
N = Convert.ToInt32(Console.ReadLine());
int[,] board = new int[N, N];
if (!theBoardSolver(board, 0))
{
Console.WriteLine("Solution not found.");
}
printBoard(board);
Console.ReadLine();
}
}

View File

@@ -1,223 +0,0 @@
using ConsoleTables;
class dualSimplex
{
public void dualSimplexAlgo()
{
file file = new file();
Tuple<List<zConstraints>, List<Constraints>> content = file.readFile();
List<zConstraints> zConstraintsList = content.Item1;
List<Constraints> constraintsList = content.Item2;
// print constraintsList
foreach (zConstraints constraints in zConstraintsList)
{
Console.WriteLine(constraints.minMax + " " + string.Join(" ", constraints.values));
}
foreach (Constraints constraints in constraintsList)
{
Console.WriteLine(constraints.sign + " " + string.Join(" ", constraints.values));
}
List<List<float>> table = new List<List<float>>();
table.Add(zConstraintsList[0].values);
// add all constraints in constraintsList to table
foreach (Constraints constraints in constraintsList)
{
table.Add(constraints.values);
}
List<List<float>> newTable = new List<List<float>>();
// add all rows in table to newTable
foreach (List<float> row in table)
{
// add all columns in row to newTable without reference to table
List<float> newRow = new List<float>();
for (int i = 0; i < row.Count; i++)
{
newRow.Add(row[i]);
}
newTable.Add(newRow);
}
int varCount = newTable[0].Count;
table = prepareTable(newTable, constraintsList);
// print every row in table
printTable(table, varCount);
}
List<List<float>> prepareTable(List<List<float>> table, List<Constraints> constraints)
{
List<List<float>> newTable = new List<List<float>>();
foreach (List<float> row in table)
{
List<float> newRow = new List<float>();
foreach (float value in row)
{
newRow.Add(value);
}
newTable.Add(newRow);
}
List<string> signs = new List<string>();
foreach (Constraints constraint in constraints)
{
signs.Add(constraint.sign);
}
for (int i = 0; i < signs.Count ; i++)
{
table[0].Add(0);
table[0].Add(0);
// if sign[i] == "=" copy table[i] to table[i+1] without overwriting table[i+1]
if (signs[i] == "=")
{
List<float> tempRow = new List<float>();
foreach (float value in table[i+1])
{
tempRow.Add(value);
}
table.Add(tempRow);
// move last row of table to table[i+2]
for (int j = table.Count - 1; j > i+2; j--)
{
List<float> row = table[j];
table[j] = table[j-1];
table[j-1] = row;
}
signs.Add("2=");
for (int j = signs.Count - 1; j > i + 1; j--)
{
string sign = signs[j];
signs[j] = signs[j-1];
signs[j-1] = sign;
}
newTable.Insert(i+1, newTable[i+1]);
}
if (signs[i] == ">=")
{
// multiply table[i+1] by -1
for (int j = 0; j < table[i+1].Count; j++)
{
table[i+1][j] = table[i+1][j] * -1;
}
}
// add 3 0s to each row for every column in table
for (int j = 0; j < signs.Count ; j++)
{
if (signs[i] == ">=")
{
// make s = 1
if (i == j)
{
table[i+1].Add(0);
table[i+1].Add(1);
}
else
{
table[i+1].Add(0);
table[i+1].Add(0);
}
}
else if (signs[i] == "<=")
{
//make e = 1
if (i == j)
{
table[i+1].Add(-1);
table[i+1].Add(0);
}
else
{
table[i+1].Add(0);
table[i+1].Add(0);
}
}
else if (signs[i] == "=")
{
// make a = 1
if (i == j)
{
table[i+1].Add(-1);
table[i+1].Add(0);
}
else
{
table[i+1].Add(0);
table[i+1].Add(0);
}
}
else if (signs[i] == "2=")
{
// make a = 1
if (i == j)
{
table[i+1].Add(0);
table[i+1].Add(1);
}
else
{
table[i+1].Add(0);
table[i+1].Add(0);
}
}
}
}
table[0].Add(0);
// remove intex newTable.Count-1 from table and place it in the back of table
for (int i = 1; i < table.Count; i++)
{
table[i].RemoveAt(newTable[i].Count-1);
if (signs[i-1] == ">=" || signs[i-1] == "2=")
{
table[i].Add(newTable[i][newTable[i].Count-1] * -1);
}
else
{
table[i].Add(newTable[i][newTable[i].Count-1]);
}
}
// remove the value of newTable.Count-1 from table[1] and place it in the back of table[1]
return table;
}
void printTable(List<List<float>> table, int varCount)
{
int count = 1;
string[] headers = new string[table[0].Count];
for (int i = 0; i < table[0].Count; i++)
{
if (i < varCount)
{
headers[i] = "x" + (i + 1);
}
else if (i < table[0].Count - 1)
{
headers[i] = "e" + (count);
headers[i+1] = "s" + (count);
i = i + 1;
count++;
}
else
{
headers[i] = "rhs";
}
}
var conTable = new ConsoleTable(headers);
foreach (List<float> row in table)
{
// convert row to object array
object[] rowArray = new object[row.Count];
for (int i = 0; i < row.Count; i++)
{
rowArray[i] = row[i];
}
conTable.AddRow(rowArray);
}
conTable.Write(Format.Alternative);
}
}

81
file.cs
View File

@@ -1,81 +0,0 @@
class file
{
public Tuple<List<zConstraints>,List<Constraints>> readFile()
{
List<zConstraints> zConstraintsList = new List<zConstraints>();
List<Constraints> constraintsList = new List<Constraints>();
//read file "input.txt" line by line
string line;
StreamReader file = new StreamReader("input.txt");
while ((line = file.ReadLine()) != null)
{
// if line contains "min" or "max"
if (line.Contains("min") || line.Contains("max"))
{
zConstraints constraints = new zConstraints();
if (line.Contains("min"))
{
constraints.minMax = "min";
}
else
{
constraints.minMax = "max";
}
// remove "min" or "max" from line
line = line.Remove(0, line.IndexOf(constraints.minMax) + constraints.minMax.Length);
// split line by " "
string[] lineArray = line.Split(' ');
//remove empty elements from array
lineArray = lineArray.Where(x => !string.IsNullOrEmpty(x)).ToArray();
// add variables to constraints.variables after parsing them to float
List<float> variables = new List<float>();
foreach (string variable in lineArray)
{
variables.Add(float.Parse(variable));
}
constraints.values = variables;
// add constraints to list
zConstraintsList.Add(constraints);
}
else
{
// split line by " "
string[] lineArray = line.Split(' ');
//remove empty elements from array
lineArray = lineArray.Where(x => !string.IsNullOrEmpty(x)).ToArray();
// for each element in array
Constraints constraints = new Constraints();
List<float> variables = new List<float>();
foreach (string variable in lineArray)
{
if (variable.Contains("=") || variable.Contains(">") || variable.Contains("<"))
{
constraints.sign = variable;
}
else
{
variables.Add(float.Parse(variable));
}
}
constraints.values = variables;
constraintsList.Add(constraints);
}
}
file.Close();
return new Tuple<List<zConstraints>, List<Constraints>>(zConstraintsList, constraintsList);
}
}
class zConstraints
{
public string minMax;
public List<float> values;
}
class Constraints
{
public List<float> values;
public string sign;
}

View File

@@ -1,8 +0,0 @@
max +1 +1
+8 +4 = 160
+4 +4 <= 100
+1 +0 <= 17
+1 +0 >= 5
+0 +1 >= 2
+1 -1 >= 0
+1 -4 <= 0

View File

@@ -1,14 +0,0 @@
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<OutputType>Exe</OutputType>
<TargetFramework>net6.0</TargetFramework>
<ImplicitUsings>enable</ImplicitUsings>
<Nullable>enable</Nullable>
</PropertyGroup>
<ItemGroup>
<PackageReference Include="ConsoleTables" Version="2.4.2" />
</ItemGroup>
</Project>

View File

@@ -1,4 +0,0 @@
// <autogenerated />
using System;
using System.Reflection;
[assembly: global::System.Runtime.Versioning.TargetFrameworkAttribute(".NETCoreApp,Version=v6.0", FrameworkDisplayName = "")]

Binary file not shown.

View File

@@ -1,22 +0,0 @@
//------------------------------------------------------------------------------
// <auto-generated>
// This code was generated by a tool.
//
// Changes to this file may cause incorrect behavior and will be lost if
// the code is regenerated.
// </auto-generated>
//------------------------------------------------------------------------------
using System;
using System.Reflection;
[assembly: System.Reflection.AssemblyCompanyAttribute("lpr381")]
[assembly: System.Reflection.AssemblyConfigurationAttribute("Debug")]
[assembly: System.Reflection.AssemblyFileVersionAttribute("1.0.0.0")]
[assembly: System.Reflection.AssemblyInformationalVersionAttribute("1.0.0")]
[assembly: System.Reflection.AssemblyProductAttribute("lpr381")]
[assembly: System.Reflection.AssemblyTitleAttribute("lpr381")]
[assembly: System.Reflection.AssemblyVersionAttribute("1.0.0.0")]
// Generated by the MSBuild WriteCodeFragment class.

View File

@@ -1 +0,0 @@
19ef02a5be1a65bf6b975f4a44f162accba6b382

View File

@@ -1,10 +0,0 @@
is_global = true
build_property.TargetFramework = net6.0
build_property.TargetPlatformMinVersion =
build_property.UsingMicrosoftNETSdkWeb =
build_property.ProjectTypeGuids =
build_property.InvariantGlobalization =
build_property.PlatformNeutralAssembly =
build_property._SupportedPlatformList = Linux,macOS,Windows
build_property.RootNamespace = lpr381
build_property.ProjectDir = /home/mrfluffy/Documents/c#/lpr381/

View File

@@ -1,8 +0,0 @@
// <auto-generated/>
global using global::System;
global using global::System.Collections.Generic;
global using global::System.IO;
global using global::System.Linq;
global using global::System.Net.Http;
global using global::System.Threading;
global using global::System.Threading.Tasks;

Binary file not shown.

View File

@@ -1 +0,0 @@
8c13023fa8aa1aee00b6cf6a6819800d58bb1521

View File

@@ -1,17 +0,0 @@
/home/mrfluffy/Documents/c#/lpr381/obj/Debug/net6.0/lpr381.csproj.AssemblyReference.cache
/home/mrfluffy/Documents/c#/lpr381/obj/Debug/net6.0/lpr381.GeneratedMSBuildEditorConfig.editorconfig
/home/mrfluffy/Documents/c#/lpr381/obj/Debug/net6.0/lpr381.AssemblyInfoInputs.cache
/home/mrfluffy/Documents/c#/lpr381/obj/Debug/net6.0/lpr381.AssemblyInfo.cs
/home/mrfluffy/Documents/c#/lpr381/obj/Debug/net6.0/lpr381.csproj.CoreCompileInputs.cache
/home/mrfluffy/Documents/c#/lpr381/bin/Debug/net6.0/lpr381
/home/mrfluffy/Documents/c#/lpr381/bin/Debug/net6.0/lpr381.deps.json
/home/mrfluffy/Documents/c#/lpr381/bin/Debug/net6.0/lpr381.runtimeconfig.json
/home/mrfluffy/Documents/c#/lpr381/bin/Debug/net6.0/lpr381.dll
/home/mrfluffy/Documents/c#/lpr381/bin/Debug/net6.0/ref/lpr381.dll
/home/mrfluffy/Documents/c#/lpr381/bin/Debug/net6.0/lpr381.pdb
/home/mrfluffy/Documents/c#/lpr381/obj/Debug/net6.0/lpr381.dll
/home/mrfluffy/Documents/c#/lpr381/obj/Debug/net6.0/ref/lpr381.dll
/home/mrfluffy/Documents/c#/lpr381/obj/Debug/net6.0/lpr381.pdb
/home/mrfluffy/Documents/c#/lpr381/obj/Debug/net6.0/lpr381.genruntimeconfig.cache
/home/mrfluffy/Documents/c#/lpr381/obj/Debug/net6.0/lpr381.csproj.CopyComplete
/home/mrfluffy/Documents/c#/lpr381/bin/Debug/net6.0/ConsoleTables.dll

Binary file not shown.

View File

@@ -1 +0,0 @@
1e253571666f59f5c0ab7c37c5d596e5501a216c

Binary file not shown.

Binary file not shown.

View File

@@ -1,4 +0,0 @@
// <autogenerated />
using System;
using System.Reflection;
[assembly: global::System.Runtime.Versioning.TargetFrameworkAttribute(".NETCoreApp,Version=v6.0", FrameworkDisplayName = "")]

Binary file not shown.

View File

@@ -1,22 +0,0 @@
//------------------------------------------------------------------------------
// <auto-generated>
// This code was generated by a tool.
//
// Changes to this file may cause incorrect behavior and will be lost if
// the code is regenerated.
// </auto-generated>
//------------------------------------------------------------------------------
using System;
using System.Reflection;
[assembly: System.Reflection.AssemblyCompanyAttribute("lpr381")]
[assembly: System.Reflection.AssemblyConfigurationAttribute("Release")]
[assembly: System.Reflection.AssemblyFileVersionAttribute("1.0.0.0")]
[assembly: System.Reflection.AssemblyInformationalVersionAttribute("1.0.0")]
[assembly: System.Reflection.AssemblyProductAttribute("lpr381")]
[assembly: System.Reflection.AssemblyTitleAttribute("lpr381")]
[assembly: System.Reflection.AssemblyVersionAttribute("1.0.0.0")]
// Generated by the MSBuild WriteCodeFragment class.

View File

@@ -1 +0,0 @@
b9e0021e723c322ac0b279cab44aef39129eb7a8

View File

@@ -1,10 +0,0 @@
is_global = true
build_property.TargetFramework = net6.0
build_property.TargetPlatformMinVersion =
build_property.UsingMicrosoftNETSdkWeb =
build_property.ProjectTypeGuids =
build_property.InvariantGlobalization =
build_property.PlatformNeutralAssembly =
build_property._SupportedPlatformList = Linux,macOS,Windows
build_property.RootNamespace = lpr381
build_property.ProjectDir = /home/mrfluffy/Documents/c#/lpr381/

View File

@@ -1,8 +0,0 @@
// <auto-generated/>
global using global::System;
global using global::System.Collections.Generic;
global using global::System.IO;
global using global::System.Linq;
global using global::System.Net.Http;
global using global::System.Threading;
global using global::System.Threading.Tasks;

View File

@@ -1 +0,0 @@
1451b566708a8403bb7092754722413801261e62

View File

@@ -1,15 +0,0 @@
/home/mrfluffy/Documents/c#/lpr381/bin/Release/net6.0/lpr381
/home/mrfluffy/Documents/c#/lpr381/bin/Release/net6.0/lpr381.deps.json
/home/mrfluffy/Documents/c#/lpr381/bin/Release/net6.0/lpr381.runtimeconfig.json
/home/mrfluffy/Documents/c#/lpr381/bin/Release/net6.0/lpr381.dll
/home/mrfluffy/Documents/c#/lpr381/bin/Release/net6.0/ref/lpr381.dll
/home/mrfluffy/Documents/c#/lpr381/bin/Release/net6.0/lpr381.pdb
/home/mrfluffy/Documents/c#/lpr381/obj/Release/net6.0/lpr381.csproj.AssemblyReference.cache
/home/mrfluffy/Documents/c#/lpr381/obj/Release/net6.0/lpr381.GeneratedMSBuildEditorConfig.editorconfig
/home/mrfluffy/Documents/c#/lpr381/obj/Release/net6.0/lpr381.AssemblyInfoInputs.cache
/home/mrfluffy/Documents/c#/lpr381/obj/Release/net6.0/lpr381.AssemblyInfo.cs
/home/mrfluffy/Documents/c#/lpr381/obj/Release/net6.0/lpr381.csproj.CoreCompileInputs.cache
/home/mrfluffy/Documents/c#/lpr381/obj/Release/net6.0/lpr381.dll
/home/mrfluffy/Documents/c#/lpr381/obj/Release/net6.0/ref/lpr381.dll
/home/mrfluffy/Documents/c#/lpr381/obj/Release/net6.0/lpr381.pdb
/home/mrfluffy/Documents/c#/lpr381/obj/Release/net6.0/lpr381.genruntimeconfig.cache

Binary file not shown.

View File

@@ -1 +0,0 @@
670f060e3646ff2f7e8cdecd2b3e98bee644fdfb

Binary file not shown.

Binary file not shown.

View File

@@ -1,72 +0,0 @@
{
"format": 1,
"restore": {
"/home/mrfluffy/Documents/c#/lpr381/lpr381.csproj": {}
},
"projects": {
"/home/mrfluffy/Documents/c#/lpr381/lpr381.csproj": {
"version": "1.0.0",
"restore": {
"projectUniqueName": "/home/mrfluffy/Documents/c#/lpr381/lpr381.csproj",
"projectName": "lpr381",
"projectPath": "/home/mrfluffy/Documents/c#/lpr381/lpr381.csproj",
"packagesPath": "/home/mrfluffy/.cache/NuGetPackages",
"outputPath": "/home/mrfluffy/Documents/c#/lpr381/obj/",
"projectStyle": "PackageReference",
"configFilePaths": [
"/home/mrfluffy/.nuget/NuGet/NuGet.Config"
],
"originalTargetFrameworks": [
"net6.0"
],
"sources": {
"https://api.nuget.org/v3/index.json": {}
},
"frameworks": {
"net6.0": {
"targetAlias": "net6.0",
"projectReferences": {}
}
},
"warningProperties": {
"warnAsError": [
"NU1605"
]
}
},
"frameworks": {
"net6.0": {
"targetAlias": "net6.0",
"dependencies": {
"ConsoleTables": {
"target": "Package",
"version": "[2.4.2, )"
}
},
"imports": [
"net461",
"net462",
"net47",
"net471",
"net472",
"net48"
],
"assetTargetFallback": true,
"warn": true,
"downloadDependencies": [
{
"name": "Microsoft.AspNetCore.App.Ref",
"version": "[6.0.6, 6.0.6]"
}
],
"frameworkReferences": {
"Microsoft.NETCore.App": {
"privateAssets": "all"
}
},
"runtimeIdentifierGraphPath": "/usr/share/dotnet/sdk/6.0.106/RuntimeIdentifierGraph.json"
}
}
}
}
}

View File

@@ -1,15 +0,0 @@
<?xml version="1.0" encoding="utf-8" standalone="no"?>
<Project ToolsVersion="14.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<PropertyGroup Condition=" '$(ExcludeRestorePackageImports)' != 'true' ">
<RestoreSuccess Condition=" '$(RestoreSuccess)' == '' ">True</RestoreSuccess>
<RestoreTool Condition=" '$(RestoreTool)' == '' ">NuGet</RestoreTool>
<ProjectAssetsFile Condition=" '$(ProjectAssetsFile)' == '' ">$(MSBuildThisFileDirectory)project.assets.json</ProjectAssetsFile>
<NuGetPackageRoot Condition=" '$(NuGetPackageRoot)' == '' ">/home/mrfluffy/.cache/NuGetPackages</NuGetPackageRoot>
<NuGetPackageFolders Condition=" '$(NuGetPackageFolders)' == '' ">/home/mrfluffy/.cache/NuGetPackages</NuGetPackageFolders>
<NuGetProjectStyle Condition=" '$(NuGetProjectStyle)' == '' ">PackageReference</NuGetProjectStyle>
<NuGetToolVersion Condition=" '$(NuGetToolVersion)' == '' ">6.0.2</NuGetToolVersion>
</PropertyGroup>
<ItemGroup Condition=" '$(ExcludeRestorePackageImports)' != 'true' ">
<SourceRoot Include="/home/mrfluffy/.cache/NuGetPackages/" />
</ItemGroup>
</Project>

View File

@@ -1,2 +0,0 @@
<?xml version="1.0" encoding="utf-8" standalone="no"?>
<Project ToolsVersion="14.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003" />

View File

@@ -1,741 +0,0 @@
{
"version": 3,
"targets": {
"net6.0": {
"ConsoleTables/2.4.2": {
"type": "package",
"dependencies": {
"System.Reflection.TypeExtensions": "4.3.0"
},
"compile": {
"lib/netcoreapp3.1/ConsoleTables.dll": {}
},
"runtime": {
"lib/netcoreapp3.1/ConsoleTables.dll": {}
}
},
"Microsoft.NETCore.Platforms/1.1.0": {
"type": "package",
"compile": {
"lib/netstandard1.0/_._": {}
},
"runtime": {
"lib/netstandard1.0/_._": {}
}
},
"Microsoft.NETCore.Targets/1.1.0": {
"type": "package",
"compile": {
"lib/netstandard1.0/_._": {}
},
"runtime": {
"lib/netstandard1.0/_._": {}
}
},
"System.IO/4.3.0": {
"type": "package",
"dependencies": {
"Microsoft.NETCore.Platforms": "1.1.0",
"Microsoft.NETCore.Targets": "1.1.0",
"System.Runtime": "4.3.0",
"System.Text.Encoding": "4.3.0",
"System.Threading.Tasks": "4.3.0"
},
"compile": {
"ref/netstandard1.5/System.IO.dll": {}
}
},
"System.Reflection/4.3.0": {
"type": "package",
"dependencies": {
"Microsoft.NETCore.Platforms": "1.1.0",
"Microsoft.NETCore.Targets": "1.1.0",
"System.IO": "4.3.0",
"System.Reflection.Primitives": "4.3.0",
"System.Runtime": "4.3.0"
},
"compile": {
"ref/netstandard1.5/System.Reflection.dll": {}
}
},
"System.Reflection.Primitives/4.3.0": {
"type": "package",
"dependencies": {
"Microsoft.NETCore.Platforms": "1.1.0",
"Microsoft.NETCore.Targets": "1.1.0",
"System.Runtime": "4.3.0"
},
"compile": {
"ref/netstandard1.0/System.Reflection.Primitives.dll": {}
}
},
"System.Reflection.TypeExtensions/4.3.0": {
"type": "package",
"dependencies": {
"System.Reflection": "4.3.0",
"System.Runtime": "4.3.0"
},
"compile": {
"ref/netstandard1.5/System.Reflection.TypeExtensions.dll": {}
},
"runtime": {
"lib/netstandard1.5/System.Reflection.TypeExtensions.dll": {}
}
},
"System.Runtime/4.3.0": {
"type": "package",
"dependencies": {
"Microsoft.NETCore.Platforms": "1.1.0",
"Microsoft.NETCore.Targets": "1.1.0"
},
"compile": {
"ref/netstandard1.5/System.Runtime.dll": {}
}
},
"System.Text.Encoding/4.3.0": {
"type": "package",
"dependencies": {
"Microsoft.NETCore.Platforms": "1.1.0",
"Microsoft.NETCore.Targets": "1.1.0",
"System.Runtime": "4.3.0"
},
"compile": {
"ref/netstandard1.3/System.Text.Encoding.dll": {}
}
},
"System.Threading.Tasks/4.3.0": {
"type": "package",
"dependencies": {
"Microsoft.NETCore.Platforms": "1.1.0",
"Microsoft.NETCore.Targets": "1.1.0",
"System.Runtime": "4.3.0"
},
"compile": {
"ref/netstandard1.3/System.Threading.Tasks.dll": {}
}
}
}
},
"libraries": {
"ConsoleTables/2.4.2": {
"sha512": "0SRFOWYCgFQ0RfAMof2DsGEJHI2YKquCA4X26kKyuG+MG+/2R3NRgRVEqXDMU7eVP69MGDzb1eg4i3/APlIfQg==",
"type": "package",
"path": "consoletables/2.4.2",
"files": [
".nupkg.metadata",
".signature.p7s",
"consoletables.2.4.2.nupkg.sha512",
"consoletables.nuspec",
"lib/net40/ConsoleTables.dll",
"lib/net40/ConsoleTables.pdb",
"lib/netcoreapp3.1/ConsoleTables.dll",
"lib/netcoreapp3.1/ConsoleTables.pdb",
"lib/netstandard1.3/ConsoleTables.dll",
"lib/netstandard1.3/ConsoleTables.pdb"
]
},
"Microsoft.NETCore.Platforms/1.1.0": {
"sha512": "kz0PEW2lhqygehI/d6XsPCQzD7ff7gUJaVGPVETX611eadGsA3A877GdSlU0LRVMCTH/+P3o2iDTak+S08V2+A==",
"type": "package",
"path": "microsoft.netcore.platforms/1.1.0",
"files": [
".nupkg.metadata",
".signature.p7s",
"ThirdPartyNotices.txt",
"dotnet_library_license.txt",
"lib/netstandard1.0/_._",
"microsoft.netcore.platforms.1.1.0.nupkg.sha512",
"microsoft.netcore.platforms.nuspec",
"runtime.json"
]
},
"Microsoft.NETCore.Targets/1.1.0": {
"sha512": "aOZA3BWfz9RXjpzt0sRJJMjAscAUm3Hoa4UWAfceV9UTYxgwZ1lZt5nO2myFf+/jetYQo4uTP7zS8sJY67BBxg==",
"type": "package",
"path": "microsoft.netcore.targets/1.1.0",
"files": [
".nupkg.metadata",
".signature.p7s",
"ThirdPartyNotices.txt",
"dotnet_library_license.txt",
"lib/netstandard1.0/_._",
"microsoft.netcore.targets.1.1.0.nupkg.sha512",
"microsoft.netcore.targets.nuspec",
"runtime.json"
]
},
"System.IO/4.3.0": {
"sha512": "3qjaHvxQPDpSOYICjUoTsmoq5u6QJAFRUITgeT/4gqkF1bajbSmb1kwSxEA8AHlofqgcKJcM8udgieRNhaJ5Cg==",
"type": "package",
"path": "system.io/4.3.0",
"files": [
".nupkg.metadata",
".signature.p7s",
"ThirdPartyNotices.txt",
"dotnet_library_license.txt",
"lib/MonoAndroid10/_._",
"lib/MonoTouch10/_._",
"lib/net45/_._",
"lib/net462/System.IO.dll",
"lib/portable-net45+win8+wp8+wpa81/_._",
"lib/win8/_._",
"lib/wp80/_._",
"lib/wpa81/_._",
"lib/xamarinios10/_._",
"lib/xamarinmac20/_._",
"lib/xamarintvos10/_._",
"lib/xamarinwatchos10/_._",
"ref/MonoAndroid10/_._",
"ref/MonoTouch10/_._",
"ref/net45/_._",
"ref/net462/System.IO.dll",
"ref/netcore50/System.IO.dll",
"ref/netcore50/System.IO.xml",
"ref/netcore50/de/System.IO.xml",
"ref/netcore50/es/System.IO.xml",
"ref/netcore50/fr/System.IO.xml",
"ref/netcore50/it/System.IO.xml",
"ref/netcore50/ja/System.IO.xml",
"ref/netcore50/ko/System.IO.xml",
"ref/netcore50/ru/System.IO.xml",
"ref/netcore50/zh-hans/System.IO.xml",
"ref/netcore50/zh-hant/System.IO.xml",
"ref/netstandard1.0/System.IO.dll",
"ref/netstandard1.0/System.IO.xml",
"ref/netstandard1.0/de/System.IO.xml",
"ref/netstandard1.0/es/System.IO.xml",
"ref/netstandard1.0/fr/System.IO.xml",
"ref/netstandard1.0/it/System.IO.xml",
"ref/netstandard1.0/ja/System.IO.xml",
"ref/netstandard1.0/ko/System.IO.xml",
"ref/netstandard1.0/ru/System.IO.xml",
"ref/netstandard1.0/zh-hans/System.IO.xml",
"ref/netstandard1.0/zh-hant/System.IO.xml",
"ref/netstandard1.3/System.IO.dll",
"ref/netstandard1.3/System.IO.xml",
"ref/netstandard1.3/de/System.IO.xml",
"ref/netstandard1.3/es/System.IO.xml",
"ref/netstandard1.3/fr/System.IO.xml",
"ref/netstandard1.3/it/System.IO.xml",
"ref/netstandard1.3/ja/System.IO.xml",
"ref/netstandard1.3/ko/System.IO.xml",
"ref/netstandard1.3/ru/System.IO.xml",
"ref/netstandard1.3/zh-hans/System.IO.xml",
"ref/netstandard1.3/zh-hant/System.IO.xml",
"ref/netstandard1.5/System.IO.dll",
"ref/netstandard1.5/System.IO.xml",
"ref/netstandard1.5/de/System.IO.xml",
"ref/netstandard1.5/es/System.IO.xml",
"ref/netstandard1.5/fr/System.IO.xml",
"ref/netstandard1.5/it/System.IO.xml",
"ref/netstandard1.5/ja/System.IO.xml",
"ref/netstandard1.5/ko/System.IO.xml",
"ref/netstandard1.5/ru/System.IO.xml",
"ref/netstandard1.5/zh-hans/System.IO.xml",
"ref/netstandard1.5/zh-hant/System.IO.xml",
"ref/portable-net45+win8+wp8+wpa81/_._",
"ref/win8/_._",
"ref/wp80/_._",
"ref/wpa81/_._",
"ref/xamarinios10/_._",
"ref/xamarinmac20/_._",
"ref/xamarintvos10/_._",
"ref/xamarinwatchos10/_._",
"system.io.4.3.0.nupkg.sha512",
"system.io.nuspec"
]
},
"System.Reflection/4.3.0": {
"sha512": "KMiAFoW7MfJGa9nDFNcfu+FpEdiHpWgTcS2HdMpDvt9saK3y/G4GwprPyzqjFH9NTaGPQeWNHU+iDlDILj96aQ==",
"type": "package",
"path": "system.reflection/4.3.0",
"files": [
".nupkg.metadata",
".signature.p7s",
"ThirdPartyNotices.txt",
"dotnet_library_license.txt",
"lib/MonoAndroid10/_._",
"lib/MonoTouch10/_._",
"lib/net45/_._",
"lib/net462/System.Reflection.dll",
"lib/portable-net45+win8+wp8+wpa81/_._",
"lib/win8/_._",
"lib/wp80/_._",
"lib/wpa81/_._",
"lib/xamarinios10/_._",
"lib/xamarinmac20/_._",
"lib/xamarintvos10/_._",
"lib/xamarinwatchos10/_._",
"ref/MonoAndroid10/_._",
"ref/MonoTouch10/_._",
"ref/net45/_._",
"ref/net462/System.Reflection.dll",
"ref/netcore50/System.Reflection.dll",
"ref/netcore50/System.Reflection.xml",
"ref/netcore50/de/System.Reflection.xml",
"ref/netcore50/es/System.Reflection.xml",
"ref/netcore50/fr/System.Reflection.xml",
"ref/netcore50/it/System.Reflection.xml",
"ref/netcore50/ja/System.Reflection.xml",
"ref/netcore50/ko/System.Reflection.xml",
"ref/netcore50/ru/System.Reflection.xml",
"ref/netcore50/zh-hans/System.Reflection.xml",
"ref/netcore50/zh-hant/System.Reflection.xml",
"ref/netstandard1.0/System.Reflection.dll",
"ref/netstandard1.0/System.Reflection.xml",
"ref/netstandard1.0/de/System.Reflection.xml",
"ref/netstandard1.0/es/System.Reflection.xml",
"ref/netstandard1.0/fr/System.Reflection.xml",
"ref/netstandard1.0/it/System.Reflection.xml",
"ref/netstandard1.0/ja/System.Reflection.xml",
"ref/netstandard1.0/ko/System.Reflection.xml",
"ref/netstandard1.0/ru/System.Reflection.xml",
"ref/netstandard1.0/zh-hans/System.Reflection.xml",
"ref/netstandard1.0/zh-hant/System.Reflection.xml",
"ref/netstandard1.3/System.Reflection.dll",
"ref/netstandard1.3/System.Reflection.xml",
"ref/netstandard1.3/de/System.Reflection.xml",
"ref/netstandard1.3/es/System.Reflection.xml",
"ref/netstandard1.3/fr/System.Reflection.xml",
"ref/netstandard1.3/it/System.Reflection.xml",
"ref/netstandard1.3/ja/System.Reflection.xml",
"ref/netstandard1.3/ko/System.Reflection.xml",
"ref/netstandard1.3/ru/System.Reflection.xml",
"ref/netstandard1.3/zh-hans/System.Reflection.xml",
"ref/netstandard1.3/zh-hant/System.Reflection.xml",
"ref/netstandard1.5/System.Reflection.dll",
"ref/netstandard1.5/System.Reflection.xml",
"ref/netstandard1.5/de/System.Reflection.xml",
"ref/netstandard1.5/es/System.Reflection.xml",
"ref/netstandard1.5/fr/System.Reflection.xml",
"ref/netstandard1.5/it/System.Reflection.xml",
"ref/netstandard1.5/ja/System.Reflection.xml",
"ref/netstandard1.5/ko/System.Reflection.xml",
"ref/netstandard1.5/ru/System.Reflection.xml",
"ref/netstandard1.5/zh-hans/System.Reflection.xml",
"ref/netstandard1.5/zh-hant/System.Reflection.xml",
"ref/portable-net45+win8+wp8+wpa81/_._",
"ref/win8/_._",
"ref/wp80/_._",
"ref/wpa81/_._",
"ref/xamarinios10/_._",
"ref/xamarinmac20/_._",
"ref/xamarintvos10/_._",
"ref/xamarinwatchos10/_._",
"system.reflection.4.3.0.nupkg.sha512",
"system.reflection.nuspec"
]
},
"System.Reflection.Primitives/4.3.0": {
"sha512": "5RXItQz5As4xN2/YUDxdpsEkMhvw3e6aNveFXUn4Hl/udNTCNhnKp8lT9fnc3MhvGKh1baak5CovpuQUXHAlIA==",
"type": "package",
"path": "system.reflection.primitives/4.3.0",
"files": [
".nupkg.metadata",
".signature.p7s",
"ThirdPartyNotices.txt",
"dotnet_library_license.txt",
"lib/MonoAndroid10/_._",
"lib/MonoTouch10/_._",
"lib/net45/_._",
"lib/portable-net45+win8+wp8+wpa81/_._",
"lib/win8/_._",
"lib/wp80/_._",
"lib/wpa81/_._",
"lib/xamarinios10/_._",
"lib/xamarinmac20/_._",
"lib/xamarintvos10/_._",
"lib/xamarinwatchos10/_._",
"ref/MonoAndroid10/_._",
"ref/MonoTouch10/_._",
"ref/net45/_._",
"ref/netcore50/System.Reflection.Primitives.dll",
"ref/netcore50/System.Reflection.Primitives.xml",
"ref/netcore50/de/System.Reflection.Primitives.xml",
"ref/netcore50/es/System.Reflection.Primitives.xml",
"ref/netcore50/fr/System.Reflection.Primitives.xml",
"ref/netcore50/it/System.Reflection.Primitives.xml",
"ref/netcore50/ja/System.Reflection.Primitives.xml",
"ref/netcore50/ko/System.Reflection.Primitives.xml",
"ref/netcore50/ru/System.Reflection.Primitives.xml",
"ref/netcore50/zh-hans/System.Reflection.Primitives.xml",
"ref/netcore50/zh-hant/System.Reflection.Primitives.xml",
"ref/netstandard1.0/System.Reflection.Primitives.dll",
"ref/netstandard1.0/System.Reflection.Primitives.xml",
"ref/netstandard1.0/de/System.Reflection.Primitives.xml",
"ref/netstandard1.0/es/System.Reflection.Primitives.xml",
"ref/netstandard1.0/fr/System.Reflection.Primitives.xml",
"ref/netstandard1.0/it/System.Reflection.Primitives.xml",
"ref/netstandard1.0/ja/System.Reflection.Primitives.xml",
"ref/netstandard1.0/ko/System.Reflection.Primitives.xml",
"ref/netstandard1.0/ru/System.Reflection.Primitives.xml",
"ref/netstandard1.0/zh-hans/System.Reflection.Primitives.xml",
"ref/netstandard1.0/zh-hant/System.Reflection.Primitives.xml",
"ref/portable-net45+win8+wp8+wpa81/_._",
"ref/win8/_._",
"ref/wp80/_._",
"ref/wpa81/_._",
"ref/xamarinios10/_._",
"ref/xamarinmac20/_._",
"ref/xamarintvos10/_._",
"ref/xamarinwatchos10/_._",
"system.reflection.primitives.4.3.0.nupkg.sha512",
"system.reflection.primitives.nuspec"
]
},
"System.Reflection.TypeExtensions/4.3.0": {
"sha512": "7u6ulLcZbyxB5Gq0nMkQttcdBTx57ibzw+4IOXEfR+sXYQoHvjW5LTLyNr8O22UIMrqYbchJQJnos4eooYzYJA==",
"type": "package",
"path": "system.reflection.typeextensions/4.3.0",
"files": [
".nupkg.metadata",
".signature.p7s",
"ThirdPartyNotices.txt",
"dotnet_library_license.txt",
"lib/MonoAndroid10/_._",
"lib/MonoTouch10/_._",
"lib/net46/System.Reflection.TypeExtensions.dll",
"lib/net462/System.Reflection.TypeExtensions.dll",
"lib/netcore50/System.Reflection.TypeExtensions.dll",
"lib/netstandard1.5/System.Reflection.TypeExtensions.dll",
"lib/xamarinios10/_._",
"lib/xamarinmac20/_._",
"lib/xamarintvos10/_._",
"lib/xamarinwatchos10/_._",
"ref/MonoAndroid10/_._",
"ref/MonoTouch10/_._",
"ref/net46/System.Reflection.TypeExtensions.dll",
"ref/net462/System.Reflection.TypeExtensions.dll",
"ref/netstandard1.3/System.Reflection.TypeExtensions.dll",
"ref/netstandard1.3/System.Reflection.TypeExtensions.xml",
"ref/netstandard1.3/de/System.Reflection.TypeExtensions.xml",
"ref/netstandard1.3/es/System.Reflection.TypeExtensions.xml",
"ref/netstandard1.3/fr/System.Reflection.TypeExtensions.xml",
"ref/netstandard1.3/it/System.Reflection.TypeExtensions.xml",
"ref/netstandard1.3/ja/System.Reflection.TypeExtensions.xml",
"ref/netstandard1.3/ko/System.Reflection.TypeExtensions.xml",
"ref/netstandard1.3/ru/System.Reflection.TypeExtensions.xml",
"ref/netstandard1.3/zh-hans/System.Reflection.TypeExtensions.xml",
"ref/netstandard1.3/zh-hant/System.Reflection.TypeExtensions.xml",
"ref/netstandard1.5/System.Reflection.TypeExtensions.dll",
"ref/netstandard1.5/System.Reflection.TypeExtensions.xml",
"ref/netstandard1.5/de/System.Reflection.TypeExtensions.xml",
"ref/netstandard1.5/es/System.Reflection.TypeExtensions.xml",
"ref/netstandard1.5/fr/System.Reflection.TypeExtensions.xml",
"ref/netstandard1.5/it/System.Reflection.TypeExtensions.xml",
"ref/netstandard1.5/ja/System.Reflection.TypeExtensions.xml",
"ref/netstandard1.5/ko/System.Reflection.TypeExtensions.xml",
"ref/netstandard1.5/ru/System.Reflection.TypeExtensions.xml",
"ref/netstandard1.5/zh-hans/System.Reflection.TypeExtensions.xml",
"ref/netstandard1.5/zh-hant/System.Reflection.TypeExtensions.xml",
"ref/xamarinios10/_._",
"ref/xamarinmac20/_._",
"ref/xamarintvos10/_._",
"ref/xamarinwatchos10/_._",
"runtimes/aot/lib/netcore50/System.Reflection.TypeExtensions.dll",
"system.reflection.typeextensions.4.3.0.nupkg.sha512",
"system.reflection.typeextensions.nuspec"
]
},
"System.Runtime/4.3.0": {
"sha512": "JufQi0vPQ0xGnAczR13AUFglDyVYt4Kqnz1AZaiKZ5+GICq0/1MH/mO/eAJHt/mHW1zjKBJd7kV26SrxddAhiw==",
"type": "package",
"path": "system.runtime/4.3.0",
"files": [
".nupkg.metadata",
".signature.p7s",
"ThirdPartyNotices.txt",
"dotnet_library_license.txt",
"lib/MonoAndroid10/_._",
"lib/MonoTouch10/_._",
"lib/net45/_._",
"lib/net462/System.Runtime.dll",
"lib/portable-net45+win8+wp80+wpa81/_._",
"lib/win8/_._",
"lib/wp80/_._",
"lib/wpa81/_._",
"lib/xamarinios10/_._",
"lib/xamarinmac20/_._",
"lib/xamarintvos10/_._",
"lib/xamarinwatchos10/_._",
"ref/MonoAndroid10/_._",
"ref/MonoTouch10/_._",
"ref/net45/_._",
"ref/net462/System.Runtime.dll",
"ref/netcore50/System.Runtime.dll",
"ref/netcore50/System.Runtime.xml",
"ref/netcore50/de/System.Runtime.xml",
"ref/netcore50/es/System.Runtime.xml",
"ref/netcore50/fr/System.Runtime.xml",
"ref/netcore50/it/System.Runtime.xml",
"ref/netcore50/ja/System.Runtime.xml",
"ref/netcore50/ko/System.Runtime.xml",
"ref/netcore50/ru/System.Runtime.xml",
"ref/netcore50/zh-hans/System.Runtime.xml",
"ref/netcore50/zh-hant/System.Runtime.xml",
"ref/netstandard1.0/System.Runtime.dll",
"ref/netstandard1.0/System.Runtime.xml",
"ref/netstandard1.0/de/System.Runtime.xml",
"ref/netstandard1.0/es/System.Runtime.xml",
"ref/netstandard1.0/fr/System.Runtime.xml",
"ref/netstandard1.0/it/System.Runtime.xml",
"ref/netstandard1.0/ja/System.Runtime.xml",
"ref/netstandard1.0/ko/System.Runtime.xml",
"ref/netstandard1.0/ru/System.Runtime.xml",
"ref/netstandard1.0/zh-hans/System.Runtime.xml",
"ref/netstandard1.0/zh-hant/System.Runtime.xml",
"ref/netstandard1.2/System.Runtime.dll",
"ref/netstandard1.2/System.Runtime.xml",
"ref/netstandard1.2/de/System.Runtime.xml",
"ref/netstandard1.2/es/System.Runtime.xml",
"ref/netstandard1.2/fr/System.Runtime.xml",
"ref/netstandard1.2/it/System.Runtime.xml",
"ref/netstandard1.2/ja/System.Runtime.xml",
"ref/netstandard1.2/ko/System.Runtime.xml",
"ref/netstandard1.2/ru/System.Runtime.xml",
"ref/netstandard1.2/zh-hans/System.Runtime.xml",
"ref/netstandard1.2/zh-hant/System.Runtime.xml",
"ref/netstandard1.3/System.Runtime.dll",
"ref/netstandard1.3/System.Runtime.xml",
"ref/netstandard1.3/de/System.Runtime.xml",
"ref/netstandard1.3/es/System.Runtime.xml",
"ref/netstandard1.3/fr/System.Runtime.xml",
"ref/netstandard1.3/it/System.Runtime.xml",
"ref/netstandard1.3/ja/System.Runtime.xml",
"ref/netstandard1.3/ko/System.Runtime.xml",
"ref/netstandard1.3/ru/System.Runtime.xml",
"ref/netstandard1.3/zh-hans/System.Runtime.xml",
"ref/netstandard1.3/zh-hant/System.Runtime.xml",
"ref/netstandard1.5/System.Runtime.dll",
"ref/netstandard1.5/System.Runtime.xml",
"ref/netstandard1.5/de/System.Runtime.xml",
"ref/netstandard1.5/es/System.Runtime.xml",
"ref/netstandard1.5/fr/System.Runtime.xml",
"ref/netstandard1.5/it/System.Runtime.xml",
"ref/netstandard1.5/ja/System.Runtime.xml",
"ref/netstandard1.5/ko/System.Runtime.xml",
"ref/netstandard1.5/ru/System.Runtime.xml",
"ref/netstandard1.5/zh-hans/System.Runtime.xml",
"ref/netstandard1.5/zh-hant/System.Runtime.xml",
"ref/portable-net45+win8+wp80+wpa81/_._",
"ref/win8/_._",
"ref/wp80/_._",
"ref/wpa81/_._",
"ref/xamarinios10/_._",
"ref/xamarinmac20/_._",
"ref/xamarintvos10/_._",
"ref/xamarinwatchos10/_._",
"system.runtime.4.3.0.nupkg.sha512",
"system.runtime.nuspec"
]
},
"System.Text.Encoding/4.3.0": {
"sha512": "BiIg+KWaSDOITze6jGQynxg64naAPtqGHBwDrLaCtixsa5bKiR8dpPOHA7ge3C0JJQizJE+sfkz1wV+BAKAYZw==",
"type": "package",
"path": "system.text.encoding/4.3.0",
"files": [
".nupkg.metadata",
".signature.p7s",
"ThirdPartyNotices.txt",
"dotnet_library_license.txt",
"lib/MonoAndroid10/_._",
"lib/MonoTouch10/_._",
"lib/net45/_._",
"lib/portable-net45+win8+wp8+wpa81/_._",
"lib/win8/_._",
"lib/wp80/_._",
"lib/wpa81/_._",
"lib/xamarinios10/_._",
"lib/xamarinmac20/_._",
"lib/xamarintvos10/_._",
"lib/xamarinwatchos10/_._",
"ref/MonoAndroid10/_._",
"ref/MonoTouch10/_._",
"ref/net45/_._",
"ref/netcore50/System.Text.Encoding.dll",
"ref/netcore50/System.Text.Encoding.xml",
"ref/netcore50/de/System.Text.Encoding.xml",
"ref/netcore50/es/System.Text.Encoding.xml",
"ref/netcore50/fr/System.Text.Encoding.xml",
"ref/netcore50/it/System.Text.Encoding.xml",
"ref/netcore50/ja/System.Text.Encoding.xml",
"ref/netcore50/ko/System.Text.Encoding.xml",
"ref/netcore50/ru/System.Text.Encoding.xml",
"ref/netcore50/zh-hans/System.Text.Encoding.xml",
"ref/netcore50/zh-hant/System.Text.Encoding.xml",
"ref/netstandard1.0/System.Text.Encoding.dll",
"ref/netstandard1.0/System.Text.Encoding.xml",
"ref/netstandard1.0/de/System.Text.Encoding.xml",
"ref/netstandard1.0/es/System.Text.Encoding.xml",
"ref/netstandard1.0/fr/System.Text.Encoding.xml",
"ref/netstandard1.0/it/System.Text.Encoding.xml",
"ref/netstandard1.0/ja/System.Text.Encoding.xml",
"ref/netstandard1.0/ko/System.Text.Encoding.xml",
"ref/netstandard1.0/ru/System.Text.Encoding.xml",
"ref/netstandard1.0/zh-hans/System.Text.Encoding.xml",
"ref/netstandard1.0/zh-hant/System.Text.Encoding.xml",
"ref/netstandard1.3/System.Text.Encoding.dll",
"ref/netstandard1.3/System.Text.Encoding.xml",
"ref/netstandard1.3/de/System.Text.Encoding.xml",
"ref/netstandard1.3/es/System.Text.Encoding.xml",
"ref/netstandard1.3/fr/System.Text.Encoding.xml",
"ref/netstandard1.3/it/System.Text.Encoding.xml",
"ref/netstandard1.3/ja/System.Text.Encoding.xml",
"ref/netstandard1.3/ko/System.Text.Encoding.xml",
"ref/netstandard1.3/ru/System.Text.Encoding.xml",
"ref/netstandard1.3/zh-hans/System.Text.Encoding.xml",
"ref/netstandard1.3/zh-hant/System.Text.Encoding.xml",
"ref/portable-net45+win8+wp8+wpa81/_._",
"ref/win8/_._",
"ref/wp80/_._",
"ref/wpa81/_._",
"ref/xamarinios10/_._",
"ref/xamarinmac20/_._",
"ref/xamarintvos10/_._",
"ref/xamarinwatchos10/_._",
"system.text.encoding.4.3.0.nupkg.sha512",
"system.text.encoding.nuspec"
]
},
"System.Threading.Tasks/4.3.0": {
"sha512": "LbSxKEdOUhVe8BezB/9uOGGppt+nZf6e1VFyw6v3DN6lqitm0OSn2uXMOdtP0M3W4iMcqcivm2J6UgqiwwnXiA==",
"type": "package",
"path": "system.threading.tasks/4.3.0",
"files": [
".nupkg.metadata",
".signature.p7s",
"ThirdPartyNotices.txt",
"dotnet_library_license.txt",
"lib/MonoAndroid10/_._",
"lib/MonoTouch10/_._",
"lib/net45/_._",
"lib/portable-net45+win8+wp8+wpa81/_._",
"lib/win8/_._",
"lib/wp80/_._",
"lib/wpa81/_._",
"lib/xamarinios10/_._",
"lib/xamarinmac20/_._",
"lib/xamarintvos10/_._",
"lib/xamarinwatchos10/_._",
"ref/MonoAndroid10/_._",
"ref/MonoTouch10/_._",
"ref/net45/_._",
"ref/netcore50/System.Threading.Tasks.dll",
"ref/netcore50/System.Threading.Tasks.xml",
"ref/netcore50/de/System.Threading.Tasks.xml",
"ref/netcore50/es/System.Threading.Tasks.xml",
"ref/netcore50/fr/System.Threading.Tasks.xml",
"ref/netcore50/it/System.Threading.Tasks.xml",
"ref/netcore50/ja/System.Threading.Tasks.xml",
"ref/netcore50/ko/System.Threading.Tasks.xml",
"ref/netcore50/ru/System.Threading.Tasks.xml",
"ref/netcore50/zh-hans/System.Threading.Tasks.xml",
"ref/netcore50/zh-hant/System.Threading.Tasks.xml",
"ref/netstandard1.0/System.Threading.Tasks.dll",
"ref/netstandard1.0/System.Threading.Tasks.xml",
"ref/netstandard1.0/de/System.Threading.Tasks.xml",
"ref/netstandard1.0/es/System.Threading.Tasks.xml",
"ref/netstandard1.0/fr/System.Threading.Tasks.xml",
"ref/netstandard1.0/it/System.Threading.Tasks.xml",
"ref/netstandard1.0/ja/System.Threading.Tasks.xml",
"ref/netstandard1.0/ko/System.Threading.Tasks.xml",
"ref/netstandard1.0/ru/System.Threading.Tasks.xml",
"ref/netstandard1.0/zh-hans/System.Threading.Tasks.xml",
"ref/netstandard1.0/zh-hant/System.Threading.Tasks.xml",
"ref/netstandard1.3/System.Threading.Tasks.dll",
"ref/netstandard1.3/System.Threading.Tasks.xml",
"ref/netstandard1.3/de/System.Threading.Tasks.xml",
"ref/netstandard1.3/es/System.Threading.Tasks.xml",
"ref/netstandard1.3/fr/System.Threading.Tasks.xml",
"ref/netstandard1.3/it/System.Threading.Tasks.xml",
"ref/netstandard1.3/ja/System.Threading.Tasks.xml",
"ref/netstandard1.3/ko/System.Threading.Tasks.xml",
"ref/netstandard1.3/ru/System.Threading.Tasks.xml",
"ref/netstandard1.3/zh-hans/System.Threading.Tasks.xml",
"ref/netstandard1.3/zh-hant/System.Threading.Tasks.xml",
"ref/portable-net45+win8+wp8+wpa81/_._",
"ref/win8/_._",
"ref/wp80/_._",
"ref/wpa81/_._",
"ref/xamarinios10/_._",
"ref/xamarinmac20/_._",
"ref/xamarintvos10/_._",
"ref/xamarinwatchos10/_._",
"system.threading.tasks.4.3.0.nupkg.sha512",
"system.threading.tasks.nuspec"
]
}
},
"projectFileDependencyGroups": {
"net6.0": [
"ConsoleTables >= 2.4.2"
]
},
"packageFolders": {
"/home/mrfluffy/.cache/NuGetPackages": {}
},
"project": {
"version": "1.0.0",
"restore": {
"projectUniqueName": "/home/mrfluffy/Documents/c#/lpr381/lpr381.csproj",
"projectName": "lpr381",
"projectPath": "/home/mrfluffy/Documents/c#/lpr381/lpr381.csproj",
"packagesPath": "/home/mrfluffy/.cache/NuGetPackages",
"outputPath": "/home/mrfluffy/Documents/c#/lpr381/obj/",
"projectStyle": "PackageReference",
"configFilePaths": [
"/home/mrfluffy/.nuget/NuGet/NuGet.Config"
],
"originalTargetFrameworks": [
"net6.0"
],
"sources": {
"https://api.nuget.org/v3/index.json": {}
},
"frameworks": {
"net6.0": {
"targetAlias": "net6.0",
"projectReferences": {}
}
},
"warningProperties": {
"warnAsError": [
"NU1605"
]
}
},
"frameworks": {
"net6.0": {
"targetAlias": "net6.0",
"dependencies": {
"ConsoleTables": {
"target": "Package",
"version": "[2.4.2, )"
}
},
"imports": [
"net461",
"net462",
"net47",
"net471",
"net472",
"net48"
],
"assetTargetFallback": true,
"warn": true,
"downloadDependencies": [
{
"name": "Microsoft.AspNetCore.App.Ref",
"version": "[6.0.6, 6.0.6]"
}
],
"frameworkReferences": {
"Microsoft.NETCore.App": {
"privateAssets": "all"
}
},
"runtimeIdentifierGraphPath": "/usr/share/dotnet/sdk/6.0.106/RuntimeIdentifierGraph.json"
}
}
}
}

View File

@@ -1,20 +0,0 @@
{
"version": 2,
"dgSpecHash": "UsG+n8no52tNULnArv36wfnSHuyNsJtVw+cLkcJKa4zAucFyRBa7qGlEyQpU5Roj2w954zGpsMoMYS9LaYexCw==",
"success": true,
"projectFilePath": "/home/mrfluffy/Documents/c#/lpr381/lpr381.csproj",
"expectedPackageFiles": [
"/home/mrfluffy/.cache/NuGetPackages/consoletables/2.4.2/consoletables.2.4.2.nupkg.sha512",
"/home/mrfluffy/.cache/NuGetPackages/microsoft.netcore.platforms/1.1.0/microsoft.netcore.platforms.1.1.0.nupkg.sha512",
"/home/mrfluffy/.cache/NuGetPackages/microsoft.netcore.targets/1.1.0/microsoft.netcore.targets.1.1.0.nupkg.sha512",
"/home/mrfluffy/.cache/NuGetPackages/system.io/4.3.0/system.io.4.3.0.nupkg.sha512",
"/home/mrfluffy/.cache/NuGetPackages/system.reflection/4.3.0/system.reflection.4.3.0.nupkg.sha512",
"/home/mrfluffy/.cache/NuGetPackages/system.reflection.primitives/4.3.0/system.reflection.primitives.4.3.0.nupkg.sha512",
"/home/mrfluffy/.cache/NuGetPackages/system.reflection.typeextensions/4.3.0/system.reflection.typeextensions.4.3.0.nupkg.sha512",
"/home/mrfluffy/.cache/NuGetPackages/system.runtime/4.3.0/system.runtime.4.3.0.nupkg.sha512",
"/home/mrfluffy/.cache/NuGetPackages/system.text.encoding/4.3.0/system.text.encoding.4.3.0.nupkg.sha512",
"/home/mrfluffy/.cache/NuGetPackages/system.threading.tasks/4.3.0/system.threading.tasks.4.3.0.nupkg.sha512",
"/home/mrfluffy/.cache/NuGetPackages/microsoft.aspnetcore.app.ref/6.0.6/microsoft.aspnetcore.app.ref.6.0.6.nupkg.sha512"
],
"logs": []
}

View File

@@ -1,249 +0,0 @@
using ConsoleTables;
class simplex
{
public void simplexAlgo()
{
file file = new file();
Tuple<List<zConstraints>, List<Constraints>> content = file.readFile();
List<zConstraints> zConstraintsList = content.Item1;
List<Constraints> constraintsList = content.Item2;
// print constraintsList
foreach (zConstraints constraints in zConstraintsList)
{
Console.WriteLine(constraints.minMax + " " + string.Join(" ", constraints.values));
}
foreach (Constraints constraints in constraintsList)
{
Console.WriteLine(constraints.sign + " " + string.Join(" ", constraints.values));
}
List<List<float>> table = new List<List<float>>();
table.Add(zConstraintsList[0].values);
// add all constraints in constraintsList to table
foreach (Constraints constraints in constraintsList)
{
table.Add(constraints.values);
}
List<List<float>> newTable = new List<List<float>>();
// add all rows in table to newTable
foreach (List<float> row in table)
{
// add all columns in row to newTable without reference to table
List<float> newRow = new List<float>();
for (int i = 0; i < row.Count; i++)
{
newRow.Add(row[i]);
}
newTable.Add(newRow);
}
// add s variable to table
for (int i = 0; i < table.Count; i++)
{
if (i == 0)
{
for (int j = 0; j < table[i].Count + 1; j++)
{
newTable[i].Add(0);
}
}
else
{
for (int j = 0; j < table[i].Count-1; j++)
{
//save the last value in newTable in to lastVal and remove it from newTanle
float lastVal = newTable[i][newTable[i].Count - 1];
newTable[i].RemoveAt(newTable[i].Count - 1);
if (i == j+1)
{
newTable[i].Add(1);
}
else
{
newTable[i].Add(0);
}
newTable[i].Add(lastVal);
}
}
}
// print table
printTable(newTable);
bool optimal = false;
newTable = flipZ(newTable);
while (!optimal)
{
int pivotCol = findPivotCol(newTable);
List<float> ratio = ratioTest(newTable, pivotCol);
int pivotRow = findPivotRow(ratio);
printTable(newTable);
newTable = pivotTable(newTable, pivotRow, pivotCol);
Console.WriteLine("");
if (checkOptimal(newTable))
{
printTable(newTable);
optimal = true;
}
}
}
static void printTable(List<List<float>> newTable)
{
string[] headers = new string[newTable[0].Count];
double half = newTable[0].Count / 2;
int halfInt = (int)Math.Floor(half);
for (int i = 0; i < newTable[0].Count; i++)
{
if (i != newTable[0].Count - 1 && i < halfInt)
{
headers[i] = "x" + (i + 1);
}
else if (i != newTable[0].Count - 1 && i >= halfInt)
{
// add "s" to headers starting at 1
headers[i] = "s" + ((i - newTable[0].Count / 2)+1);
//headers[i] = "s" + (i + 1);
}
else
{
headers[i] = "rhs";
}
}
var conTable = new ConsoleTable(headers);
// for each row in table add row to conTable
foreach (List<float> row in newTable)
{
// convert row to object array
object[] rowArray = new object[row.Count];
for (int i = 0; i < row.Count; i++)
{
rowArray[i] = row[i];
}
conTable.AddRow(rowArray);
}
conTable.Write(Format.Alternative);
}
static bool checkOptimal(List<List<float>> table)
{
int zIndex = 0;
for (int i = 0; i < table[0].Count; i++)
{
if (table[0][i] < 0)
{
zIndex = i;
}
}
if (zIndex == 0)
{
return true;
}
else
{
return false;
}
}
static List<List<float>> flipZ(List<List<float>> table)
{
for (int i = 0; i < table[0].Count; i++)
{
if (table[0][i] > 0)
{
table[0][i] = -table[0][i];
}
}
return table;
}
static int findPivotCol(List<List<float>> table)
{
float largest = 0;
int largestIndex = 0;
for (int i = 0; i < table[0].Count; i++)
{
if (table[0][i] < largest)
{
largest = table[0][i];
largestIndex = i;
}
}
return largestIndex;
}
static List<float> ratioTest(List<List<float>> table, int testCol)
{
List<float> ratios = new List<float>();
for (int i = 1; i < table.Count; i++)
{
if (table[i][testCol] != 0)
{
ratios.Add(table[i][table[i].Count - 1] / table[i][testCol]);
}
else
{
ratios.Add(float.MaxValue);
}
}
return ratios;
}
static int findPivotRow(List<float> ratios)
{
float smallest = float.MaxValue;
int smallestIndex = 0;
for (int i = 0; i < ratios.Count; i++)
{
if (ratios[i] < smallest && ratios[i] > 0.0)
{
smallest = ratios[i];
smallestIndex = i;
}
}
return smallestIndex;
}
static List<List<float>> pivotTable(List<List<float>> table, int pivotRow, int pivotCol)
{
//clone table in to newTable
List<List<float>> newTable = new List<List<float>>();
foreach (List<float> row in table)
{
List<float> newRow = new List<float>();
for (int i = 0; i < row.Count; i++)
{
newRow.Add(row[i]);
}
newTable.Add(newRow);
}
var pivotPoint = newTable[pivotRow + 1][pivotCol];
// divide pivot row by pivot point
for (int i = 0; i < newTable[pivotRow + 1].Count; i++)
{
newTable[pivotRow + 1][i] = newTable[pivotRow + 1][i] / pivotPoint;
}
// current possition-(pivot_row*new_table pivot_point)
for (int i = 0; i < newTable.Count; i++)
{
if (i != pivotRow + 1)
{
var currentPossition = newTable[i][pivotCol];
for (int j = 0; j < newTable[i].Count; j++)
{
newTable[i][j] = newTable[i][j] - (currentPossition * newTable[pivotRow + 1][j]);
}
}
}
return newTable;
}
}

View File

@@ -1,432 +0,0 @@
using ConsoleTables;
class twoPhaseSimplex
{
public void twoPhaseSimplexAlgo()
{
file file = new file();
Tuple<List<zConstraints>, List<Constraints>> content = file.readFile();
List<zConstraints> zConstraintsList = content.Item1;
List<Constraints> constraintsList = content.Item2;
// print constraintsList
foreach (zConstraints constraints in zConstraintsList)
{
Console.WriteLine(constraints.minMax + " " + string.Join(" ", constraints.values));
}
foreach (Constraints constraints in constraintsList)
{
Console.WriteLine(constraints.sign + " " + string.Join(" ", constraints.values));
}
List<List<float>> table = new List<List<float>>();
table.Add(zConstraintsList[0].values);
// add all constraints in constraintsList to table
foreach (Constraints constraints in constraintsList)
{
table.Add(constraints.values);
}
List<List<float>> newTable = new List<List<float>>();
// add all rows in table to newTable
foreach (List<float> row in table)
{
// add all columns in row to newTable without reference to table
List<float> newRow = new List<float>();
for (int i = 0; i < row.Count; i++)
{
newRow.Add(row[i]);
}
newTable.Add(newRow);
}
int varCount = newTable[0].Count;
table = prepareTable(newTable, constraintsList);
// print table
printTablePhaseOne(table, varCount);
flipZ(table);
printTablePhaseOne(table, varCount);
bool isOptimal = isOptimalPhaseOne(table);
while (!isOptimal)
{
int pivotCol = findPivotCol(table);
List<float> ratio = ratioTest(table, pivotCol);
int pivotRow = findPivotRow(ratio);
table = pivotTable(table, pivotRow, pivotCol);
printTablePhaseOne(table, varCount);
isOptimal = isOptimalPhaseOne(table);
}
table = dropCol(table, varCount);
isOptimal = isOptimalPhaseTwo(table);
printTablePhaseTwo(table, varCount);
while (!isOptimal)
{
int pivotCol = findPivotCol(table);
List<float> ratio = ratioTest(table, pivotCol);
int pivotRow = findPivotRow(ratio);
table = pivotTable(table, pivotRow, pivotCol);
printTablePhaseTwo(table, varCount);
isOptimal = isOptimalPhaseTwo(table);
}
}
void printTablePhaseOne(List<List<float>> table, int varCount)
{
int count = 1;
string[] headers = new string[table[0].Count];
for (int i = 0; i < table[0].Count; i++)
{
if (i < varCount)
{
headers[i] = "x" + (i + 1);
}
else if (i < table[0].Count - 1)
{
headers[i] = "e" + (count);
headers[i+1] = "a" + (count);
headers[i+2] = "s" + (count);
i = i + 2;
count++;
}
else
{
headers[i] = "rhs";
}
}
var conTable = new ConsoleTable(headers);
foreach (List<float> row in table)
{
// convert row to object array
object[] rowArray = new object[row.Count];
for (int i = 0; i < row.Count; i++)
{
rowArray[i] = row[i];
}
conTable.AddRow(rowArray);
}
conTable.Write(Format.Alternative);
}
void printTablePhaseTwo(List<List<float>> table, int varCount)
{
int count = 1;
string[] headers = new string[table[0].Count];
for (int i = 0; i < table[0].Count; i++)
{
if (i < varCount)
{
headers[i] = "x" + (i + 1);
}
else if (i < table[0].Count - 1)
{
headers[i] = "e" + (count);
headers[i+1] = "s" + (count);
i = i + 1;
count++;
}
else
{
headers[i] = "rhs";
}
}
var conTable = new ConsoleTable(headers);
foreach (List<float> row in table)
{
// convert row to object array
object[] rowArray = new object[row.Count];
for (int i = 0; i < row.Count; i++)
{
rowArray[i] = row[i];
}
conTable.AddRow(rowArray);
}
conTable.Write(Format.Alternative);
}
List<List<float>> prepareTable(List<List<float>> table, List<Constraints> constraints)
{
// save all values in table in to newTable
List<List<float>> newTable = new List<List<float>>();
foreach (List<float> row in table)
{
List<float> newRow = new List<float>();
foreach (float value in row)
{
newRow.Add(value);
}
newTable.Add(newRow);
}
List<int> rowsWithW = new List<int>();
List<string> signs = new List<string>();
foreach (Constraints constraint in constraints)
{
signs.Add(constraint.sign);
}
// ammount of values in newTable startring from newTable[1])
int varCount = 0;
for (int i = 1; i < newTable.Count; i++)
{
varCount = varCount + newTable[i].Count;
}
for (int i = 0; i < signs.Count ; i++)
{
table[0].Add(0);
table[0].Add(0);
table[0].Add(0);
int temp = (newTable[i+1].Count-1) * signs.Count;
// add 3 0s to each row for every column in table
for (int j = 0; j < signs.Count ; j++)
{
if (signs[i] == ">=")
{
// make s = 1
if (i == j)
{
table[i+1].Add(0);
table[i+1].Add(0);
table[i+1].Add(1);
}
else
{
table[i+1].Add(0);
table[i+1].Add(0);
table[i+1].Add(0);
}
}
else if (signs[i] == "<=")
{
//make e and a = 1
if (i == j)
{
table[i+1].Add(-1);
table[i+1].Add(1);
table[i+1].Add(0);
rowsWithW.Add(i+1);
}
else
{
table[i+1].Add(0);
table[i+1].Add(0);
table[i+1].Add(0);
}
}
else if (signs[i] == "=")
{
// make a = 1
if (i == j)
{
table[i+1].Add(0);
table[i+1].Add(1);
table[i+1].Add(0);
rowsWithW.Add(i+1);
}
else
{
table[i+1].Add(0);
table[i+1].Add(0);
table[i+1].Add(0);
}
}
}
}
table[0].Add(0);
// create list of floats called wRow size table[0].Count - 1
List<float> wRow = new List<float>();
for (int i = 0; i < table[0].Count; i++)
{
wRow.Add(0);
}
for (int i = 0; i < table[0].Count; i++)
{
// if i is in rowsWithW
if (rowsWithW.Contains(i))
{
for (int j = 0; j < wRow.Count; j++)
{
wRow[j] = wRow[j] + (-table[i][j]);
}
}
}
//add wRow to the start of table
table.Insert(1, wRow);
// remove intex newTable.Count-1 from table and place it in the back of table
for (int i = 2; i < table.Count; i++)
{
table[i].RemoveAt(newTable.Count-1);
table[i].Add(newTable[i-1][newTable[i-1].Count-1]);
}
// remove the value of newTable.Count-1 from table[1] and place it in the back of table[1]
float lastValue = table[1][newTable.Count-1];
table[1].RemoveAt(newTable.Count-1);
table[1].Add(lastValue);
return table;
}
static List<List<float>> flipZ(List<List<float>> table)
{
for (int i = 0; i < table[0].Count; i++)
{
if (table[0][i] > 0)
{
table[0][i] = -table[0][i];
}
}
return table;
}
static int findPivotCol(List<List<float>> table)
{
float largest = 0;
int largestIndex = 0;
for (int i = 0; i < table[0].Count; i++)
{
if (table[0][i] < largest)
{
largest = table[0][i];
largestIndex = i;
}
}
return largestIndex;
}
static List<float> ratioTest(List<List<float>> table, int testCol)
{
List<float> ratios = new List<float>();
for (int i = 1; i < table.Count; i++)
{
if (table[i][testCol] != 0)
{
ratios.Add(table[i][table[i].Count - 1] / table[i][testCol]);
}
else
{
ratios.Add(float.MaxValue);
}
}
return ratios;
}
static int findPivotRow(List<float> ratios)
{
float smallest = float.MaxValue;
int smallestIndex = 0;
for (int i = 0; i < ratios.Count; i++)
{
if (ratios[i] < smallest && ratios[i] > 0.0)
{
smallest = ratios[i];
smallestIndex = i;
}
}
return smallestIndex;
}
static List<List<float>> pivotTable(List<List<float>> table, int pivotRow, int pivotCol)
{
//clone table in to newTable
List<List<float>> newTable = new List<List<float>>();
foreach (List<float> row in table)
{
List<float> newRow = new List<float>();
for (int i = 0; i < row.Count; i++)
{
newRow.Add(row[i]);
}
newTable.Add(newRow);
}
var pivotPoint = newTable[pivotRow + 1][pivotCol];
// divide pivot row by pivot point
for (int i = 0; i < newTable[pivotRow + 1].Count; i++)
{
newTable[pivotRow + 1][i] = newTable[pivotRow + 1][i] / pivotPoint;
}
// current possition-(pivot_row*new_table pivot_point)
for (int i = 0; i < newTable.Count; i++)
{
if (i != pivotRow + 1)
{
var currentPossition = newTable[i][pivotCol];
for (int j = 0; j < newTable[i].Count; j++)
{
newTable[i][j] = newTable[i][j] - (currentPossition * newTable[pivotRow + 1][j]);
}
}
}
return newTable;
}
//check if the table is optimal first phase
// table is optimal if all values in table[1] are positive
static bool isOptimalPhaseOne(List<List<float>> table)
{
int wIndex = 0;
for (int i = 0; i < table[1].Count; i++)
{
if (table[1][i] < 0)
{
wIndex = i;
}
}
if (wIndex == 0)
{
return true;
}
else
{
return false;
}
}
static bool isOptimalPhaseTwo(List<List<float>> table)
{
int wIndex = 0;
for (int i = 0; i < table[0].Count; i++)
{
if (table[0][i] < 0)
{
wIndex = i;
}
}
if (wIndex == 0)
{
return true;
}
else
{
return false;
}
}
//drop all a coloumn from the table and drop w row from the table
static List<List<float>> dropCol(List<List<float>> table, int varCount)
{
table.RemoveAt(1);
// for each row in table drop the varCount-1th element
for (int i = 0; i < table.Count; i++)
{
for (int j = varCount + 1; j < table[i].Count - 1; j+=3)
{
table[i].RemoveAt(j);
j = j - 1;
}
}
return table;
}
}