Crevice
0.1
Xypron
>
Projects
>
Crevice
> Doxygen
Main Page
Classes
Files
File List
All
Classes
Functions
Variables
Pages
src
problem
TermSign.cc
1
/*
2
* File: TermSign.cc
3
*
4
* Copyright 2012 Heinrich Schuchardt <xypron.glpk@gmx.de>
5
*
6
* Licensed under the Apache License, Version 2.0 (the "License");
7
* you may not use this file except in compliance with the License.
8
* You may obtain a copy of the License at
9
*
10
* http://www.apache.org/licenses/LICENSE-2.0
11
*
12
* Unless required by applicable law or agreed to in writing, software
13
* distributed under the License is distributed on an "AS IS" BASIS,
14
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15
* See the License for the specific language governing permissions and
16
* limitations under the License.
17
*/
18
19
#include "Problem.h"
20
#include "TermSign.h"
21
#include "TermConstant.h"
22
#include <sstream>
23
29
TermSign::TermSign
(
Problem
* problem,
Term
*term) :
30
Term
::
Term
(problem) {
31
term_ = term;
32
}
33
37
TermSign::~TermSign
() {
38
}
39
46
TermSign
*
TermSign::create
(
Problem
* problem,
Term
*term)
throw
47
(
ProblemMismatchException
) {
48
TermSign
* ret =
new
TermSign
(problem, term);
49
ret =
static_cast<
TermSign
*
>
(problem->addTerm(ret));
50
return
ret;
51
}
52
53
Term
*
TermSign::differentiate
(
TermVariable
* variable)
throw
54
(
ProblemMismatchException
) {
55
return
TermConstant::create
(this->getProblem(), 0);
56
}
57
58
double
TermSign::eval
(
59
const
DoubleVector* variableValues,
60
TermValueSet* termValues) {
61
double
value = this->term_->
evaluate
(variableValues, termValues);
62
if
(value > 0) {
63
return
1.;
64
}
else
if
(value < 0) {
65
return
-1.;
66
}
else
{
67
return
0.;
68
}
69
}
70
71
bool
TermSign::less
(
const
Term
* term)
const
{
72
if
(this->
Term::less
(term)) {
73
return
true
;
74
}
else
if
(term->Term::less(
this
)) {
75
return
false
;
76
}
else
{
77
const
TermSign
* term_sign;
78
term_sign =
static_cast<
const
TermSign
*
>
(term);
79
return
this->term_->
less
(term_sign->term_);
80
}
81
}
82
83
std::string
TermSign::toString
()
const
{
84
std::ostringstream os;
85
os <<
"sgn("
<< term_->
toString
() <<
")"
;
86
return
os.str();
87
};
Generated on Sat Feb 1 2014 14:50:31 for Crevice by
1.8.1.2