double ConstraintEqual::grad(double *param)
{
    double deriv=0.;
    if (param == param1()) deriv += 1;
    if (param == param2()) deriv += -1;
    return scale * deriv;
}
Esempio n. 2
0
int main(int argc, char const *argv[])
{
	char* buf = getenv("QUERY_STRING");
	if (buf == NULL)
	{
		exit(0);
	}
	std::string buffer(buf);
	int position = buffer.find('&');
	std::string::iterator iter = buffer.begin() + position;
	std::string param1(buffer.begin(), iter);
	std::string param2(iter + 1, buffer.end());
	int nparam1 = atoi(param1.c_str());
	int nparam2 = atoi(param2.c_str());

	std::vector<char> content(1024*64);
	sprintf(&content[0], "Welcome to add.com: ");
	sprintf(&content[0], "%sTHE Internet addition portal.\r\n<p>", &content[0]);
	sprintf(&content[0], "%sThe answer is: %d + %d = %d \r\n<p>", &content[0], nparam1, nparam2, nparam1 + nparam2);
	sprintf(&content[0], "%sThanks for visiting!\r\n", &content[0]);

	printf("Content-length: %d\r\n", strlen(&content[0]));
	printf("Content-type: text/html\r\n\r\n");
	printf("%s\n", &content[0]);
	fflush(stdout);
	return 0;
}
double ConstraintDifference::grad(double *param)
{
    double deriv=0.;
    if (param == param1()) deriv += -1;
    if (param == param2()) deriv += 1;
    if (param == difference()) deriv += -1;
    return scale * deriv;
}
TInt CNitzRFSPluginTestModule::ExecuteCustomCommand(CStifItemParser& /*aItem*/ )
    {
    TBuf<256> param1( KNullDesC );
     STIF_ASSERT_NOT_LEAVES( iPlugin->ExecuteCustomCommandL( ENormalRfs, param1 ) );
     TBuf<1> param2( KNullDesC );
     STIF_ASSERT_NOT_LEAVES( iPlugin->ExecuteCustomCommandL( EDeepRfs, param2 ) );
     STIF_ASSERT_NOT_LEAVES( iPlugin->ExecuteCustomCommandL( EInitRfs, param2 ) );
     STIF_ASSERT_NOT_LEAVES( iPlugin->ExecuteCustomCommandL( static_cast<TRfsReason>( 100 ), param2 ) );
    return KErrNone;
    }
ossimGpt ossimThreeParamDatum::shiftToWgs84(const ossimGpt &aPt)const
{
   
   if(ossim::almostEqual(param1(),  0.0)&&
      ossim::almostEqual(param2(), 0.0)&&
      ossim::almostEqual(param3(), 0.0))
   {
      return ossimGpt(aPt.latd(),
                      aPt.lond(),
                      aPt.latd(),
                      ossimGpt().datum());
   }
      
   ossimEcefPoint p1 = aPt;
   ossimEcefPoint p2;
 
   
   if(withinMolodenskyRange(aPt.latd()))
   {
      ossimWgs84Datum wgs84;
      double latin, lonin, hgtin;
      double latout, lonout, hgtout;
      
      double da = wgs84.ellipsoid()->getA() - ellipsoid()->getA();
      double df = wgs84.ellipsoid()->getFlattening() - ellipsoid()->getFlattening();

      latin = aPt.latr();
      lonin = aPt.lonr();
      hgtin = aPt.height();

      if(aPt.isHgtNan())
      {
         hgtin = 0.0;
      }
      molodenskyShift(ellipsoid()->getA(), da, ellipsoid()->getFlattening(), df, param1(), param2(), param3(),
                      latin, lonin, hgtin,
                      latout, lonout, hgtout);
      ossimGpt g;

      g.latr(latout);
      g.lonr(lonout);
      g.height(hgtout);
      g.datum(this);
      return g;
   }
   else
     {
       p2 = ossimEcefPoint(p1.x() + theParam1,
			   p1.y() + theParam2,
			   p1.z() + theParam3);
     }
   
   return ossimGpt(p2); // defaults to WGS84
}
void UT_CMccResourceItem::UT_CMccResourceItem_UserMatchNotStrictL(  )
    {
    TMccResourceParams param(0,1,0,0,EFalse,0);
    TMccResourceParams param2(0,1,0,0,EFalse,0);
    EUNIT_ASSERT(iItem->UserMatchNotStrict(param, param2))
    
    TMccResourceParams para3(0,0,1,0,EFalse,0);
    TMccResourceParams param4(0,0,1,0,EFalse,0);
    EUNIT_ASSERT(iItem->UserMatchNotStrict(param, param2))

    }
Esempio n. 7
0
int main()
{
    Leph::MetaParameter param1("param1", 41.0);
    Leph::MetaParameter param2("param2", 42.0);
    Leph::MetaParameter param3("param3", 43.0);
    assert(param1.name() == "param1");
    assert(param2.name() == "param2");
    assert(param3.name() == "param3");
    assert(param1.value() == 41.0);
    assert(param2.value() == 42.0);
    assert(param3.value() == 43.0);

    param2.setMinimum(40.0);
    param3.setMinimum(30.0);
    param3.setMaximum(100.0);
    assert(param2.hasMinimum());
    assert(!param2.hasMaximum());
    assert(param3.hasMinimum());
    assert(param3.hasMaximum());

    param1.setValue(100.0);
    assert(param1.value() == 100.0);
    param2.setValue(0.0);
    assert(param2.value() == 40.0);
    param2.setValue(200.0);
    assert(param2.value() == 200.0);
    
    param3.setValue(40.0);
    assert(param3.value() == 40.0);
    param3.setValue(20.0);
    assert(param3.value() == 30.0);
    param3.setValue(300.0);
    assert(param3.value() == 100.0);

    std::cout << param1 << std::endl;
    std::cout << param2 << std::endl;
    std::cout << param3 << std::endl;
    
    TestOptimizable testOptimizable;
    assert(testOptimizable.parameterSize() == 2);
    assert(testOptimizable.getParameter(0).value() == 1.0);
    assert(testOptimizable.getParameter(1).value() == 2.0);
    assert(testOptimizable.setParameter(1, 3.0) == true);
    assert(testOptimizable.setParameter(1, 11.0) == false);

    testOptimizable.parameterPrint();
    testOptimizable.parameterSave("/tmp/testMetaParameter.params");
    testOptimizable.parameterLoad("/tmp/testMetaParameter.params");
    testOptimizable.parameterPrint();

    return 0;
}
void UT_CMccResourceItem::UT_CMccResourceItem_UserMatchL(  )
    {
    TMccResourceParams param(0,0,0,0,EFalse,0);

    TMccResourceParams param2(0,0,0,0,EFalse,0);
    
    EUNIT_ASSERT(iItem->UserMatch(param, param2));
    
    param.iStreamId = 2;
    param2.iStreamId = 3;
    EUNIT_ASSERT(!iItem->UserMatch(param, param2));

    }
Esempio n. 9
0
void CGroupPrice::UnsubscribeGroup(const CComVariant& params)
{
	if(V_VT(&params) == VT_ERROR)
	{
		EgLib::CEgLibTraceManager::Trace(LogInfo, __FUNCTION__, _T("[%s]\t Checking Subscription Group"), m_strUserName.c_str()); 
		UnsubscribeAll();
	}
	else
	{

		_QuoteUpdateParams Params(params);

		EgLib::CEgLibTraceManager::Trace(LogInfo, __FUNCTION__, _T("[%s]\t Symbol: %s, Exchange: %s, Type: %d"), m_strUserName.c_str(), 
			Params->Symbol?CW2T(Params->Symbol):_T(""), 
			Params->Exchange?CW2T(Params->Exchange):_T(""), 
			Params->Type);


		if(V_VT(&m_vtRequest) != VT_ERROR)
		{
			_QuoteUpdateParams param2(m_vtRequest);
			_bstr_t bsSymbol1(Params->Symbol) ;
			_bstr_t bsSymbol2(param2->Symbol) ;
			if(bsSymbol1 == bsSymbol2 && Params->Type == param2->Type)
			{
				_CancelOptions();
			}
		}		
		_SetDbKey(Params);
		char szSymbol[MAX_LENGTH + 1];
		ZeroMemory(szSymbol,sizeof(szSymbol));
		if(CUtilities::KeyToString(&m_dbaKey.dbaKey, szSymbol, MAX_LENGTH))
		{
			CAutoLock lk(m_csGroupSubscript);
			grouptickermap::iterator itrGroup = m_mapGroupSubscript.find(szSymbol);
			if(itrGroup != m_mapGroupSubscript.end())
			{
				for(tickerset::iterator iter = itrGroup->second.begin(); iter !=  itrGroup->second.end(); iter++)
				{
					DBA_KEYS dbaKey;
					ZeroMemory(&dbaKey, sizeof(DBA_KEYS));
					DeleteSubscription(*iter);
					(*iter)->GetRawKey(&dbaKey.dbaKey);
					DecInterest(&dbaKey);		
				}
				m_mapGroupSubscript.erase(itrGroup);
			}
		}
	}
	m_vtRequest.Clear();
}
Esempio n. 10
0
void CGroupPrice::CancelGroupPrice(const CComVariant& Params)
{
	if(V_VT(&Params) == VT_ERROR || V_VT(&m_vtRequest) == VT_ERROR)
	{
		_CancelOptions();
	}
	else
	{
		_QuoteUpdateParams param1(Params);
		_QuoteUpdateParams param2(m_vtRequest);
		_bstr_t bsSymbol1(param1->Symbol) ;
		_bstr_t bsSymbol2(param2->Symbol) ;
		if(bsSymbol1 == bsSymbol2 && param1->Type == param2->Type)
		{
			_CancelOptions();
		}
	}

}
Esempio n. 11
0
int main (int argc, char **argv)
{
  // initialize the rpc handle
  saga::rpc::rpc rm (std::string ("rpc://sakura.hpcc.jp/simple/add_test"));

  // initialize the parameter stack
  int input = 100, output = -1;
  saga::rpc::parameter param1 (&input, 1, saga::rpc::In);
  saga::rpc::parameter param2 (&output, 1, saga::rpc::Out);

  std::vector <saga::rpc::parameter> parameters;
  parameters.push_back (param1);
  parameters.push_back (param2);

  // invoke the remote procedure
  rm.call (parameters);

  // when completed, the output parameters are available
  std::cout << "Output: " << output << std::endl;

  return (0);
}
Esempio n. 12
0
void CGroupPrice::UnsubscribeGroup(const CComVariant& params)
{
	if(V_VT(&params) == VT_ERROR)
	{
		UnsubscribeAll();
	}
	else
	{

		_QuoteUpdateParams Params(params);
		if(V_VT(&m_vtRequest) != VT_ERROR)
		{
			_QuoteUpdateParams param2(m_vtRequest);
			_bstr_t bsSymbol1(Params->Symbol) ;
			_bstr_t bsSymbol2(param2->Symbol) ;
			if(bsSymbol1 == bsSymbol2 && Params->Type == param2->Type)
			{
				_CancelOptions();
			}
		}		
		_SetDbKey(Params);
		
		char szSymbol[MAX_LENGTH + 1];
		ZeroMemory(szSymbol,sizeof(szSymbol));
		KeyToString(&m_dbaKey.dbaKey, szSymbol, MAX_LENGTH);

		m_csSubscript.Lock();
		for(tickerset::const_iterator iter = m_mapGroupSubscript[szSymbol].begin(); iter !=  m_mapGroupSubscript[szSymbol].end(); iter++)
		{
			ZeroMemory(&m_dbaKey.dbaKey, sizeof(DBA_KEY));
			::StringToKey(const_cast<char*>((*iter).c_str()), &m_dbaKey.dbaKey);
			m_mapSubscript.erase(*iter);
			DecInterest();		
		}
		m_mapGroupSubscript.erase(szSymbol);
		m_csSubscript.Unlock();
	}
	m_vtRequest.Clear();
}
Esempio n. 13
0
fei::SharedPtr<fei::MatrixGraph> test_MatrixGraph::create_MatrixGraph(testData* testdata,
					 int localProc, int numProcs,
					 bool bothFields, bool nonSymmetric,
					 const char* name,
					 fei::SharedPtr<fei::VectorSpace> vectorSpacePtr,
					 fei::SharedPtr<fei::Factory> factory,
                                         const std::string& path,
					 bool turnOnDebugOutput)
{
  //
  //This function creates a MatrixGraph object, and initializes it as follows:
  //
  //setRowSpace(vectorSpacePtr)
  //
  //definePattern patternID=0, numIDs=4, idType=testdata->idTypes[0]
  //      fieldID=testdata->fieldIDs[0] if !bothFields, else
  //      fieldIDs=testdata->fieldIDs
  //
  //initConnectivityBlock blockID=0, numConnectivityLists=1
  //
  //initConnectivity blockID, 0, testdata->ids
  //
  //If nonSymmetric==true, then also do the following:
  //  definePattern patternID=1, numIDs=1, idType=testdata->idTypes[0]
  //     fieldID=testdata->fieldIDs[0] if !bothFields, else
  //      fieldIDs=testdata->fieldIDs
  //  definePattern patternID=2, numIDs=4, idType=testdata->idTypes[0]
  //     fieldID=testdata->fieldIDs[0] if !bothFields, else
  //      fieldIDs=testdata->fieldIDs
  //
  //initConnectivityBlock blockID=1, patterns 1 and 2
  //
  //initConnectivity blockID, 0, testdata->ids
  //
  fei::SharedPtr<fei::MatrixGraph> mgptr;
  if (factory.get() == NULL) {
    fei::SharedPtr<fei::MatrixGraph> tmp(new fei::MatrixGraph_Impl2(vectorSpacePtr,
							      vectorSpacePtr, name));
    mgptr = tmp;
  }
  else {
    mgptr = factory->createMatrixGraph(vectorSpacePtr, vectorSpacePtr, name);
  }

  fei::ParameterSet paramset;
  fei::Param param1("name", name);
  paramset.add(param1);
  if (turnOnDebugOutput) {
    if (path.empty()) {
      fei::Param param2("debugOutput", ".");
      paramset.add(param2);
    }
    else {
      fei::Param param2("debugOutput", path.c_str());
      paramset.add(param2);
    }
  }

  fei::MatrixGraph* matrixGraphPtr = mgptr.get();

  matrixGraphPtr->setParameters(paramset);

  matrixGraphPtr->setRowSpace(vectorSpacePtr);

  int patternID = 0;
  int numIDs = 4;
  int idType = testdata->idTypes[0];
  int fieldID = testdata->fieldIDs[0];

  if (bothFields) {
    std::vector<int> numFieldsPerID(numIDs, 2);
    std::vector<int> fieldIDsArray(numIDs*2);
    for(int i=0; i<numIDs; ++i) {
      fieldIDsArray[i*2] = testdata->fieldIDs[0];
      fieldIDsArray[i*2+1] = testdata->fieldIDs[1];
    }

    patternID = matrixGraphPtr->definePattern(numIDs, idType,
					 &numFieldsPerID[0],
					 &fieldIDsArray[0]);
  }
  else {
    patternID = matrixGraphPtr->definePattern(numIDs, idType, fieldID);
  }

  int blockID = 0;
  int numConnectivityLists = 1;

  matrixGraphPtr->initConnectivityBlock(blockID,
					   numConnectivityLists,
					   patternID);

  matrixGraphPtr->initConnectivity(blockID, 0, &(testdata->ids[0]));

  if (!nonSymmetric) {
    return(mgptr);
  }

  int patternID1 = 1, patternID2 = 2;
  int numRowIDs = 1, numColIDs = 4;

  if (bothFields) {
    std::vector<int> numFieldsPerID(numIDs, 2);
    std::vector<int> fieldIDsArray(numIDs*2);
    for(int i=0; i<numIDs; ++i) {
      fieldIDsArray[i*2] = testdata->fieldIDs[0];
      fieldIDsArray[i*2+1] = testdata->fieldIDs[1];
    }

    patternID1 = matrixGraphPtr->definePattern(numRowIDs, idType,
					 &numFieldsPerID[0],
					 &fieldIDsArray[0]);
    patternID2 = matrixGraphPtr->definePattern(numColIDs, idType,
					 &numFieldsPerID[0],
					 &fieldIDsArray[0]);
  }
  else {
    patternID1 = matrixGraphPtr->definePattern(numRowIDs,
					   idType, fieldID);
    patternID2 = matrixGraphPtr->definePattern(numColIDs,
					   idType, fieldID);
  }

  blockID = 1;

  matrixGraphPtr->initConnectivityBlock(blockID,
					   numConnectivityLists,
					   patternID1, patternID2);

  matrixGraphPtr->initConnectivity(blockID, 0,
					  &(testdata->ids[0]),
					  &(testdata->ids[0]));

  return(mgptr);
}
Esempio n. 14
0
double ConstraintEqual::error()
{
    return scale * (*param1() - *param2());
}
Esempio n. 15
0
double ConstraintDifference::error()
{
    return scale * (*param2() - *param1() - *difference());
}
/*--------------------------------------------------------------------------*/
types::Function::ReturnValue sci_findfileassociation(types::typed_list &in, int _iRetCount, types::typed_list &out)
{
    types::String* pS = nullptr;
    std::wstring param1;
    std::wstring param2(L"open");

    int rhs = static_cast<int>(in.size());
    if (rhs != 1 && rhs != 2)
    {
        Scierror(77, _("%s: Wrong number of input argument(s): %d to %d expected.\n"), fname.data(), 1, 2);
        return types::Function::Error;
    }

    if (_iRetCount != 1)
    {
        Scierror(999, _("%s: Wrong number of output arguments: %d expected.\n"), fname.data(), 1);
        return types::Function::Error;
    }

    if (in[0]->isString() == false)
    {
        Scierror(999, _("%s: Wrong type for input argument #%d: String expected.\n"), fname.data(), 1);
        return types::Function::Error;
    }

    pS = in[0]->getAs<types::String>();
    if (pS->isScalar() == false)
    {
        Scierror(999, _("%s: Wrong size for input argument #%d: String expected.\n"), fname.data(), 1);
        return types::Function::Error;
    }

    param1 = pS->get()[0];

    if (rhs == 2)
    {
        if (in[1]->isString() == false)
        {
            Scierror(999, _("%s: Wrong type for input argument #%d: String expected.\n"), fname.data(), 2);
            return types::Function::Error;
        }

        pS = in[1]->getAs<types::String>();
        if (pS->isScalar() == false)
        {
            Scierror(999, _("%s: Wrong size for input argument #%d: String expected.\n"), fname.data(), 2);
            return types::Function::Error;
        }

        param2 = pS->get()[0];
    }

    wchar_t* output = FindFileAssociation(param1.data(), param2.data()) ;
    if (output)
    {
        out.push_back(new types::String(output));
    }
    else
    {
        out.push_back(types::Double::Empty());
    }
    return types::Function::OK;
}