source: trunk/Couenne/src/main/CouenneOSInterface.cpp @ 972

Last change on this file since 972 was 490, checked in by pbelotti, 9 years ago

cut repeated (EPL)...

  • Property svn:keywords set to Author Date Id Revision
File size: 3.3 KB
Line 
1/* $Id: CouenneOSInterface.cpp 490 2011-01-14 16:07:12Z tkr $
2 *
3 * Name:    CouenneOS.cpp
4 * Authors:
5 *         
6 * Purpose: Creates a CouenneProblem object from an OSil instance
7 *
8 * (C) Carnegie-Mellon University, 2009.
9 * This file is licensed under the Eclipse Public License (EPL)
10 */
11
12#include "CouenneOSInterface.hpp"
13
14#include "CouenneProblem.hpp"
15
16#include "CouenneTypes.hpp"
17
18#include "CouenneExprSum.hpp"
19#include "CouenneExprMul.hpp"
20#include "CouenneExprClone.hpp"
21#include "CouenneExprGroup.hpp"
22
23#include "BonTMINLP.hpp"
24
25//#include "OSInstance.hpp"
26//class OSInstance;
27
28namespace Bonmin {
29
30  class RegisteredOptions;
31  class Bab;
32  class TMINLP;
33}
34
35using Ipopt::SmartPtr;
36
37using namespace Couenne;
38
39void CouenneOSInterface::registerOptions(Ipopt::SmartPtr<Bonmin::RegisteredOptions> roptions) {
40        roptions->AddStringOption1("osilfile", "name of an osil file to read the problem instance from", "", "*", "name of osil file");
41}
42
43CouenneOSInterface::~CouenneOSInterface() {
44        //delete osinstance;
45        delete problem;
46}
47
48CouenneProblem* CouenneOSInterface::getCouenneProblem() {
49        if (!osinstance) {
50                // create osinstance from osilfile
51        }
52
53  problem = new CouenneProblem;
54
55  //p -> setProblemName (filename); // sets filename member, for later stats -- TODO
56
57  // number of defined variables (aka common expressions)
58  //ndefined_ = 0; // Don't know if OS has them: in AMPL they are
59                 // defined by "var y := f(x)", with f(x) some
60                 // expression
61
62  int n_var = 0; // to be set to no. of variables
63
64  // nonlinear in both objectives and constraints
65  for (int i = 0; i < n_var; i++) 
66    problem -> addVariable (false, problem -> domain ()); // true if integer
67
68  // add objective function(s)
69  expression *expr = NULL; 
70  // fill in the objective
71  problem -> addObjective (expr, "min");  // "max" for maximization
72
73  // add constraints:
74
75  /*
76    addEQConstraint  (expr, new exprConst (ub));  // for equality
77    addLEConstraint  (expr, new exprConst (ub));  // for <=
78    addGEConstraint  (expr, new exprConst (lb));  // for >=
79    addRNGConstraint (expr, new exprConst (lb), new exprConst (ub));  // for range
80  */
81
82  // create room for problem's variables and bounds
83  CouNumber
84    *= (CouNumber *) malloc (n_var * sizeof (CouNumber)),
85    *lb = (CouNumber *) malloc (n_var * sizeof (CouNumber)),
86    *ub = (CouNumber *) malloc (n_var * sizeof (CouNumber));
87
88  for (int i = n_var; i--;) {
89    x  [i] =  0.;
90    lb [i] = -COUENNE_INFINITY;
91    ub [i] =  COUENNE_INFINITY;
92  }
93
94  // create domain point for Couenne
95  problem -> domain () -> push (n_var, x, lb, ub);
96  free (x); free (lb); free (ub);
97
98  // suggested:
99  // problem -> domain () -> push (n_var + problem -> nDefVars(), x, lb, ub, false);
100  // //free (x); free (lb); free (ub);
101  // saves three allocations (default last parameter is true, which copies x,l,b)
102
103  // fill in lower and upper bounds ///////////////////////////////////////////////////////////////
104
105  for (register int i=n_var; i--;) {
106    problem -> Lb (i) = - COUENNE_INFINITY;
107    problem -> Ub (i) =   COUENNE_INFINITY;
108    problem -> X  (i) = 0;
109  }
110
111  // initial x ////////////////////////////////////////////////////////////////////
112
113  return problem;
114}
115
116Ipopt::SmartPtr<Bonmin::TMINLP> CouenneOSInterface::getTMINLP() {
117        return tminlp;
118}
119
120bool CouenneOSInterface::writeSolution(Bonmin::Bab& bab) {
121
122        return false;
123}
Note: See TracBrowser for help on using the repository browser.