[go: up one dir, main page]

Menu

[925ebb]: / OptFrame / MoveCost.hpp  Maximize  Restore  History

Download this file

178 lines (142 with data), 4.1 kB

  1
  2
  3
  4
  5
  6
  7
  8
  9
 10
 11
 12
 13
 14
 15
 16
 17
 18
 19
 20
 21
 22
 23
 24
 25
 26
 27
 28
 29
 30
 31
 32
 33
 34
 35
 36
 37
 38
 39
 40
 41
 42
 43
 44
 45
 46
 47
 48
 49
 50
 51
 52
 53
 54
 55
 56
 57
 58
 59
 60
 61
 62
 63
 64
 65
 66
 67
 68
 69
 70
 71
 72
 73
 74
 75
 76
 77
 78
 79
 80
 81
 82
 83
 84
 85
 86
 87
 88
 89
 90
 91
 92
 93
 94
 95
 96
 97
 98
 99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
// OptFrame - Optimization Framework
// Copyright (C) 2009-2015
// http://optframe.sourceforge.net/
//
// This file is part of the OptFrame optimization framework. This framework
// is free software; you can redistribute it and/or modify it under the
// terms of the GNU Lesser General Public License v3 as published by the
// Free Software Foundation.
// This framework is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU Lesser General Public License v3 for more details.
// You should have received a copy of the GNU Lesser General Public License v3
// along with this library; see the file COPYING. If not, write to the Free
// Software Foundation, 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301,
// USA.
#ifndef OPTFRAME_MOVE_COST_HPP_
#define OPTFRAME_MOVE_COST_HPP_
#include <cstdlib>
#include <iostream>
#include <cmath>
#include "Component.hpp"
using namespace std;
namespace optframe
{
class MoveCost: public Component
{
protected:
// objective function value (cost difference)
evtype objFunction;
// infeasibility measure value (cost difference)
evtype infMeasure;
// constant to mutiply infeasibility weight
evtype weight;
// flag indicating if Evaluation was outdated
bool outdated;
// flag indicating if cost is estimated
bool estimated;
// storing costs for lexicographic approaches
vector<pair<evtype, evtype> > alternatives;
public:
explicit MoveCost(evtype obj, evtype inf = 0, evtype w = 1, bool _outdated = true, bool _estimated = false) :
objFunction(obj), infMeasure(inf), weight(w), outdated(_outdated), estimated(_estimated)
{
}
MoveCost(const MoveCost& mc) :
objFunction(mc.objFunction), infMeasure(mc.infMeasure),
weight(mc.weight), outdated(mc.outdated), estimated(mc.estimated),
alternatives(mc.alternatives)
{
}
virtual ~MoveCost()
{
}
bool isEstimated() const
{
return estimated;
}
const vector<pair<evtype, evtype> >& getAlternativeCosts() const
{
return alternatives;
}
evtype getObjFunctionCost() const
{
return objFunction;
}
evtype getInfMeasureCost() const
{
return infMeasure;
}
void addAlternativeCost(const pair<evtype, evtype>& alternativeCost)
{
alternatives.push_back(alternativeCost);
}
void setAlternativeCosts(const vector<pair<evtype, evtype> >& alternativeCosts)
{
alternatives = alternativeCosts;
}
void setObjFunctionCost(evtype obj)
{
objFunction = obj;
}
void setInfMeasureCost(evtype inf)
{
infMeasure = inf;
}
evtype cost() const
{
return objFunction + weight * infMeasure;
}
// update Evaluation with costs
virtual void update(Evaluation& e)
{
// update objective function value
e.setObjFunction(e.getObjFunction()+objFunction);
// update infeasibility measure value
e.setInfMeasure(e.getInfMeasure()+infMeasure);
// restore previous 'outdated' status, if Evaluation wasn't outdated before
if(!outdated)
e.outdated = outdated;
// may also update lexicographic costs...
}
static string idComponent()
{
return "OptFrame:MoveCost";
}
virtual string id() const
{
return idComponent();
}
virtual void print() const
{
cout << fixed; // disable scientific notation
cout << "Move cost = " << cost() << endl;
if (alternatives.size() > 0)
{
cout << "Alternative Costs: ";
for (unsigned i = 0; i < alternatives.size(); i++)
cout << "(" << alternatives[i].first << ";" << alternatives[i].second << ") ";
cout << endl;
}
}
virtual MoveCost& operator=(const MoveCost& mc)
{
if (&mc == this) // auto ref check
return *this;
objFunction = mc.objFunction;
infMeasure = mc.infMeasure;
outdated = mc.outdated;
estimated = mc.estimated;
alternatives = mc.alternatives;
weight = mc.weight;
return *this;
}
virtual MoveCost& clone() const
{
return *new MoveCost(*this);
}
friend class MultiMoveCost; // TODO: remove! experiment for MO problems
};
}
#endif /*OPTFRAME_MOVE_COST_HPP_*/