本文整理汇总了C++中IntervalVector::subvector方法的典型用法代码示例。如果您正苦于以下问题:C++ IntervalVector::subvector方法的具体用法?C++ IntervalVector::subvector怎么用?C++ IntervalVector::subvector使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类IntervalVector
的用法示例。
在下文中一共展示了IntervalVector::subvector方法的4个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: contract
void CtcFirstOrderTest::contract(IntervalVector& box, ContractContext& context) {
if(box.size() == 2) {
return;
}
BxpNodeData* node_data = (BxpNodeData*) context.prop[BxpNodeData::id];
if(node_data == nullptr) {
ibex_error("CtcFirstOrderTest: BxpNodeData must be set");
}
vector<IntervalVector> gradients;
for (int i = 0; i < system_.normal_constraints_.size() - 1; ++i) {
if (!system_.normal_constraints_[i].isSatisfied(box)) {
gradients.push_back(system_.normal_constraints_[i].gradient(box));
}
}
for (int i = 0; i < system_.sic_constraints_.size(); ++i) {
if (!system_.sic_constraints_[i].isSatisfied(box, node_data->sic_constraints_caches[i])) {
gradients.push_back(system_.sic_constraints_[i].gradient(box, node_data->sic_constraints_caches[i]));
}
}
// Without the goal variable
IntervalMatrix matrix(nb_var - 1, gradients.size() + 1);
matrix.set_col(0, system_.goal_function_->gradient(box.subvector(0, nb_var - 2)));
for (int i = 0; i < gradients.size(); ++i) {
matrix.set_col(i + 1, gradients[i].subvector(0, nb_var - 2));
}
bool testfailed = true;
if (matrix.nb_cols() == 1) {
if (matrix.col(0).contains(Vector::zeros(nb_var - 2))) {
testfailed = false;
}
} else {
int* pr = new int[matrix.nb_rows()];
int* pc = new int[matrix.nb_cols()];
IntervalMatrix LU(matrix.nb_rows(), matrix.nb_cols());
testfailed = true;
try {
interval_LU(matrix, LU, pr, pc);
} catch(SingularMatrixException&) {
testfailed = false;
}
delete[] pr;
delete[] pc;
}
if(testfailed) {
box.set_empty();
}
}
示例2: do_Sivia
//.........这里部分代码省略.........
IntervalVector currentBox = data.boxes.front(); //start from the first one
data.boxes.pop_front(); //once it has been copied remove the first box
IntervalVector auxBox=currentBox; //store it in aux variable to compare later
tubeConstraints.contract(currentBox); //contract the current box using the previously calculated constraints
if (currentBox!=auxBox){ //if the box has been contracted
IntervalVector* removedByContractor;
int setDiff=auxBox.diff(currentBox, removedByContractor); //set difference between the contracted box and the original box
for (int i = 0; i < setDiff; ++i) {
data.boxesOutside.push_back(removedByContractor[i]); //add the areas removed by the contractor to the outside set
}
delete[] removedByContractor;
}
if(data.realTimeDraw){ //draw the boxes processing in real time
draw_update(data, auxBox, currentBox);
}
bool allBoxesLessEpsilon=true; //check if all the boxes are smaler than epsilon
for (int i=0;(i<(currentBox.size()-1));i++){
allBoxesLessEpsilon = (allBoxesLessEpsilon && ((currentBox.diam()[i])<=data.epsilons[i]));
}
allBoxesLessEpsilon = (allBoxesLessEpsilon && ((currentBox[currentBox.size()-1].diam())<=data.dt)); //check the time box also
bool boxesLessEpsilon=false; //check if at least one box is smaller than epsilon
for (int i=0;(i<(currentBox.size()-1));i++){
boxesLessEpsilon = boxesLessEpsilon||((currentBox[i].diam())<=data.epsilons[i]);
}
boxesLessEpsilon = boxesLessEpsilon&&((currentBox[currentBox.size()-1].diam())<=data.dt); //check time box
if (boxesLessEpsilon && !allBoxesLessEpsilon){
IntervalVector xnext = currentBox.subvector(0, data.numVarF-1).mid(); //using the middle point of the box calculate the future positions using euler method
IntervalVector x = currentBox.mid();
bool testBackIn;
for (int i = 0;i<data.numFuturePos;i++){ // Euler method: x(n+1)=x(n)+dt*fx
x[data.numVarF]= x[data.numVarF].mid();
testBackIn = true;
xnext=xnext+(data.dt)*data.f->eval_vector(x);
x.put(0, xnext);
x[data.numVarF] = x[data.numVarF]+(data.dt);
IntervalVector gg=data.g->eval_vector(x);
for(int j = 0; j<gg.size(); j++){
testBackIn = testBackIn && (gg[j].ub()<0); //test if it comes back to the bubble
}
if(testBackIn == true){
break;
}
}
if(testBackIn == true && data.enableBackIn){ //If my box was back in the bubble after integration, I store it in boxesbackin
(data.boxesBackIn).append(currentBox);
continue;
}
}
if (allBoxesLessEpsilon) { //if allBoxesLessEpsilon = true the box is unsafe and I continue my loop
(data.boxesUnsafe).push_back(currentBox);
count++;
if (count >=data.maxNumUnsafeBoxes && data.maxNumUnsafeBoxesActivated){ //If I have more boxes than nbPerhaps I stop the loop and I display the results
break;
}
示例3: sip_from_ext_box
IntervalVector sip_from_ext_box(const IntervalVector& ext_box) {
return ext_box.subvector(0, ext_box.size()-2);
}
示例4: do_Sivia
/// Processes the data using contractors and bissections. Classifies the boxes in outside (grey), back_in(yellow) and unsafe (red)
void Sivia::do_Sivia(Ctc& tubeConstraints, Data &data, Function gdot, bool calcInner) {
QTime tSivia;
tSivia.start();
if (calcInner) //inner approximation calculation
{
int count=0;
while (!data.boxes.empty()) {
IntervalVector currentBox = data.boxes.front(); //start from the first one
data.boxes.pop_front(); //once it has been copied remove the first box
IntervalVector auxBox=currentBox; //store it in aux variable to compare later
tubeConstraints.contract(currentBox); //contract the current box using the previously calculated constraints
if (currentBox!=auxBox){ //if the box has been contracted
IntervalVector* removedByContractorInner;
int setDiff=auxBox.diff(currentBox, removedByContractorInner); //set difference between the contracted box and the original box
for (int i = 0; i < setDiff; ++i) {
//data.boxesOutside.push_back(removedByContractor[i]); //add the areas removed by the contractor to the outside set
bool testInside=true;
IntervalVector gg=data.g->eval_vector(removedByContractorInner[i]);
for(int j = 0; j<gg.size(); j++){
testInside = testInside && (gg[j].ub()<=0);
}
if (testInside) {
data.boxesInside.append(removedByContractorInner[i]);
}
}
delete[] removedByContractorInner;
}
if(data.realTimeDraw){ //draw the boxes processing in real time
draw_update(data, auxBox, currentBox);
}
bool allBoxesLessEpsilon=true; //check if all the boxes are smaler than epsilon
for (int i=0;(i<(currentBox.size()-1));i++){
allBoxesLessEpsilon = (allBoxesLessEpsilon && ((currentBox.diam()[i])<=data.epsilons[i]));
}
allBoxesLessEpsilon = (allBoxesLessEpsilon && ((currentBox[currentBox.size()-1].diam())<=data.dt)); //check the time box also
bool boxesLessEpsilon=false; //check if at least one box is smaller than epsilon
for (int i=0;(i<(currentBox.size()-1));i++){
boxesLessEpsilon = boxesLessEpsilon||((currentBox[i].diam())<=data.epsilons[i]);
}
boxesLessEpsilon = boxesLessEpsilon&&((currentBox[currentBox.size()-1].diam())<=data.dt); //check time box
if (boxesLessEpsilon && !allBoxesLessEpsilon){
IntervalVector xnext = currentBox.subvector(0, data.numVarF-1).mid(); //using the middle point of the box calculate the future positions using euler method
IntervalVector x = currentBox.mid();
bool testBackIn;
for (int i = 0;i<data.numFuturePos;i++){ // Euler method: x(n+1)=x(n)+dt*fx
x[data.numVarF]= x[data.numVarF].mid();
testBackIn = true;
xnext=xnext+(data.dt)*data.f->eval_vector(x);
x.put(0, xnext);
x[data.numVarF] = x[data.numVarF]+(data.dt);
IntervalVector gg=data.g->eval_vector(x);
for(int j = 0; j<gg.size(); j++){
testBackIn = testBackIn && (gg[j].ub()<0); //test if it comes back to the bubble
}
if(testBackIn == true){ //If so we calculate the max deviation
break;
}
}
if(testBackIn == true){ //If my box was back in the bubble after integration, I store it in boxesbackin
(data.boxesInsideBackIn).append(currentBox);
continue;
}
}
if (allBoxesLessEpsilon) { //if allBoxesLessEpsilon = true the box is unsafe and I continue my loop
(data.boxesInsideUnsafe).push_back(currentBox);
count++;
if (count >=data.maxNumUnsafeBoxes && data.maxNumUnsafeBoxesActivated){ //If I have more boxes than nbPerhaps I stop the loop and I display the results
break;
}
}
else { //Otherwise we bissect following the widest diameter
double l = 0;
double l_temp = 0;
int v = -1;
for(int i = 0; i<currentBox.size()-1; i++){ //test that the diameter of the boxes doesnt depend on time
if(currentBox[i].is_bisectable()||!(currentBox[i].is_degenerated())){
l_temp = currentBox[i].diam();
//.........这里部分代码省略.........