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

Topic a7 #51

Open
wants to merge 2 commits into
base: main
Choose a base branch
from
Open
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
106 changes: 106 additions & 0 deletions App/a7.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,106 @@
<?php
require_once 'Work-Cell-Scheduler/App/tdd.php';

$hours = NULL;
$worker = array();
$product = array();
$cell = array();

$hours = rand(1,3);
$numWorker = 5;
$numProduct = 6;
$numCell = 4;
$numProductProduced = 15;
$workersTrained = 20;

$i=NULL;


for ($i=1; $i<=5; $i++){
$worker[]="worker-$i";
}

for ($i=1; $i<=4; $i++){
$cell[]="cell-$i";
}

for ($i=1; $i<=6; $i++){
$product[]="product-$i";
}

//print_r($worker);
//print_r($cell);
//print_r($product);

assertEquals($worker[1],"worker-2");
assertEquals($cell[1],"cell-2");
assertEquals($product[1],"product-2");

$randomWorker = rand(0,$numWorker-1);
//print_r($worker[$randomWorker]);

class Demand{

public $product;
public $cell;
public $hours;

function __construct($p, $c, $h){
$this->hours=$h;
$this->cell=$c;
$this->product=$p;
}

}

//create demand
for($i=0;$i<$numProductProduced;$i++){
$newProduct=array_rand($product,1);
$newCell=array_rand($cell,1);
$demand[]=new Demand($newProduct,$newCell,$hours);
}

//print_r($demand);

class training{

public $attribute;

function __get($p){
return $this->$p;
}

function __set($p, $prod){
$this->$p=$prod;
}
}
$t = new training();
$t->attribute = .80;

//populate Training Matrix with random productivity
//for($i=0;$i<$workersTrained;$i++){
//$newWorker=array_rand($worker,1);
//$newCell=array_rand($cell,1);
//$setKey = "${newWorker}_${newCell}";
//$randomProductivity = rand (50,100)/100;
//$trainingMatrix[$setKey]= $randomProductivity;
//}

foreach ($worker as $newWorker){
$newWorker=array_rand($worker,1);
$newCell=array_rand($cell,1);
$setKey = "${newWorker}_${newCell}";
$randomProductivity = rand (50,100)/100;
$trainingMatrix[$setKey]= $randomProductivity;
}

print_r($trainingMatrix);


//C





?>
87 changes: 87 additions & 0 deletions App/examB.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,87 @@
<?php
require_once 'Work-Cell-Scheduler/WCS/os.php';
require_once 'tdd.php';

function examB(){
$os=New WebIS\OS;
/*$os->addVariable('x11');
$os->addObjCoef('x11','2');
$os->addVariable('x12');
$os->addObjCoef('x12','5');
$os->addVariable('x13');
$os->addObjCoef('x13','3');
$os->addVariable('x14');
$os->addObjCoef('x14','3');
$os->addVariable('x21');
$os->addObjCoef('x21','3');
$os->addVariable('x22');
$os->addObjCoef('x22','2');
$os->addVariable('x23');
$os->addObjCoef('x23','2');
$os->addVariable('x24');
$os->addObjCoef('x24','2');
$os->addVariable('x31');
$os->addObjCoef('x31','3');
$os->addVariable('x32');
$os->addObjCoef('x32','4');
$os->addVariable('x33');
$os->addObjCoef('x33','8');
$os->addVariable('x34');
$os->addObjCoef('x34','4');
$os->addVariable('x41');
$os->addObjCoef('x41','3');
$os->addVariable('x42');
$os->addObjCoef('x42','4');
$os->addVariable('x43');
$os->addObjCoef('x43','2');
$os->addVariable('x44');
$os->addObjCoef('x44','2');
$os->addVariable('x51');
$os->addObjCoef('x51','3');
$os->addVariable('x52');
$os->addObjCoef('x52','2');
$os->addVariable('x53');
$os->addObjCoef('x53','2');
$os->addVariable('x54');
$os->addObjCoef('x54','2');
*/

$supplier = array(1,2,3,4);
$department = array(1,2,3,4,5);
$shipping = array(
array(2,5,3,3),
array(3,2,2,2),
array(3,4,8,4),
array(3,4,2,2),
array(3,2,2,2),
);
$capacity = array(600,200,300,500);
$profit = array(20,30,40,25,25);
$demand = array(600,200,300,100,300);
$prodCosts = array(10,14,40,11);

//print_r($shipping);
//random shipping&suppliers
foreach ($supplier as $newSupplier){
$newSupplier=array_rand($supplier,1);
$newDepartment=array_rand($department,1);
$setKey = "${newSupplier}_${newDepartment}";
$shippingMatrix[$setKey]= $shipping;
}
//print_r($shippingMatrix);

foreach(array_combine($department, $demand) as $dp => $dm){
$os->addConstraint(NULL, $dp);

}
foreach(array_combine($supplier, $capacity) as $sup => $cap){
$os->addConstraint(NULL, $sup);

}

//$os->solve();
}

examB();

?>
161 changes: 161 additions & 0 deletions App/osbasics.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,161 @@
<?php
echo "osbasics";

// problem 1
echo "1";

assert(TRUE);

// problem 2
echo "2";

function tddStringEquals($a,$b){
if (!($a===$b)){
return FALSE;
}
return TRUE;
}
assert(tddStringEquals("One","One"));

// problem 3
echo "3";

function assertEquals($expected,$result){
if ($expected!==$result){
throw new Exception("Expected string does not match result");
}
return TRUE;
}

function assertNotEquals($expected, $result){
if ($expected===$result){
throw new Exception("Expected string matches result");
}
return TRUE;
}

assertEquals("One","One");
assertNotEquals("One","Two");


// To trigger Exceptions

//assertEquals("One","Two");
//assertNotEquals("One","One");


//problem 4
echo "4";

try {
assertEquals("One", "Two");
}
catch (Exception $e){
$failed=TRUE;
}
assert($failed);

try {
assertNotEquals("One", "One");
}
catch (Exception $e){
$failed=TRUE;
}
assert($failed);


// problem 5

echo "5";

$xml = <<<XML
<?xml version="1.0"?>
<osil><instanceHeader></osil>
XML;


function osil(){
$osil = new simpleXMLElement ("<osil/>");
$osil -> addChild ('instanceHeader');
return $osil -> asXML();

}
//assertEquals($xml,osil());


// problem 6a
echo "6";

function assertContainsString($needle, $haystack){
if(strpos($haystack, $needle)===FALSE){
throw new Exception("assertContainsString: |$needle |$haystack");
}
return TRUE;
}

assertContainsString("one", "one two three");
//assertContainsString("zero", "one two three");

// problem 6b
function assertContains($needle, $hay){
foreach ($hay as $h)
if(strpos($h, $needle)===FALSE){
throw new Exception("assertContains: |$needle |$hay");
}
return TRUE;
}

assertContains("needle", array("needle hay", "hay needle"));


// problem 7
echo "7";

exec("\\WebIS\\bin\\OSsolverservice.exe -h", $output, $result);
print_r($output);


assertEquals(0,$result);

// problem 8
echo "8";

function write($file){
$osil = new simpleXMLElement ("<osil/>");
$osil -> addChild ('instanceHeader');
return $osil -> asXML($file);
}
write("test.xml");
//read file
$xml = file_get_contents("test.xml");
assertEquals($xml,osil());

// problem 9
echo "9";

function solve(){
exec("\\WebIS\\bin\\OSsolverservice.exe -osil test.xml -osrl solution.xml", $output, $result);
if($result !==0){
throw new Exception("Solve function failed!\n".implode("\n",$output));
}
return TRUE;
}
$osil = new simpleXMLElement ('<osil/>');
$osil -> addChild("instanceHeader");
$osil -> addChild("instanceData") -> addChild ("objectives") -> addChild("obj") -> addAttribute("objCoeffiencts", 0);
$osil -> asXML('test.xml');
assert(solve());

//problem 10
echo "10";

function solution(){
$xml = file_get_contents(asXML('solution.xml'));
$osrl = new simpleXMLElement($xml);
$result = (string)$osrl -> Optimization -> solution -> status -> attributes() -> type();
$value = (double)$osrl -> Optimization -> solution -> objectives -> values -> obj;
return $value;
}
echo "11";

?>
Loading