예제 #1
0
//------------------------------------------------------------------------------
Minimize& Minimize::operator=(const Minimize& m)
{
   if (this == &m)
      return *this;
    
   SolverSequenceCommand::operator=(m);
   optimizerName          = m.optimizerName;
   objectiveName          = m.objectiveName;
   objective              = NULL;
   //objectiveValue         = m.objectiveValue;
   optimizer              = NULL;
   optimizerDataFinalized = false;
   //isMinimizeParm         = m.isMinimizeParm;
   objId                  = m.objId;
   interpreted            = false;

   // Initialize wrappers to NULL
   ClearWrappers();

   return *this;
}
예제 #2
0
//------------------------------------------------------------------------------
bool NonlinearConstraint::InterpretAction()
{
   bool tooMuch = false;
   // Clean out any old data
   wrapperObjectNames.clear();
   ClearWrappers();

   StringArray chunks = InterpretPreface();

   #ifdef DEBUG_NLC_PARSING
      MessageInterface::ShowMessage(wxT("Preface chunks as\n"));
      for (StringArray::iterator i = chunks.begin(); i != chunks.end(); ++i)
         MessageInterface::ShowMessage(wxT("   \"%s\"\n"), i->c_str());
      MessageInterface::ShowMessage(wxT("\n"));
   #endif
   
   // Find and set the solver object name
   // This is the only setting in Vary that is not in a wrapper
   StringArray currentChunks = parser.Decompose(chunks[1], wxT("()"), false);
   if (!GmatStringUtil::HasNoBrackets(currentChunks.at(0), false))
      throw CommandException(
            wxT("Solver name for NonlinearConstraint command may not contain brackets, braces, or parentheses.")); 
   SetStringParameter(OPTIMIZER_NAME, currentChunks[0]);
   if (currentChunks.size() < 2)
      throw CommandException(wxT("Missing field or value for NonlinearConstraint command."));
   if (currentChunks.size() > 2) tooMuch = true;
   wxString cc = GmatStringUtil::Strip(currentChunks[1]);
   Integer ccEnd = cc.size() - 1;
   if ((tooMuch) || (cc.at(0) != wxT('(')) || (cc.at(ccEnd) != wxT(')')))
      throw CommandException(
           wxT("Missing parentheses, or unexpected characters found, around logical expression argument to NonlinearConstraint command."));
   if (!GmatStringUtil::IsBracketBalanced(cc, wxT("()")))
      throw CommandException(wxT("Parentheses unbalanced in NonlinearConstraint command."));
   // @todo - if tolerance allowed later, will need to not check for braces here ...
   if ((cc.find(wxT('[')) != cc.npos) || (cc.find(wxT(']')) != cc.npos) ||
       (cc.find(wxT('{')) != cc.npos) || (cc.find(wxT('}')) != cc.npos) )
      throw CommandException(wxT("NonlinearConstraint command may not contain brackets or braces."));
   
   wxString noSpaces2     = GmatStringUtil::RemoveAll(cc,wxT(' '));
   //wxString noSpaces2     = GmatStringUtil::RemoveAll(currentChunks[1],' ');
   currentChunks = parser.SeparateBrackets(noSpaces2, wxT("()"), wxT(","), false);
   
   #ifdef DEBUG_NLC_PARSING
      MessageInterface::ShowMessage(
         wxT("NLC:  noSpaces2 = %s\n"), noSpaces2.c_str());
      MessageInterface::ShowMessage(
         wxT("NLC: after SeparateBrackets, current chunks = \n"));
      for (Integer jj = 0; jj < (Integer) currentChunks.size(); jj++)
         MessageInterface::ShowMessage(wxT("   %s\n"),
                                       currentChunks[jj].c_str());
   #endif
   bool testForMore = false;
   if ((Integer) currentChunks.size() > 1) testForMore = true;
   Integer end;
   wxString constraintStr = currentChunks[0];
   Integer opSize = 1;
   if ((end = constraintStr.find(wxT(">="), 0)) != (Integer) constraintStr.npos)
   {
      op = GREATER_THAN_OR_EQUAL;
      isInequality = true;
      isIneqString = wxT("IneqConstraint");
      opSize       = 2;
      #ifdef DEBUG_NONLINEAR_CONSTRAINT_INIT
         MessageInterface::ShowMessage(wxT("NLC:InterpretAction: greater_than_or_equal\n"));
      #endif
   }
   else if ((end = constraintStr.find(wxT("<="), 0)) != (Integer) constraintStr.npos)
   {
      op = LESS_THAN_OR_EQUAL;
      isInequality = true;
      isIneqString = wxT("IneqConstraint");
      opSize       = 2;
      #ifdef DEBUG_NONLINEAR_CONSTRAINT_INIT
         MessageInterface::ShowMessage(wxT("NLC:InterpretAction: less_than_or_equal\n"));
      #endif
   }
   else if ((end = constraintStr.find(wxT("=>"), 0)) != (Integer) constraintStr.npos)
   {
      wxString errmsg = wxT("The string \"=>\" is an invalid conditonal operator");
      errmsg            += wxT(" in a NonlinearConstraint command.\n");
      errmsg            += wxT("The allowed values are [=, <=, >=]\n");
      throw CommandException(errmsg);
   }
   else if ((end = constraintStr.find(wxT("=<"), 0)) != (Integer) constraintStr.npos)
   {
      wxString errmsg = wxT("The string \"=<\" is an invalid conditonal operator");
      errmsg            += wxT(" in a NonlinearConstraint command.\n");
      errmsg            += wxT("The allowed values are [=, <=, >=]\n");
      throw CommandException(errmsg);
   }
   else if ((end = constraintStr.find(wxT("=="), 0)) != (Integer) constraintStr.npos)
   {
      wxString errmsg = wxT("The string \"==\" is an invalid conditonal operator");
      errmsg            += wxT(" in a NonlinearConstraint command.\n");
      errmsg            += wxT("The allowed values are [=, <=, >=]\n");
      throw CommandException(errmsg);
   }
   else if ((end = constraintStr.find(wxT("="), 0)) != (Integer) constraintStr.npos)
   {
      //end = constraintStr.find("=", 0);
      op = EQUAL;
      isInequality = false;
      isIneqString = wxT("EqConstraint");
      #ifdef DEBUG_NONLINEAR_CONSTRAINT_INIT
         MessageInterface::ShowMessage(wxT("NLC:InterpretAction: equal\n"));
      #endif
   }
   else
   {
      wxString errmsg = wxT("The conditional operator is missing or invalid ");
      errmsg            += wxT(" in a NonlinearConstraint command.\n");
      errmsg            += wxT("The allowed values are [=, <=, >=]\n");
      throw CommandException(errmsg);
   }
   arg1Name = constraintStr.substr(0,end);
   arg2Name = constraintStr.substr(end+opSize, (constraintStr.npos - end + opSize - 1));
   #ifdef DEBUG_NLC_PARSING
      MessageInterface::ShowMessage(wxT("... arg1Name = %s\n"), arg1Name.c_str());
      MessageInterface::ShowMessage(wxT("... operator = %s\n"), OP_STRINGS[(Integer)op].c_str());
      MessageInterface::ShowMessage(wxT("... arg2Name = %s\n"), arg2Name.c_str());
   #endif
   // Currently, this should not happen ..... 
   if (testForMore)
   {
      wxString noSpaces     = GmatStringUtil::RemoveAll(currentChunks[1],wxT(' '));
      currentChunks = parser.SeparateBrackets(noSpaces, wxT("{}"), wxT(","), false);
      
      #ifdef DEBUG_NLC_PARSING
         MessageInterface::ShowMessage(
            wxT("NLC: After SeparateBrackets, current chunks = \n"));
         for (Integer jj = 0; jj < (Integer) currentChunks.size(); jj++)
            MessageInterface::ShowMessage(wxT("   %s\n"),
                                          currentChunks[jj].c_str());
      #endif
      
      // currentChunks now holds all of the pieces - no need for more separation  
      
      wxString lhs, rhs;
      for (StringArray::iterator i = currentChunks.begin(); 
           i != currentChunks.end(); ++i)
      {
         SeparateEquals(*i, lhs, rhs);
         
         if (IsSettable(lhs))
            SetStringParameter(GetParameterID(lhs), rhs);
         else
         {
            throw CommandException(wxT("The setting \"") + lhs + 
               wxT("\" is not a valid setting for a ") + typeName + 
               wxT(" command.\n"));
         }
      }
   }
   
   interpreted = true;
  
   return true;
}
예제 #3
0
//------------------------------------------------------------------------------
NonlinearConstraint::~NonlinearConstraint()
{
   ClearWrappers();
}
예제 #4
0
//------------------------------------------------------------------------------
bool Minimize::InterpretAction()
{
   #ifdef DEBUG_MINIMIZE // ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ debug ~~~~
      MessageInterface::ShowMessage("Interpreting Minimize command ...\n");
      MessageInterface::ShowMessage("generatingString = %s",
         generatingString.c_str());
   #endif // ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ end debug ~~~~
   /// @todo: Clean up this hack for the Minimize::InterpretAction method
   // Sample string:  "Minimize myDC(Sat1.SMA = 21545.0, {Tolerance = 0.1});"
   /// @todo clean that up - because that's not even right ^^^^^
   
      // Clean out any old data
   wrapperObjectNames.clear();
   ClearWrappers();

   StringArray chunks = InterpretPreface();

   #ifdef DEBUG_MINIMIZE_PARSING
      MessageInterface::ShowMessage("Preface chunks as\n");
      for (StringArray::iterator i = chunks.begin(); i != chunks.end(); ++i)
         MessageInterface::ShowMessage("   \"%s\"\n", i->c_str());
      MessageInterface::ShowMessage("\n");
   #endif
   
   // Find and set the solver object name
   // This is the only setting in Vary that is not in a wrapper
   StringArray currentChunks = parser.Decompose(chunks[1], "()", false);
   if (!GmatStringUtil::HasNoBrackets(currentChunks.at(0), false))
      throw CommandException(
            "Solver name for Minimize command may not contain brackets, braces, or parentheses."); 
      
   SetStringParameter(OPTIMIZER_NAME, currentChunks[0]);
   if (currentChunks.size() < 2)
      throw CommandException("Missing field or value for Minimize command.");
 
    // The remaining text in the instruction is the variable definition and 
   // parameters, all contained in currentChunks[1].  Deal with those next.
   std::string cc = GmatStringUtil::Strip(currentChunks[1]);
   Integer ccEnd = cc.size() - 1;
   if ((cc.at(0) != '(') || (cc.at(ccEnd) != ')'))
      throw CommandException(
           "Missing parentheses, or unexpected characters found, around argument to Minimize command.");
   if (!GmatStringUtil::IsBracketBalanced(cc, "()"))
      throw CommandException("Parentheses unbalanced in Minimize command.");
   if ((cc.find('[') != cc.npos) || (cc.find(']') != cc.npos) ||
       (cc.find('{') != cc.npos) || (cc.find('}') != cc.npos) )
      throw CommandException("Minimize command may not contain brackets or braces.");

   std::string noSpaces     = GmatStringUtil::RemoveAll(cc,' ');
   currentChunks = parser.Decompose(noSpaces, "()", true, true);
   
   #ifdef DEBUG_MINIMIZE_PARSING
      MessageInterface::ShowMessage(
         "Minimize: after Decompose, current chunks = \n");
      for (Integer jj = 0; jj < (Integer) currentChunks.size(); jj++)
         MessageInterface::ShowMessage("   %s\n",
                                       currentChunks[jj].c_str());
   #endif

   if (currentChunks.size() == 0)
      throw CommandException("The objective function name is missing in the "
               "Minimize command\n");

   // First chunk is the objectiveName
   objectiveName = currentChunks[0];
      
   #ifdef DEBUG_MINIMIZE_PARSE // ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ debug ~~~~
      MessageInterface::ShowMessage("Minimize::InterpretAction() exiting\n");
   #endif // ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ end debug ~~~~
      
   interpreted   = true;

   return true;
}
예제 #5
0
//------------------------------------------------------------------------------
Minimize::~Minimize()
{
   ClearWrappers();
   //delete objective;  // yes? no? not in ths case, it seems
}