fix one crash in Collect variables
This commit is contained in:
61
examples/tests/visitor_test.cc
Normal file
61
examples/tests/visitor_test.cc
Normal file
@@ -0,0 +1,61 @@
|
||||
// Copyright 2011-2012 Google
|
||||
// Licensed under the Apache License, Version 2.0 (the "License");
|
||||
// you may not use this file except in compliance with the License.
|
||||
// You may obtain a copy of the License at
|
||||
//
|
||||
// http://www.apache.org/licenses/LICENSE-2.0
|
||||
//
|
||||
// Unless required by applicable law or agreed to in writing, software
|
||||
// distributed under the License is distributed on an "AS IS" BASIS,
|
||||
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
// See the License for the specific language governing permissions and
|
||||
// limitations under the License.
|
||||
|
||||
|
||||
#include "base/hash.h"
|
||||
#include "base/map-util.h"
|
||||
#include "base/stl_util.h"
|
||||
#include "base/random.h"
|
||||
#include "constraint_solver/constraint_solveri.h"
|
||||
#include "constraint_solver/constraint_solver.h"
|
||||
|
||||
namespace operations_research {
|
||||
void TestVisitSumEqual() {
|
||||
Solver solver("BinPacking");
|
||||
const int total_items = 10;
|
||||
const int total_bins = 3;
|
||||
|
||||
// create the variables
|
||||
// Index des lignes => bins
|
||||
// Index des colonnes => items
|
||||
std::vector<operations_research::IntVar*> vars;
|
||||
solver.MakeBoolVarArray(total_items * total_bins, "", &vars);
|
||||
|
||||
//Contrainte ct1 : un item appartient qu'à un seul bin
|
||||
for (int i = 0; i < total_items; ++i) {
|
||||
vector<IntVar*> item_column(total_bins);
|
||||
for(int j = 0; j < total_bins; ++j) {
|
||||
item_column[j] = vars[j + i * total_bins];
|
||||
}
|
||||
solver.AddConstraint(solver.MakeSumEquality(item_column, 1));
|
||||
////////////////////////////////Constraint
|
||||
}
|
||||
|
||||
std::vector<IntVar*> primary_integer_variables;
|
||||
std::vector<IntVar*> secondary_integer_variables;
|
||||
std::vector<SequenceVar*> sequence_variables;
|
||||
std::vector<IntervalVar*> interval_variables;
|
||||
|
||||
solver.CollectDecisionVariables(&primary_integer_variables,
|
||||
&secondary_integer_variables,
|
||||
&sequence_variables,
|
||||
&interval_variables);
|
||||
}
|
||||
} // namespace operations_research
|
||||
|
||||
|
||||
int main(int argc, char** argv) {
|
||||
google::ParseCommandLineFlags(&argc, &argv, true);
|
||||
operations_research::TestVisitSumEqual();
|
||||
return 0;
|
||||
}
|
||||
@@ -656,6 +656,12 @@ $(OBJ_DIR)/gcc_test.$O:$(EX_DIR)/tests/gcc_test.cc $(SRC_DIR)/constraint_solver/
|
||||
$(BIN_DIR)/gcc_test$E: $(CP_DEPS) $(OBJ_DIR)/gcc_test.$O
|
||||
$(CCC) $(CFLAGS) $(OBJ_DIR)/gcc_test.$O $(CP_LNK) $(LDFLAGS) $(EXEOUT)gcc_test$E
|
||||
|
||||
$(OBJ_DIR)/visitor_test.$O:$(EX_DIR)/tests/visitor_test.cc $(SRC_DIR)/constraint_solver/constraint_solver.h
|
||||
$(CCC) $(CFLAGS) -c $(EX_DIR)$Stests/visitor_test.cc $(OBJ_OUT)visitor_test.$O
|
||||
|
||||
$(BIN_DIR)/visitor_test$E: $(CP_DEPS) $(OBJ_DIR)/visitor_test.$O
|
||||
$(CCC) $(CFLAGS) $(OBJ_DIR)/visitor_test.$O $(CP_LNK) $(LDFLAGS) $(EXEOUT)visitor_test$E
|
||||
|
||||
# Linear Programming Examples
|
||||
|
||||
$(OBJ_DIR)/strawberry_fields_with_column_generation.$O: $(EX_DIR)/cpp/strawberry_fields_with_column_generation.cc $(SRC_DIR)/linear_solver/linear_solver.h
|
||||
|
||||
@@ -52,9 +52,11 @@ class CollectVariablesVisitor : public ModelParser {
|
||||
virtual void EndVisitConstraint(const string& type_name,
|
||||
const Constraint* const constraint) {
|
||||
if (type_name.compare(ModelVisitor::kLinkExprVar) == 0 ||
|
||||
type_name.compare(ModelVisitor::kSumEqual) == 0 ||
|
||||
(type_name.compare(ModelVisitor::kSumEqual) == 0 &&
|
||||
Top()->HasIntegerExpressionArgument(ModelVisitor::kTargetArgument))||
|
||||
type_name.compare(ModelVisitor::kElementEqual) == 0 ||
|
||||
type_name.compare(ModelVisitor::kScalProdEqual) == 0 ||
|
||||
(type_name.compare(ModelVisitor::kScalProdEqual) == 0 &&
|
||||
Top()->HasIntegerExpressionArgument(ModelVisitor::kTargetArgument))||
|
||||
type_name.compare(ModelVisitor::kIsEqual) == 0 ||
|
||||
type_name.compare(ModelVisitor::kIsDifferent) == 0 ||
|
||||
type_name.compare(ModelVisitor::kIsGreaterOrEqual) == 0 ||
|
||||
|
||||
Reference in New Issue
Block a user