diff --git a/App/osbasics.php b/App/osbasics.php
new file mode 100644
index 0000000..bbf79ac
--- /dev/null
+++ b/App/osbasics.php
@@ -0,0 +1,200 @@
+
+
+XML;
+
+function osil(){
+ $osil=new SimpleXMLElement('');
+ $osil-> addChild('instanceHeader');
+ return $osil-> asXML();
+
+AssertEquals($xml,$osil);
+}
+
+//Problem 6a
+
+function AssertContainsString($needle,$haystack){
+ if (strpos($haystack,$needle)===FALSE){
+ throw new Exception("AssertContainsString failed");
+ }
+}
+AssertContainsString("needle","haystack needle");
+//AssertContainsString("needle","nada");
+
+//AssertContainsString("needle","nada");
+$failed=FALSE;
+try{
+ //AssertContainsString("needle","needle");
+ AssertContainsString("needle","HAY");
+} catch (Exception $e){
+ $failed=TRUE;
+}
+assert($failed);
+
+//echo "passed\n";
+
+//Problem 6b
+
+function AssertContains($needle,$hay){
+ foreach($hay as $h)
+ if (strpos($h,$needle)!==FALSE){
+ return TRUE;
+ }
+ throw new Exception("AssertContains failed");
+}
+AssertContains("needle",array("needle hay","hay needle"));
+//AssertContains("needle",array("hay hay","hay hay hay"));
+
+$failed=FALSE;
+try{
+ AssertContains("needle",array("hay","hay no sharp objects"));
+} catch (Exception $e){
+ $failed=TRUE;
+}
+assert($failed);
+
+//Problem 7
+
+exec("\\WebIS\\bin\\OSSolverService.exe -h",$output,$result);
+
+AssertEquals(0,$result);
+
+//print_r ($output);
+
+$failed=FALSE;
+try{
+ AssertContains("OS Version X.Y.Z",$output);
+ //AssertContains("OS Version: 2.",$output);
+} catch (Exception $e){
+ $failed=TRUE;
+}
+assert($failed);
+
+AssertContains("OS Version: 2.",$output);
+
+//problem 8
+
+function write($file){
+ $osil=new SimpleXMLElement('');
+ $osil -> addchild('instanceHeader');
+ return $osil-> asXML($file);
+}
+
+write('test.xml');
+$xxml=file_get_contents('test.xml');
+
+//print_r($xxml);
+//print_r(osil());
+AssertEquals($xxml,osil());
+
+
+//Problem 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 -> addchild('instanceHeader');
+$osil -> addChild('instanceData') -> addChild('objectives') -> addChild('obj') -> addAttribute('numberOfObjCoef',0);
+$osil -> asXML('test.xml');
+
+assert(solve());
+
+
+//problem 10
+
+
+function solution(){
+ $xml=file_get_contents('solution.xml');
+ //print_r($xml);
+ $osrl=new simpleXMLElement($xml);
+ //print_r($osrl);
+ $result=(string)$osrl -> optimization->solution->status->attributes()->type();
+ //print_r($result);
+ $value=(double)$osrl->optimization->solution->objectives->values->obj;
+ //print_r($value);
+ return $value;
+ //AssertEquals("optimal",$result);
+ //problem 11
+ //AssertContains("PARSER ERROR",$xml);
+}
+//solution();
+//assertEquals(solution(),0);
+
+//problem 12
+
+
+
+echo "done";
+
+?>
\ No newline at end of file
diff --git a/App/test.xml b/App/test.xml
new file mode 100644
index 0000000..edb4422
--- /dev/null
+++ b/App/test.xml
@@ -0,0 +1,2 @@
+
+
diff --git a/WCS/os.php b/WCS/os.php
index e9a4abb..393502e 100644
--- a/WCS/os.php
+++ b/WCS/os.php
@@ -6,15 +6,16 @@ class OS {
static $DEBUG=FALSE;
static $solver="\\WebIS\\bin\OSSolverService.exe";
static $tmp="\\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;
- private $linear=FALSE;
- function __construct($maxOrMin='min') {
+ function __construct($maxOrMin='max') {
$osil=new \SimpleXMLElement('');
$osil->addChild('instanceHeader')->addChild('name',php_uname('n').' '.date('c'));
$data=$osil->addChild('instanceData');
@@ -42,7 +43,7 @@ function getName(){
return (string)$this->osrl->general->instanceName;
}
- function addVariable($name,$type=null){
+ function addVariable($name,$type=NULL){
$variables=$this->osil->instanceData->variables; // shortcut
$this->var[$name]=$variables->var->count(); // $name to $idx (zero based -- preinsert)
$var=$variables->addChild('var');
@@ -72,7 +73,7 @@ function addObjCoef($name,$value){
$obj['numberOfObjCoef']=$obj->coef->count();
}
- function addConstraint($ub=null,$lb=null){
+ function addConstraint($lb,$ub){
$constraints=$this->osil->instanceData->constraints;
$con=$constraints->addChild('con');
if(!is_null($lb)){
@@ -135,7 +136,8 @@ function solve(){
$this->osrl=new \SimpleXMLElement($xml);
$result=(string)$this->osrl->optimization->solution->status->attributes()->type;
if($result!=='optimal'){
- return FALSE;
+ $this->solution=NULL;
+ return $result;
}
// save values to array
@@ -148,11 +150,12 @@ function solve(){
if(self::$DEBUG) print (float)$var."\n";
}
- return (double)$this->osrl->optimization->solution->objectives->values->obj;
+ $this->solution=(double)$this->osrl->optimization->solution->objectives->values->obj;
+ return TRUE;
}
function getSolution(){
- return (double)$solution->objectives->values->obj;
+ return $this->solution;
}
}
diff --git a/WCS/osTest.php b/WCS/osTest.php
index 5578f9c..40c562b 100644
--- a/WCS/osTest.php
+++ b/WCS/osTest.php
@@ -18,29 +18,33 @@ function testOS() {
function testSolver(){
$os=new WebIS\OS();
- $this->assertEquals(0.0,$os->solve(),"Solve empty problem");
+ $this->assertTrue($os->solve(),"Solve empty problem");
+ $this->assertEquals(0.0,$os->getSolution(),"Solution to empty problem is 0.0");
$this->assertContains(date('Y-m-d'),$os->getName(),"Solved today");
$os->addVariable('x1');
- $this->assertEquals(0.0,$os->solve(),"Solve problem with only one variable");
+ $this->assertTrue($os->solve(),"Solve problem with only one variable");
+ $this->assertEquals(0.0,$os->getSolution(),"Solution to one variable is 0.0");
$this->assertEquals(0.0,$os->getVariable('x1'),"x1 is zero");
$os->addObjCoef('x1', '-1');
- $this->assertEquals(0.0,$os->solve());
+ $this->assertEquals("unbounded",$os->solve(),"Problem is unbounded");
+ $this->assertEquals(0.0,$os->getSolution());
$os->addVariable('x2');
$os->addObjCoef('x2', '-2');
- $os->addConstraint(40);
+ $os->addConstraint(NULL,40);
$os->addConstraintCoef('x1',1);
$os->addConstraintCoef('x2',1);
- $os->addConstraint(60);
+ $os->addConstraint(NULL,60);
$os->addConstraintCoef('x1',2);
$os->addConstraintCoef('x2',1);
- $this->assertEquals(-80.0,$os->solve());
+ $this->assertTrue($os->solve());
+ $this->assertEquals(-80.0,$os->getSolution());
$this->assertEquals(0,$os->getVariable('x1'));
$this->assertEquals(40,$os->getVariable('x2'));
## test LB
$os=new WebIS\OS();
$os->addVariable('x1');
- $os->addConstraint(NULL,40);
+ $os->addConstraint(40,NULL);
$this->assertContains('lb=',$os->getOsil());
}
diff --git a/Web/ExamRestart.php b/Web/ExamRestart.php
new file mode 100644
index 0000000..14406da
--- /dev/null
+++ b/Web/ExamRestart.php
@@ -0,0 +1,28 @@
+ 600, "s2" => 300, "s3" => 200);
+//print_r($capacity);
+
+$demand=array("d1"=>600, "d2"=>200, "d3"=>300);
+//print_r($demand);
+
+$profit=array("d1"=>20, "d2"=>30, "d3"=>40);
+//print_r($profit['d1']);
+
+$distance=array("s1,d1"=>2, "s1,d2"=>3, "s1,d3"=>3,"s2,d1"=>5, "s2,d2"=>2, "s2,d3"=>4, "s3,d1"=>3, "s3,d2"=>2, "s3,d3"=>8);
+//print_r($distance['s1,d1']);
+
+$a=$demand['d1']*$profit['d1'];
+//print_r($a);
+$b=$demand['d2']*$profit['d2'];
+$c=$demand['d3']*$profit['d3'];
+
+$revenue=$a+$b+$c;
+//print_r($revenue);
+
+//300 from s1 to d1
+
+//300 from s1 to d3
+
+
+?>
\ No newline at end of file
diff --git a/Web/Final-PartE.php b/Web/Final-PartE.php
new file mode 100644
index 0000000..8e8966d
--- /dev/null
+++ b/Web/Final-PartE.php
@@ -0,0 +1,194 @@
+matrix["${supply}_${department}"]=$shipping;
+ }
+
+ function get($supply,$department){
+ if(array_key_exists("${supply}_${department}",$this->matrix)){
+ return $this->matrix["${supply}_${department}"];
+ }
+ return FALSE;
+ }
+}
+
+$shipping=new ShippingClass;
+
+//Test Get and Set
+assertEquals(FALSE,$shipping->get('supply-0','department-0'));
+$shipping->set('supply-0','department-0',2);
+assertEquals(2,$shipping->get('supply-0','department-0'));
+$shipping->set('supply-0','department-1',3);
+$shipping->set('supply-0','department-2',3);
+$shipping->set('supply-0','department-3',3);
+$shipping->set('supply-0','department-4',3);
+
+$shipping->set('supply-1','department-0',5);
+$shipping->set('supply-1','department-1',2);
+$shipping->set('supply-1','department-2',4);
+$shipping->set('supply-1','department-3',4);
+$shipping->set('supply-1','department-4',2);
+
+$shipping->set('supply-2','department-0',3);
+$shipping->set('supply-2','department-1',2);
+$shipping->set('supply-2','department-2',8);
+$shipping->set('supply-2','department-3',2);
+$shipping->set('supply-2','department-4',2);
+
+$shipping->set('supply-3','department-0',3);
+$shipping->set('supply-3','department-1',2);
+$shipping->set('supply-3','department-2',4);
+$shipping->set('supply-3','department-3',2);
+$shipping->set('supply-3','department-4',2);
+
+
+//print_r($shipping);
+//print_r($shipping->get($supply[0],$department[0]));
+
+
+//Profit for each department respectively
+$d0=array(20,30,40,25,25);
+//print_r($d0[1]);
+
+//Production costs for each plant respectively
+$p0=array(10,14,40,11);
+
+
+//revenue array = (profit for each department) - (shipping cost) - (production cost)
+$revenue=array();
+foreach($supply as $s){
+ foreach(array_combine($department,$d0) as $d => $d1){
+ $var="${s}_${d}";
+ $revenue[$var]=$d1-$shipping->get($s,$d);
+
+ }
+}
+
+foreach($department as $d){
+ foreach(array_combine($supply,$p0) as $s => $p1){
+ $var="${s}_${d}";
+ $revenue[$var]-=$p1;
+ }
+}
+//print_r($revenue);
+
+//Start Optimization
+
+$os=new \WebIS\OS;
+
+//print_r($os->solve());
+assertTrue($os->solve());
+
+foreach($supply as $s){
+ foreach($department as $d){
+ $var="${s}_${d}";
+ //print_r($var."\n");
+ $os->addVariable($var);
+ $os->addObjCoef($var,$revenue[$var]);
+ }
+}
+
+//print_r($os);
+//echo"here\n";
+
+foreach(array_combine($department,$demand) as $dep => $dem){
+ $os->addConstraint($dem,NULL);
+ //print_r($dem."\n");
+ //print_r($dep."\n");
+ foreach($supply as $s){
+ $vari="${s}_${dep}";
+ //print_r($vari."\n");
+ $os->addConstraintCoef($vari,1);
+ }
+}
+
+
+
+foreach(array_combine($capacity,$supply) as $c => $s){
+ $os->addConstraint(NULL,$c);
+ foreach($department as $d){
+ $vari="${s}_${d}";
+ $os->addConstraintCoef($vari,1);
+ }
+}
+
+
+
+assertTrue($os->solve());
+
+
+
+$os->solve();
+$maxprofit=$os->getsolution();
+print_r("max profit: ".$maxprofit."\n");
+
+
+
+//echo"End";
+?>
\ No newline at end of file
diff --git a/Web/FinalPartB.php b/Web/FinalPartB.php
new file mode 100644
index 0000000..719dc7f
--- /dev/null
+++ b/Web/FinalPartB.php
@@ -0,0 +1,130 @@
+matrix["${supply}_${department}"]=$shipping;
+ }
+
+ function get($supply,$department){
+ if(array_key_exists("${supply}_${department}",$this->matrix)){
+ return $this->matrix["${supply}_${department}"];
+ }
+ return FALSE;
+ }
+}
+
+$shipping=new ShippingClass;
+
+foreach($supply as $s){
+$shipping->set($s,$department[array_rand($department)],rand(1,8));
+}
+
+
+//print_r($shipping);
+
+
+
+//Start Optimization
+
+$os=new \WebIS\OS;
+
+//print_r($os->solve());
+assertTrue($os->solve());
+
+foreach($supply as $s){
+ foreach($department as $d){
+ $var="${s}_${d}";
+ //print_r($var."\n");
+ $os->addVariable($var);
+ $os->addObjCoef($var,$shipping->get($s,$d));
+ }
+}
+
+
+
+foreach(array_combine($demand,$department) as $dem => $dep){
+ $os->addConstraint(NULL,$dem);
+ //print_r($dem."\n");
+ //print_r($dep."\n");
+ foreach($supply as $s){
+ $vari="${s}_${dep}";
+ //print_r($vari."\n");
+ $os->addConstraintCoef($vari,1);
+ }
+}
+
+
+
+foreach(array_combine($capacity,$supply) as $c => $s){
+ $os->addConstraint($c,NULL);
+ foreach($department as $d){
+ $vari="${s}_${d}";
+ //print_r($vari."\n");
+ $os->addConstraintCoef($vari,1);
+ }
+}
+
+
+
+
+assertTrue($os->solve());
+//echo"here";
+
+//print_r($os);
+
+$os->solve();
+$minshippingcost=$os->getsolution();
+print_r($minshippingcost);
+//$maxprofit=$revenue-$minshippingcost;
+//print_r("max profit: ".$maxprofit."\n");
+
+
+//echo"End";
+?>
\ No newline at end of file
diff --git a/Web/a6.php b/Web/a6.php
new file mode 100644
index 0000000..711ecf9
--- /dev/null
+++ b/Web/a6.php
@@ -0,0 +1,84 @@
+assertEquals(0,$return);
+ $this->assertContains("OS Version: 2.",$output[5]);
+ }
+
+ function testSolver(){
+ $os=New WebIS\OS;
+ $this->assertEquals(0.0,$os->solve(),"Solve empty problem");
+ $this->assertContains(date('Y-m-d'),$os->getName(),"Solved today");
+ $os->addVariable('x11');
+ //$this->assertEquals(0.0,$os->solve(),"Solve problem with only one variable");
+ //$this->assertEquals(0.0,$os->getVariable('x11'),"x11 is zero");
+ $os->addObjCoef('x11', '3');
+ //$this->assertEquals(0.0,$os->solve());
+
+ $os->addVariable('x12');
+ $os->addObjCoef('x12', '2');
+
+ $os->addVariable('x21');
+ $os->addObjCoef('x21', '1');
+
+ $os->addVariable('x22');
+ $os->addObjCoef('x22', '5');
+
+ $os->addVariable('x31');
+ $os->addObjCoef('x31', '5');
+
+ $os->addVariable('x32');
+ $os->addObjCoef('x32', '4');
+
+ $os->addConstraint($ub=45);
+ $os->addConstraintCoef('x11',1);
+ $os->addConstraintCoef('x12',1);
+
+ $os->addConstraint($ub=60);
+ $os->addConstraintCoef('x21',1);
+ $os->addConstraintCoef('x22',1);
+
+
+ $os->addConstraint($ub=35);
+ $os->addConstraintCoef('x31',1);
+ $os->addConstraintCoef('x32',1);
+
+ $os->addConstraint(null,50);
+ $os->addConstraintCoef('x11',1);
+ $os->addConstraintCoef('x21',1);
+ $os->addConstraintCoef('x31',1);
+
+ $os->addConstraint(null,60);
+ $os->addConstraintCoef('x12',1);
+ $os->addConstraintCoef('x22',1);
+ $os->addConstraintCoef('x32',1);
+
+ print_r($os->solve());
+
+ //$this->assertEquals(-80.0,$os->solve());
+ //$this->assertEquals(0,$os->getVariabl
+
+ //$this->assertEquals(40,$os->getVariable('x2'));
+
+ //print_r($os->getVariable('x11'));
+ //print_r($os->getVariable('x12'));
+
+ }
+}
+
+if (!defined('PHPUnit_MAIN_METHOD')) {
+ OsTestCase::main();
+}
+
+?>
diff --git a/Web/a7.php b/Web/a7.php
new file mode 100644
index 0000000..d20dae3
--- /dev/null
+++ b/Web/a7.php
@@ -0,0 +1,113 @@
+product=$p;
+ //print_r($this->product);
+ $this->cell=$c;
+ $this->hour=$h;
+ }
+
+}
+
+$demand=array();
+
+foreach($product as $p){
+
+ $demand[]=new Demand($p,"$ccell",rand(1,3));
+}
+
+//print_r($demand);
+
+
+//Problem B4
+
+class Training{
+
+
+ public $worker=array();
+ public $cellproductivity=array();
+
+ function __construct($w,$cp){
+ $this->worker=$w;
+ $this->cellproductivity=$cp;
+ }
+
+ function set($p){
+ if($p===NULL){
+ $p=(rand(60,100))/100.0;
+ }
+ print_r($p);
+ }
+
+ function get($worker,$cell,$productivity){
+
+ }
+
+}
+
+$traingingMatrix[]=array();
+
+
+foreach($worker as $w){
+ $w=$worker[rand(0,$numworker-1)];
+ $c=$cell[rand(0,$numcell-1)];
+ $value="${c}_${w}"."\n";
+ $trainingMatrix[$value]=(rand(60,100)/100.0);
+}
+
+//print_r($value);
+
+print_r($trainingMatrix);
+
+
+
+
+
+echo"you made it to the end.";
+
+?>
\ No newline at end of file
diff --git a/Web/osil.xml b/Web/osil.xml
new file mode 100644
index 0000000..5044f93
--- /dev/null
+++ b/Web/osil.xml
@@ -0,0 +1,2 @@
+
+EBE3404-PC-22 2014-04-21T11:20:00-05:003215540246912012345024135111111111111
diff --git a/Web/tdd.php b/Web/tdd.php
new file mode 100644
index 0000000..b31a328
--- /dev/null
+++ b/Web/tdd.php
@@ -0,0 +1,25 @@
+
\ No newline at end of file