Patch by Christof Lutteroth:

* copyright headers for the files of the libraries linprog and alm
* new class Summand for representing summands in a linear constraint
* merged class SoftConstraint into class Constraint; Constraint now
  supports both soft and hard constraint functionality
* new AddConstraint methods in class LinearSpec for directly setting
  constraints with 1 to 4 summands
* code cleanups by using aforementioned AddConstraint methods
* a new very simple test application for alm
* some style corrections


git-svn-id: file:///srv/svn/repos/haiku/haiku/trunk@24108 a95241bf-73f2-0310-859d-f6bbb57e9c96
This commit is contained in:
Ingo Weinhold
2008-02-25 01:54:05 +00:00
parent da51719239
commit 0306945545
39 changed files with 918 additions and 1069 deletions
+6
View File
@@ -22,3 +22,9 @@ Application ALMTest2 :
be liblpsolve55.so be liblinprog.so libalm.so
;
Application ALMSimpleTest :
SimpleTest.cpp
:
be liblpsolve55.so be liblinprog.so libalm.so
;
+74
View File
@@ -0,0 +1,74 @@
/*
* Copyright 2007-2008, Christof Lutteroth, [email protected]
* Copyright 2007-2008, James Kim, [email protected]
* Distributed under the terms of the MIT License.
*/
#include <Application.h>
#include <Button.h>
#include <List.h>
#include <Window.h>
#include "Area.h"
#include "BALMLayout.h"
#include "OperatorType.h"
#include "XTab.h"
#include "YTab.h"
using namespace BALM;
class SimpleTestWindow : public BWindow {
public:
SimpleTestWindow(BRect frame)
: BWindow(frame, "SimpleTest", B_TITLED_WINDOW, B_QUIT_ON_WINDOW_CLOSE)
{
fLS = new BALMLayout();
SetLayout(fLS);
button1 = new BButton("button1");
SetBALMLayout();
Show();
}
void
SetBALMLayout()
{
Area* a = fLS->AddArea(fLS->Left(), fLS->Top(), fLS->Right(), fLS->Bottom(), button1);
a->SetLeftInset(10);
fLS->Save("/boot/home/Desktop/test1_ls.txt");
// fLS->AddConstraint(2.0, x1, -1.0, fLS->Right(), OperatorType(EQ), 0.0);
// fLS->AddConstraint(2.0, y1, -1.0, fLS->Bottom(), OperatorType(EQ), 0.0);
}
private:
BALMLayout* fLS;
BButton* button1;
};
class SimpleTest : public BApplication {
public:
SimpleTest()
: BApplication("application/x-vnd.haiku.simpletest")
{
BRect frameRect;
frameRect.Set(100, 100, 392, 366);
SimpleTestWindow* theWindow = new SimpleTestWindow(frameRect);
}
};
int
main()
{
SimpleTest test;
test.Run();
return 0;
}
+15 -5
View File
@@ -1,3 +1,8 @@
/*
* Copyright 2007-2008, Christof Lutteroth, [email protected]
* Copyright 2007-2008, James Kim, [email protected]
* Distributed under the terms of the MIT License.
*/
#include <Application.h>
#include <File.h>
@@ -14,9 +19,9 @@ using namespace BALM;
class TableTestWindow : public BWindow {
public:
TableTestWindow(BRect frame) : BWindow(frame, "TableTest", B_TITLED_WINDOW,
B_QUIT_ON_WINDOW_CLOSE) {
TableTestWindow(BRect frame)
: BWindow(frame, "TableTest", B_TITLED_WINDOW, B_QUIT_ON_WINDOW_CLOSE)
{
BALMLayout* fLS = new BALMLayout();
SetLayout(fLS);
@@ -55,7 +60,9 @@ public:
class TableTest : public BApplication {
public:
TableTest() : BApplication("application/x-vnd.haiku.table-test") {
TableTest()
: BApplication("application/x-vnd.haiku.table-test")
{
BRect frameRect;
frameRect.Set(100, 100, 400, 400);
TableTestWindow* theWindow = new TableTestWindow(frameRect);
@@ -63,8 +70,11 @@ public:
};
int main() {
int
main()
{
TableTest test;
test.Run();
return 0;
}
+20 -19
View File
@@ -1,3 +1,9 @@
/*
* Copyright 2007-2008, Christof Lutteroth, [email protected]
* Copyright 2007-2008, James Kim, [email protected]
* Distributed under the terms of the MIT License.
*/
#include <Application.h>
#include <Button.h>
#include <List.h>
@@ -14,9 +20,9 @@ using namespace BALM;
class Test1Window : public BWindow {
public:
Test1Window(BRect frame) : BWindow(frame, "Test1", B_TITLED_WINDOW,
B_QUIT_ON_WINDOW_CLOSE) {
Test1Window(BRect frame)
: BWindow(frame, "Test1", B_TITLED_WINDOW, B_QUIT_ON_WINDOW_CLOSE)
{
fLS = new BALMLayout();
SetLayout(fLS);
@@ -32,7 +38,9 @@ public:
}
void SetBALMLayout() {
void
SetBALMLayout()
{
XTab* x1 = fLS->AddXTab();
YTab* y1 = fLS->AddYTab();
@@ -40,20 +48,8 @@ public:
fLS->AddArea(x1, fLS->Top(), fLS->Right(), y1, button2);
fLS->AddArea(fLS->Left(), y1, fLS->Right(), fLS->Bottom(), button3);
//~ BList* coeffs1 = new BList(2);
//~ coeffs1->AddItem(new double(2.0));
//~ coeffs1->AddItem(new double(-1.0));
//~ BList* vars1 = new BList(2);
//~ vars1->AddItem(x1);
//~ vars1->AddItem(fLS->Right());
fLS->AddConstraint(2.0, x1, -1.0, fLS->Right(), OperatorType(EQ), 0.0);
//~ BList* coeffs2 = new BList(2);
//~ coeffs2->AddItem(new double(2.0));
//~ coeffs2->AddItem(new double(-1.0));
//~ BList* vars2 = new BList(2);
//~ vars2->AddItem(y1);
//~ vars2->AddItem(fLS->Bottom());
fLS->AddConstraint(2.0, x1, -1.0, fLS->Right(), OperatorType(EQ), 0.0);
fLS->AddConstraint(2.0, y1, -1.0, fLS->Bottom(), OperatorType(EQ), 0.0);
}
@@ -68,7 +64,9 @@ private:
class Test1 : public BApplication {
public:
Test1() : BApplication("application/x-vnd.haiku.test1") {
Test1()
: BApplication("application/x-vnd.haiku.test1")
{
BRect frameRect;
frameRect.Set(100, 100, 392, 366);
Test1Window* theWindow = new Test1Window(frameRect);
@@ -76,8 +74,11 @@ public:
};
int main() {
int
main()
{
Test1 test;
test.Run();
return 0;
}
+18 -30
View File
@@ -1,3 +1,8 @@
/*
* Copyright 2007-2008, Christof Lutteroth, lutteroth@cs.auckland.ac.nz
* Copyright 2007-2008, James Kim, jkim202@ec.auckland.ac.nz
* Distributed under the terms of the MIT License.
*/
#include <Application.h>
#include <Button.h>
@@ -18,9 +23,9 @@ using namespace BALM;
class Test2Window : public BWindow {
public:
Test2Window(BRect frame) : BWindow(frame, "Test2", B_TITLED_WINDOW,
B_QUIT_ON_WINDOW_CLOSE) {
Test2Window(BRect frame)
: BWindow(frame, "Test2", B_TITLED_WINDOW, B_QUIT_ON_WINDOW_CLOSE)
{
fLS = new BALMLayout();
SetLayout(fLS);
@@ -50,7 +55,9 @@ public:
}
void SetBALMLayout() {
void
SetBALMLayout()
{
XTab* x1 = fLS->AddXTab();
XTab* x2 = fLS->AddXTab();
XTab* x3 = fLS->AddXTab();
@@ -67,32 +74,8 @@ public:
fLS->AddArea(fLS->Left(), y2, x1, y3, button5);
fLS->AddArea(x1, y2, x2, y3, button6);
//~ BList* coeffs1 = new BList(2);
//~ coeffs1->AddItem(new double(2.0));
//~ coeffs1->AddItem(new double(-1.0));
//~ BList* vars1 = new BList(2);
//~ vars1->AddItem(x1);
//~ vars1->AddItem(x2);
//~ fLS->AddConstraint(coeffs1, vars1, OperatorType(EQ), 0.0);
fLS->AddConstraint(2.0, x1, -1.0, x2, OperatorType(EQ), 0.0);
//~ BList* coeffs2 = new BList(2);
//~ coeffs2->AddItem(new double(2.0));
//~ coeffs2->AddItem(new double(-1.0));
//~ BList* vars2 = new BList(2);
//~ vars2->AddItem(y1);
//~ vars2->AddItem(y2);
fLS->AddConstraint(2.0, y1, -1.0, y2, OperatorType(EQ), 0.0);
//~ BList* coeffs3 = new BList(3);
//~ coeffs3->AddItem(new double(1.0));
//~ coeffs3->AddItem(new double(1.0));
//~ coeffs3->AddItem(new double(-1.0));
//~ BList* vars3 = new BList(3);
//~ vars3->AddItem(y1);
//~ vars3->AddItem(y2);
//~ vars3->AddItem(y3);
fLS->AddConstraint(1.0, y1, 1.0, y2, -1.0, y3, OperatorType(EQ), 0.0);
fLS->AddArea(fLS->Left(), y3, x2, y4, checkedListBox1);
@@ -147,7 +130,9 @@ private:
class Test2 : public BApplication {
public:
Test2() : BApplication("application/x-vnd.haiku.test2") {
Test2()
: BApplication("application/x-vnd.haiku.test2")
{
BRect frameRect;
frameRect.Set(100, 100, 610, 456);
Test2Window* theWindow = new Test2Window(frameRect);
@@ -155,8 +140,11 @@ public:
};
int main() {
int
main()
{
Test2 test;
test.Run();
return 0;
}
+1 -1
View File
@@ -4,7 +4,7 @@ SetSubDirSupportedPlatformsBeOSCompatible ;
UseLibraryHeaders lp_solve linprog ;
SimpleTest linprog :
SimpleTest linprog_test :
Program.cpp
:
be liblpsolve55.so liblinprog.so
+15 -3
View File
@@ -1,3 +1,8 @@
/*
* Copyright 2007-2008, Christof Lutteroth, lutteroth@cs.auckland.ac.nz
* Copyright 2007-2008, James Kim, jkim202@ec.auckland.ac.nz
* Distributed under the terms of the MIT License.
*/
#include <List.h>
#include <SupportDefs.h>
@@ -10,7 +15,9 @@
#include <stdio.h>
void PrintVars(LinearSpec* ls) {
void
PrintVars(LinearSpec* ls)
{
int32 size = ls->Variables()->CountItems();
Variable* variable;
for (int i = 0; i < size; i++) {
@@ -21,7 +28,9 @@ void PrintVars(LinearSpec* ls) {
}
void Test1() {
void
Test1()
{
LinearSpec* ls = new LinearSpec();
Variable* x1 = ls->AddVariable();
Variable* x2 = ls->AddVariable();
@@ -62,6 +71,9 @@ void Test1() {
}
int main() {
int
main()
{
Test1();
}
+1 -1
View File
@@ -4,7 +4,7 @@ SetSubDirSupportedPlatformsBeOSCompatible ;
UseLibraryHeaders lp_solve ;
SimpleTest lp_solve :
SimpleTest lp_solve_test :
demo.c
:
liblpsolve55.so