Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

A8 #50

Open
wants to merge 15 commits into
base: main
Choose a base branch
from
Open

A8 #50

Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 9 additions & 9 deletions WCS/os.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,17 +5,17 @@
class OS {
static $DEBUG=FALSE;
static $solver="\\WebIS\\bin\OSSolverService.exe";
static $tmp="\\WebIS\\tmp\\"; // trailing slash required.
static $temp="\\WebIS\\tmp\\"; // trailing slash required.
private $linear=FALSE;

private $osil=NULL;
private $osrl=NULL;
private $var=array(); // Reverse IDX mapping ($idx->$name).
private $value=NULL; // Solution value.
private $solution=NULL;
public $osil=NULL;
public $osrl=NULL;
public $var=array(); // Reverse IDX mapping ($idx->$name).
public $value=NULL; // Solution value.
public $solution=NULL;


function __construct($maxOrMin='min') {
function __construct($maxOrMin='max') {
$osil=new \SimpleXMLElement('<osil/>');
$osil->addChild('instanceHeader')->addChild('name',php_uname('n').' '.date('c'));
$data=$osil->addChild('instanceData');
Expand Down Expand Up @@ -105,8 +105,8 @@ function addConstraintCoef($name,$value){
}

function solve(){
$osilfile=tempnam(OS::$tmp,'OS-');
$osrlfile=tempnam(OS::$tmp,'OS-');
$osilfile=tempnam(OS::$temp,'OS-');
$osrlfile=tempnam(OS::$temp,'OS-');
if(self::$DEBUG){
$osilfile='osil.xml';
$osrlfile='osrl.xml';
Expand Down
2 changes: 2 additions & 0 deletions Web/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
/solution.xml
/test.xml
135 changes: 135 additions & 0 deletions Web/Final-partA.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,135 @@
<?php

echo "IMSE 4420 Final - Part A\n";

require_once 'Work-Cell-Scheduler/WCS/os.php';

//$supplier =array('S1'=>600,'S2'=>300,'S3'=>200);
//$department=array('D1'=>600,'D2'=>200,'D3'=>300);
//$dprofit=array('profit-1'=>20,'profit-2'=>30,'profit-3'=>40);

$supplier = array ();
$numSupplier = 4;
for($i = 1; $i <= $numSupplier; $i ++) {
$supplier [] = "S".$i;
}

$numDepart = 5;
for($i = 1; $i <= $numDepart; $i ++) {
$department [] = "D".$i;
}

$numProfit=5;
for ($i=1; $i<=$numProfit; $i++) {
$dprofit[]="profit-".$i;
}

//print_r($supplier)."\n";
//print_r($department)."\n";

//added part e.
$distance = array (
'D1_S1' => 2,
'D1_S2' => 5,
'D1_S3' => 3,
'D1_S4' => 3,
'D2_S1' => 3,
'D2_S2' => 2,
'D2_S3' => 2,
'D2_S4' => 2,
'D3_S1' => 3,
'D3_S2' => 4,
'D3_S3' => 8,
'D3_S4' => 4,
'D4_S1' => 3,
'D4_S2' => 4,
'D4_S3' => 2,
'D4_S4' => 2,
'D5_S1' => 3,
'D5_S2' => 2,
'D5_S3' => 2,
'D5_S4' => 2

);
//part e) shown in $distance - added S4, D4, D5
//distsance calculated below - $distance - 5 BONUS POINTS!
print_r($distance);

$capacity = array (0,600,300,200,500);
$demand = array (0,600,200,300,100,300);
$dProfit = array ('D1' => 20,'D2' => 30,'D3' => 40, 'D4' => 25,'D5' => 25);
//print_r($dProfit);

// create supply capacity
$supplyVar = array ();
for($i = 1; $i <= $numSupplier; $i ++) {
$supplyVar ["S$i"] = $capacity [$i];
}
// print_r($supplyVar);

// create department demand
$demandVar = array ();
for($i = 1; $i <= $numDepart; $i ++) {
$demandVar ["D$i"] = $demand [$i];
}
// print_r($demandVar);

// create decision variable
$decVar = array ();
foreach ( $supplier as $s ) {
foreach ( $department as $d ) {
$decVar [] = "{$s}_{$d}";
}
}
//print_r($decVar);

// problem f) add plant production costs
$pCosts=array('S1'=>10,'S2'=>14,'S3'=>40,'S4'=>11);
//print_r($pCosts);
$costs=array();
foreach ($supplier as $s) {
$costs[]=$pCosts[$s];
}
//print_r($costs);

// define real profit - objective
$realProfit = array ();
foreach ( $supplier as $key => $value ) {
foreach ( $dProfit as $k => $v ) {
$newkey = "{$k}_{$value}";
$realProfit [$newkey] = $v - $distance [$newkey] - $pCosts[$s];
}
}
// f) complete in $realProfit - 10 POINTS
print_r($realProfit);

// create OSIL

$os = new \WebIS\OS ();

foreach ( $decVar as $dVar ) {
$os->addVariable ( "$dVar" );
$os->addObjCoef ( "$dVar" , $value) ;
}

// create supply constraint
foreach ( $supplier as $s ) {
$os->addConstraint ( $supplyVar [$s], NULL );
foreach ( $department as $d ) {
$os->addConstraintCoef ( "{$s}_{$d}", 1 );
}
}

// create demand constraint
foreach ( $department as $d ) {
$os->addConstraint ( NULL, $demandVar [$d] );
foreach ( $supplier as $s ) {
$os->addConstraintCoef ( "{$s}_{$d}", 1 );
}
}

$os -> solve();
//print_r ( $os );

//print_r("end of exam");
?>
81 changes: 81 additions & 0 deletions Web/Final-partB.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,81 @@
<?php

require_once 'Work-Cell-Scheduler/WCS/os.php';

//define departments
$department=array();
$numDep=rand(5,10);
for($i=0;$i<$numDep;$i++){
$department[]="D$i";
}
//print_r($department);

//define suppliers
$supplier=array();
$numSup=rand(5,10);
for($i=0;$i<$numSup;$i++){
$supplier[]="S$i";
}
//print_r($supplier)

// define demand
$demand=array();
for($i=0;$i<$numDep;$i++){
$demand["D$i"]=rand(20,1000);
}
//print_r($demand);

// define supply
$supply=array();
for($i=0;$i<$numSup;$i++){
$supply["S$i"]=rand(50,800);
}
//print_r($supply);

// define decision variable
$decVar=array();
foreach($supplier as $s){
foreach($department as $d){
$decVar[]="{$s}_{$d}";
}
}

// define profit
$profit=array();
foreach($demand as $key=>$d){
$profit[$key]=rand(5,50);
}
//print_r($profit)

// create cost / distance
$cost=array();
foreach($decVar as $key => $var){
$cost[$var]=rand(2,10);
}
//print_r($cost)

// create real profit
$realProfit=array();
foreach($department as $d){
$value=$profit[$d];
foreach ($supplier as $s){
$realProfit["{$s}_{$d}"]=$value-$cost["{$s}_{$d}"];
}
}
print_r($realProfit);

// create OSIL file

$os=new \WebIS\OS;

foreach ( $realProfit as $key => $value ) {
$os->addVariable ( $key );
$os->addObjCoef ( $key, $value );
}

$os -> solve();
print_r($os);



?>
76 changes: 76 additions & 0 deletions Web/Final.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,76 @@
<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<title>Decision Support Systems - IMSE 4420 Final</title>
</head>
<body>
<h1>Sean McLerran - scmmv4</h1>
<h2>Supply Data</h2>
<table border='1'>
<tr>
<td>Supplier</td>
<?php
foreach ($supplier as $s){
echo"<td>$s</td>";
}
echo"<tr><td>Supply</td>";
foreach($supplyVar as $s){
echo"<td>$s</td>";
}
echo"</tr>";
?>
</tr>
</table>
<h2>Demand Data</h2>
<table border='1'>
<tr>
<td>Department</td>
<?php
foreach ($department as $d){
echo"<td>$d</td>";
}
echo"<tr><td>Demand</td>";
foreach($demandVar as $d){
echo"<td>$d</td>";
}
echo"<tr>";
?>
</tr>
</table>
<h2>Profit Data</h2>
<table border='1'>
<tr>
<td>Department</td>
<?php
foreach ($departments as $d){
echo"<td>$d</td>";
}
echo"<tr><td>Profit</td>";
foreach($dProfit as $p){
echo"<td>$p</td>";
}
echo"<tr>";
?>
</tr>
</table>

<h2>Shipping Data</h2>
<table border='1'>
<tr>
<td>Supplier to Department</td>
<?php
foreach ($decVar as $d){
echo"<td>$d</td>";
}
echo"<tr><td>Real Profit</td>";
foreach($realProfit as $p){
echo"<td>$p</td>";
}
echo"</tr>";
?>
</tr>
</table>

</body>
</html>
41 changes: 41 additions & 0 deletions Web/OSRL.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<title>OSRL Solution</title>
</head>
<body>
<h1>Sean McLerran - scmmv4</h1>
<h2>OSRL Solution</h2>
<table border='1'>
<tr>
<td>Objective Value</td>
</tr>
<?php
$objvalue=$os->solve();
echo "<tr><td>$objvalue</td><td>"
?>
</table>
<h2>Shipping Values</h2>
<table border='1'>
<tr>
<th></th>
<?php
foreach($supplier as $s){
echo "<th>$s\n";
}
?>
</tr>
<?php
foreach($department as $d){
echo "<tr><th>$d</th>";
foreach($supplier as $s){
echo "<td>".$os->getVariable("{$s}_{$d}")."</td>";
echo "\n";
}
}
?>
</table>
<br>
</body>
</html>
Loading