void cloth::initParticlePairConstraint(int x1, int y1, int x2, int y2) { Particle *p1 = getParticle(x1,y1); Particle *p2 = getParticle(x2,y2); constraints.push_back( Constraint(p1,p2));//p1,p2,及弹簧之间的自然长度存为一个结构体 vec3 vec = p1->getPos()-p2->getPos(); float rest_distance = length(vec); ParticleConstraint pc1 = {x2,y2,rest_distance};//p1点受到p2点的constraint constrainsPerParticle[getParticleIndex(x1,y1)].push_back(pc1);//将p1收到的p2的constraint压入p1的constraint集合 ParticleConstraint pc2 = {x1,y1,rest_distance};//p2点受到p1点的constraint constrainsPerParticle[getParticleIndex(x2,y2)].push_back(pc2);//将p2收到的p1的constraint压入p1的constraint集合 }
TEST_F(AslTests, test_create_asl_query) { QueryContext ctx; ctx.constraints["sender"].add(Constraint(EQUALS, "bar")); ctx.constraints["sender"].add(Constraint(LIKE, "%a%")); ctx.constraints["message"].affinity = INTEGER_TYPE; ctx.constraints["message"].add(Constraint(LESS_THAN, "10")); aslmsg query = createAslQuery(ctx); ASSERT_EQ((uint32_t)ASL_TYPE_QUERY, asl_get_type(query)); ASSERT_EQ((size_t)3, asl_count(query)); const char *key, *val; uint32_t op; // Ordering doesn't really matter here, only that we only ended up with // (message, baz, LESS) and (sender, bar, EQUAL) ASSERT_EQ(0, asl_fetch_key_val_op(query, 0, &key, &val, &op)); ASSERT_STREQ("Message", key); ASSERT_STREQ("10", val); ASSERT_EQ((uint32_t)(ASL_QUERY_OP_LESS | ASL_QUERY_OP_NUMERIC), op); ASSERT_EQ(0, asl_fetch_key_val_op(query, 1, &key, &val, &op)); ASSERT_STREQ("Sender", key); ASSERT_STREQ("bar", val); ASSERT_EQ((uint32_t)ASL_QUERY_OP_EQUAL, op); ASSERT_EQ(0, asl_fetch_key_val_op(query, 2, &key, &val, &op)); ASSERT_STREQ("Sender", key); ASSERT_STREQ(".*a.*", val); ASSERT_EQ((uint32_t)(ASL_QUERY_OP_EQUAL | ASL_QUERY_OP_REGEX | ASL_QUERY_OP_CASEFOLD), op); asl_release(query); }
// Returns a list of points on the convex hull in counter-clockwise order. vector<Constraint> upper_envelope(vector<Constraint>* P, long double numerical_tolerance) { // Add (0, 0) (*P).push_back(Constraint(0.0, 0.0, -1.0, -1)); int n = (*P).size(), k = 0; vector<Constraint> H(n); // Sort points lexicographically sort((*P).begin(), (*P).end(), compare_Constraint_lexicographically()); // Build lower hull for (int i = 0; i < n; i++) { while (k >= 2 && cross(H[k-2], H[k-1], (*P)[i]) <= numerical_tolerance) k--; H[k] = (*P)[i]; k++; } H.resize(k); return H; }
/******************************************************************************* * parse_picross_input_file: parse one line from the input file, based on parsing_state * * file format: * GRID <title> <--- beginning of a new grid * ROWS <--- marker to start listing the constraints on the rows * [ 1 2 3 ... <--- constraint on one line (here a row) * ... * COLUMNS <--- marker for columns * ... ******************************************************************************/ bool parse_picross_input_file(const std::string& line_to_parse, std::vector<GridInput>& grids) { bool valid_line = false; std::istringstream iss(line_to_parse); std::string token; /* Copy the first word in 'token' */ iss >> token; if(token == "GRID") { parsing_state = GRID_START; valid_line = true; grids.push_back(GridInput()); grids.back().name = line_to_parse.substr(5); } else if(token == "ROWS") { if(parsing_state != FILE_START) { parsing_state = ROW_SECTION; valid_line = true; } } else if(token == "COLUMNS") { if(parsing_state != FILE_START) { parsing_state = COLUMN_SECTION; valid_line = true; } } else if(token == "[") { if(parsing_state == ROW_SECTION) { std::vector<int> new_row; int n; while(iss >> n) { new_row.push_back(n); } grids.back().rows.push_back(Constraint(Line::ROW, new_row)); valid_line = true; } else if(parsing_state == COLUMN_SECTION)
///------------------------------------------------------------- /// Creates initial list of constraints. ///------------------------------------------------------------- void IKSolver::CreateConstraints(int frameNum) { // clear any old data that might exist mConstraintList.clear(); // get all handles on model MarkerList & modelHandles = mModel->mHandleList; Vec3d zeroVec(0, 0, 0); zeroVec.MakeZero(); // loop over all handles on model, evaluating constraint for (int i = 0; i < modelHandles.size(); i++) { // get handle on model and contraint position Marker * handle = modelHandles[i]; Vec3d & constraintPos = mModel->mOpenedC3dFile->GetMarkerPos(frameNum, i); // if constraint is 0, 0, 0, then we don't have a constraint to actually deal with, // so only create and add constraint if this is not the case // all of these checks are in place to absolutely make sure, because somehow some of // these constraints snuck through if (constraintPos != vl_zero && constraintPos != vl_0) { if (len(constraintPos) != 0) { if ( !(constraintPos[0] == 0 && constraintPos[1] == 0 && constraintPos[2] == 0) ) { if (zeroVec != constraintPos) { mConstraintList.push_back(Constraint(mModel, i)); } } } } } #ifdef _DEBUG //LogConstraintList(0, false); #endif }
TEST_F(TablesTests, test_constraint_map) { ConstraintMap cm; ConstraintList cl; cl.add(Constraint(EQUALS, "some")); cm["path"] = cl; // If a constraint list exists for a map key, normal constraints apply. EXPECT_TRUE(cm["path"].matches("some")); EXPECT_FALSE(cm["path"].matches("not_some")); // If a constraint list does not exist, then all checks will match. // If there is no predicate clause then all results will match. EXPECT_TRUE(cm["not_path"].matches("some")); EXPECT_TRUE(cm["not_path"].notExistsOrMatches("some")); EXPECT_FALSE(cm["not_path"].exists()); EXPECT_FALSE(cm["not_path"].existsAndMatches("some")); // And of the column has constraints: EXPECT_TRUE(cm["path"].notExistsOrMatches("some")); EXPECT_FALSE(cm["path"].notExistsOrMatches("not_some")); EXPECT_TRUE(cm["path"].exists()); EXPECT_TRUE(cm["path"].existsAndMatches("some")); }
Constraint operator >= ( const LinearForm& l, const LinearForm& r ) { return Constraint( l - r, false ); }
static int xBestIndex(sqlite3_vtab *tab, sqlite3_index_info *pIdxInfo) { auto *pVtab = (VirtualTable *)tab; ConstraintSet constraints; // Keep track of the index used for each valid constraint. // Expect this index to correspond with argv within xFilter. size_t expr_index = 0; // If any constraints are unusable increment the cost of the index. double cost = 1; // Expressions operating on the same virtual table are loosely identified by // the consecutive sets of terms each of the constraint sets are applied onto. // Subsequent attempts from failed (unusable) constraints replace the set, // while new sets of terms append. if (pIdxInfo->nConstraint > 0) { for (size_t i = 0; i < static_cast<size_t>(pIdxInfo->nConstraint); ++i) { // Record the term index (this index exists across all expressions). const auto &constraint_info = pIdxInfo->aConstraint[i]; #if defined(DEBUG) plan("Evaluating constraints for table: " + pVtab->content->name + " [index=" + std::to_string(i) + " column=" + std::to_string(constraint_info.iColumn) + " term=" + std::to_string((int)constraint_info.iTermOffset) + " usable=" + std::to_string((int)constraint_info.usable) + "]"); #endif if (!constraint_info.usable) { // A higher cost less priority, prefer more usable query constraints. cost += 10; continue; } // Lookup the column name given an index into the table column set. if (constraint_info.iColumn < 0 || static_cast<size_t>(constraint_info.iColumn) >= pVtab->content->columns.size()) { cost += 10; continue; } const auto &name = pVtab->content->columns[constraint_info.iColumn].first; // Save a pair of the name and the constraint operator. // Use this constraint during xFilter by performing a scan and column // name lookup through out all cursor constraint lists. constraints.push_back( std::make_pair(name, Constraint(constraint_info.op))); pIdxInfo->aConstraintUsage[i].argvIndex = ++expr_index; #if defined(DEBUG) plan("Adding constraint for table: " + pVtab->content->name + " [column=" + name + " arg_index=" + std::to_string(expr_index) + "]"); #endif } } pIdxInfo->idxNum = kConstraintIndexID++; // Add the constraint set to the table's tracked constraints. #if defined(DEBUG) plan("Recording constraint set for table: " + pVtab->content->name + " [cost=" + std::to_string(cost) + " size=" + std::to_string(constraints.size()) + " idx=" + std::to_string(pIdxInfo->idxNum) + "]"); #endif pVtab->content->constraints[pIdxInfo->idxNum] = std::move(constraints); pIdxInfo->estimatedCost = cost; return SQLITE_OK; }
OptError NewtonProblem::CreateFunctionOptimizer(OptimizeClass * &objfcn, NLP0 * &func) { OptError error; int numVar = GetNumVar(); int derivOrder = GetDerivOrder(); VariableList* variables = GetVariables(); CompoundConstraint* constraints = 0; if ((variables->linearExists()) || (variables->nonlinearExists())) { cout << "Newton does not support linear or nonlinear constraints." << endl; cout << "Linear and nonlinear constraints being ignored." << endl; } if ((variables->upperExists()) || (variables->lowerExists())) { constraints = new CompoundConstraint(Constraint(variables->GetBoundConstraints())); } if(derivOrder == 2) { USERFCN2 userFcn = GetUserFunction2(); INITFCN initFcn = GetInitFunction(); if(userFcn == NULL || initFcn == NULL) { error.value = -4; error.msg = "Error loading function"; return error; } NLF2 * myFunc = new NLF2(numVar, userFcn, initFcn, constraints); myFunc->setIsExpensive(true); myFunc->setX(variables->GetInitialValues()); if ((variables->upperExists()) || (variables->lowerExists())) { objfcn = new OptBCNewton(myFunc); } else { objfcn = new OptNewton(myFunc); } func = myFunc; } else if(derivOrder == 1) { // construct a function with 1st derivative info USERFCN1 userFcn = GetUserFunction1(); INITFCN initFcn = GetInitFunction(); if(userFcn == NULL || initFcn == NULL) { error.value = -4; error.msg = "Error loading function"; return error; } NLF1 * myFunc = new NLF1(numVar, userFcn, initFcn, constraints); myFunc->setIsExpensive(true); myFunc->setX(variables->GetInitialValues()); if ((variables->upperExists()) || (variables->lowerExists())) { objfcn = new OptBCQNewton(myFunc); } else { objfcn = new OptQNewton(myFunc); } func = myFunc; } else if(derivOrder == 0) { INITFCN initFcn = GetInitFunction(); USERFCN0 userFcn = GetUserFunction0(); if(userFcn == NULL) { error.value = -4; error.msg = "Error loading user function"; return error; } else if(initFcn == NULL) { error.value = -4; error.msg = "Error loading init function"; return error; } // construct a function with no derivative info // but use finite differences to approximate a first derivative FDNLF1 * myFunc = new FDNLF1(numVar, userFcn, initFcn, constraints); myFunc->setIsExpensive(true); myFunc->setX(variables->GetInitialValues()); if(searchType_ == trustPDS) myFunc->setSpecOption(NoSpec); if ((variables->upperExists()) || (variables->lowerExists())) { objfcn = new OptBCQNewton(myFunc); } else { objfcn = new OptQNewton(myFunc); } func = myFunc; } error.value = 0; error.msg = "Success"; return error; }
void makeConstraint(Particle *p1, Particle *p2) {constraints.push_back(Constraint(p1,p2));}
void Subproblem::SolveSubproblemConvexHull(int iteration, int index) { if (constraints_.size() < 1) { return; } //if (iteration == 6 && index == 715) { if (iteration == 2 && index == 715) { int y = 0; y++; cout << y; } // Eliminate all superfluous constraints. std::vector<Constraint> active_constraints; vector<Point> points; for (int p = 0; p < constraints_.size(); ++p) { points.push_back(Point()); points[p].x = (-1.0) * constraints_[p].coefficient_; points[p].y = (-1.0) * constraints_[p].price_; points[p].weight = constraints_[p].weight_; points[p].constraint_id = p; constraints_[p].is_active_ = false; } points.push_back(Point()); points[constraints_.size()].x = 0.0; points[constraints_.size()].y = 0.0; points[constraints_.size()].weight = -1; points[constraints_.size()].constraint_id = -1; vector<Point> convex_hull_points = convex_hull(points); for (int p = 0; p < convex_hull_points.size(); ++p) { if ((convex_hull_points[p].x != 0.0) || (convex_hull_points[p].y != 0.0)) { active_constraints.push_back(Constraint(convex_hull_points[p].y * (-1.0), convex_hull_points[p].x * (-1.0), convex_hull_points[p].x / convex_hull_points[p].y, -1)); constraints_[convex_hull_points[p].constraint_id].is_active_ = true; } } // Sort list of active constraints. Note that the current implementation creates a clone of the // constraints vector. This isn't necessary, should be fixed. std::sort(active_constraints.begin(), active_constraints.end(), compare_Constraint_by_weight()); // Go through active constraints, create envelope points. envelope_points_.clear(); // First create intersection with x axis envelope_points_.push_back(std::make_pair((active_constraints[0].price_ / active_constraints[0].coefficient_), 0.0)); for (int k = 0; (k < (active_constraints.size() - 1)); ++k) { long double u_value = ((active_constraints[k].price_ - active_constraints[k + 1].price_) / (active_constraints[k].coefficient_ - active_constraints[k + 1].coefficient_)); envelope_points_.push_back(std::make_pair(u_value, (active_constraints[k].price_ - active_constraints[k].coefficient_ * u_value))); } // Last, create intersection with y axis envelope_points_.push_back(std::make_pair(0.0, active_constraints[active_constraints.size() - 1].price_)); // Find the budget ranges where there is a change of basis. budget_cutoffs_.clear(); // Start by addding 0 for convenience. budget_cutoffs_.push_back(0.0); for (int k = 0; k < envelope_points_.size() - 1; ++k) { if ((envelope_points_[k].first - envelope_points_[k + 1].first) > 0.00000000000001) { budget_cutoffs_.push_back((envelope_points_[k + 1].second - envelope_points_[k].second) / (envelope_points_[k].first - envelope_points_[k + 1].first)); } else { budget_cutoffs_.push_back(budget_cutoffs_[k]); } } // Add +\infty for convenience. budget_cutoffs_.push_back(DBL_MAX); active_constraints.clear(); }
void Subproblem::SolveSubproblem(int iteration, int index) { // Eliminate all superfluous constraints. std::vector<Constraint> active_constraints; for (int i = 0; i < num_vars_; ++i) { for (int j = i + 1; j < num_vars_; ++j) { if ((constraints_[j].is_active_ == true) && (constraints_[j].price_ >= constraints_[i].price_) && (constraints_[j].weight_ <= constraints_[i].weight_)) { constraints_[i].set_active(false); } if ((constraints_[i].is_active_ == true) && (constraints_[i].price_ >= constraints_[j].price_) && (constraints_[i].weight_ <= constraints_[j].weight_)) { constraints_[j].set_active(false); } } } for (int i = 0; i < num_vars_; ++i) { if (constraints_[i].is_active_ == true) { active_constraints.push_back(Constraint(constraints_[i].price_, constraints_[i].coefficient_, constraints_[i].weight_, constraints_[i].advertiser_index_)); } } if (active_constraints.size() < 1) { return; } // Sort list of active constraints. Note that the current implementation creates a clone of the // constraints vector. This isn't necessary, should be fixed. std::sort(active_constraints.begin(), active_constraints.end(), compare_Constraint_by_weight()); // Go through active constraints, create envelope points. envelope_points_.clear(); // First create intersection with x axis envelope_points_.push_back(std::make_pair((active_constraints[0].price_ / active_constraints[0].coefficient_), 0.0)); for (int k = 0; (k < (active_constraints.size() - 1)); ++k) { long double u_value = ((active_constraints[k].price_ - active_constraints[k + 1].price_) / (active_constraints[k].coefficient_ - active_constraints[k + 1].coefficient_)); envelope_points_.push_back(std::make_pair(u_value, (active_constraints[k].price_ - active_constraints[k].coefficient_ * u_value))); } // Last, create intersection with x axis envelope_points_.push_back(std::make_pair(0.0, active_constraints[active_constraints.size() - 1].price_)); // Find the budget ranges where there is a change of basis. budget_cutoffs_.clear(); // Start by addding 0 for convenience. budget_cutoffs_.push_back(0.0); for (int k = 0; k < envelope_points_.size() - 1; ++k) { if ((envelope_points_[k].first - envelope_points_[k + 1].first) > 0.00000000000001) { budget_cutoffs_.push_back((envelope_points_[k + 1].second - envelope_points_[k].second) / (envelope_points_[k].first - envelope_points_[k + 1].first)); } else { budget_cutoffs_.push_back(budget_cutoffs_[k]); } } // Add +\infty for convenience. budget_cutoffs_.push_back(DBL_MAX); active_constraints.clear(); };
Constraint operator <= ( const LinearForm& l, const LinearForm& r ) { return Constraint( r - l, false ); }
// Impose the constraints system to the equation system // the prefit residuals vector, hMatrix and rMatrix will be appended. void EquationSystem::imposeConstraints() { if(!equationConstraints.hasConstraints()) return; ConstraintList destList; ConstraintList tempList = equationConstraints.getConstraintList(); for(ConstraintList::iterator it = tempList.begin(); it != tempList.end(); ++it ) { VariableDataMap dataMapOk; bool validConstraint(true); try { VariableDataMap dataMap = it->body; for(VariableDataMap::iterator itv = dataMap.begin(); itv != dataMap.end(); ++itv ) { bool isFound(false); VariableSet::iterator itv2 = varUnknowns.find(itv->first); if(itv2!=varUnknowns.end()) { isFound = true; dataMapOk[*itv2] = dataMap[itv->first]; } else { for(itv2 = varUnknowns.begin(); itv2 != varUnknowns.end(); ++itv2 ) { if( (itv->first.getType() == itv2->getType()) && (itv->first.getSource() == itv2->getSource()) && (itv->first.getSatellite() == itv2->getSatellite()) ) { isFound = true; dataMapOk[*itv2] = dataMap[itv->first]; break; } } } if( !isFound ) validConstraint = false; } } catch(...) { validConstraint = false; } if(validConstraint) { destList.push_back(Constraint(it->header,dataMapOk)); } else { // we discard all constraints return; } } // Update the equation system equationConstraints.setConstraintList(destList); // Now, we can append the matrix(prefit design and weight) try { Vector<double> meas; Matrix<double> design; Matrix<double> cov; equationConstraints.constraintMatrix(varUnknowns, meas, design, cov); const int oldSize = measVector.size(); const int newSize = oldSize + meas.size(); const int colSize = hMatrix.cols(); Vector<double> tempPrefit(newSize,0.0); Matrix<double> tempGeometry(newSize,colSize,0.0); Matrix<double> tempWeight(newSize,newSize,0.0); for(int i=0; i< newSize; i++) { // prefit if(i<oldSize) tempPrefit(i) = measVector(i); else tempPrefit(i) = meas(i-oldSize); // geometry for(int j=0;j<colSize;j++) { if(i<oldSize) tempGeometry(i,j) = hMatrix(i,j); else tempGeometry(i,j) = design(i-oldSize,j); } // weight if(i<oldSize) tempWeight(i,i) = rMatrix(i,i); else tempWeight(i,i) = 1.0/cov(i-oldSize,i-oldSize); } // Update these matrix measVector = tempPrefit; hMatrix = tempGeometry; rMatrix = tempWeight; } catch(...) { return; } } // End of method 'EquationSystem::imposeConstraints()'
Constraint operator == ( const LinearForm& l, const LinearForm& r ) { return Constraint( l - r, true ); }
void Manifold::AddContact(float dt, const Vector3& globalOnA, const Vector3& globalOnB, const Vector3& normal, const float& penetration) { Vector3 r1 = (globalOnA - m_NodeA->GetPosition()); Vector3 r2 = (globalOnB - m_NodeB->GetPosition()); Vector3 v1 = m_NodeA->GetLinearVelocity() + Vector3::Cross(m_NodeA->GetAngularVelocity(), r1); Vector3 v2 = m_NodeB->GetLinearVelocity() + Vector3::Cross(m_NodeB->GetAngularVelocity(), r2); Vector3 dv = v2 - v1; Vector3 tangent1 = dv - (normal * Vector3::Dot(dv, normal)); if (Vector3::Dot(tangent1, tangent1) < 0.001f) { tangent1 = Vector3::Cross(normal, Vector3(1, 0, 0)); if (Vector3::Dot(tangent1, tangent1) < 0.001f) { tangent1 = Vector3::Cross(normal, Vector3(0, 0, 1)); } } tangent1.Normalise(); Vector3 tangent2 = Vector3::Cross(normal, tangent1); tangent2.Normalise(); //Normal Collision Constraint float b = 0.0f; //Baumgarte Offset { float baumgarte_scalar = 0.3f; float baumgarte_slop = 0.001f; float penSlop = min(penetration + baumgarte_slop, 0.0f); b += (baumgarte_scalar / dt) * penSlop; } //Elasticity { float elasticity = 0.8f; float elasticity_slop = 0.5f; float elatisity_term = elasticity * Vector3::Dot(normal, -m_NodeA->GetLinearVelocity() - Vector3::Cross(r1, m_NodeA->GetAngularVelocity()) + m_NodeB->GetLinearVelocity() + Vector3::Cross(r2, m_NodeB->GetAngularVelocity()) ); b += min(elatisity_term + elasticity_slop, 0.0f); } //Friction Collision Constraints const float friction = 0.5f; Contact contact; contact.pos = globalOnA; contact.normal = Constraint(m_NodeA, m_NodeB, -normal, Vector3::Cross(-r1, normal), normal, Vector3::Cross(r2, normal), b); contact.normal.impulseSumMin = 0.0f; contact.friction1 = Constraint(m_NodeA, m_NodeB, -tangent1 * friction, Vector3::Cross(-r1, tangent1) * friction, tangent1 * friction, Vector3::Cross(r2, tangent1) * friction, 0.0f); contact.friction2 = Constraint(m_NodeA, m_NodeB, -tangent2 * friction, Vector3::Cross(-r1, tangent2) * friction, tangent2 * friction, Vector3::Cross(r2, tangent2) * friction, 0.0f); m_Contacts.push_back(contact); }
int main() { float input[ROWS][COLUMNS] ; int state[ROWS][COLUMNS] ; float weight[ROWS][COLUMNS][ROWS][COLUMNS] ; float deviceOpTime[ROWS] = {0.5, 2.3} ; float costTimeSlot[COLUMNS] ={92.84, 94.39}; float T = 1 ; float energy, E1, E2, deltaE ; float EnergyGlobMinCurr ; float EnergyGlobMinPrev = 1000000; float switchP, randP ; int iteration, repetition ; int locX, locY ; float sum = 0 ; int i, j, k, l ; for(i = 0; i<ROWS; i++) { for(j=0; j<COLUMNS; j++) { for(k= 0; k<ROWS; k++) { for(l=0; l<COLUMNS; l++) { if(i == k) { if(j == l) { weight[i][j][k][l] = 0 ; } else { weight [i][j][k][l] = constA/2 ; } } else if (j == l) { if(i == k) { weight[i][j][k][l] = 0 ; } else { weight[i][j][k][l] = constB/2 ; } } else { weight[i][j][k][l] = 0 ; } } } } } for(i=0; i<ROWS; i++) { for(j=0; j<COLUMNS; j++) { input[i][j] = deviceOpTime[i]*costTimeSlot[j]; state[i][j] = 0 ; } } state[3][2] = 1 ; // for(iteration =0; iteration <20; iteration ++) while (T > 0.0001) { for(repetition =0; repetition < 8*18; repetition++) { locX = rand()%ROWS ; locY = rand()%COLUMNS ; sum = 0 ; for(i=0; i<ROWS; i++) { for(j=0; j<COLUMNS; j++) { sum = sum + state[i][j]*weight[i][j][locX][locY] ; } } sum = sum + input[locX][locY] ; if(sum > THRESHHOLD) { state[locX][locY] = 1 ; } else { E1 = FindEnergy(weight, state, input); SwitchState(&state[locX][locY]) ; E2 = FindEnergy(weight, state, input) ; SwitchState(&state[locX][locY]) ; deltaE = E2 - E1 ; randP = (rand()%1000)/1000.0 +0.00001; switchP = 1/(1 + (exp(-deltaE*(2/5))/T)) ; if ( switchP > randP) { state[locX][locY] = 1 ; } else { state[locX][locY] = 0 ; } } if( (FindEnergy(weight, state, input) > 0) && Constraint(state) == 1 ) { EnergyGlobMinCurr = FindEnergy(weight, state, input); if(EnergyGlobMinCurr <= EnergyGlobMinPrev) { SaveState(state); EnergyGlobMinPrev = EnergyGlobMinCurr; } } } T = 0.85*T ; } for(i = 0; i<ROWS; i++) { for(j=0; j<COLUMNS; j++) { printf("state[%d][%d] = %d \n", i, j, globMinState[i][j]) ; } } printf("Energy = %f", FindEnergy(weight, globMinState, input)) ; return 0 ; }