Exemplo n.º 1
0
void FSISPOptimizerWCP::calculateBlockAssignment()
{
    clear();
    generateBlockCostsConstraints();
    generateBlockSizeConstraint();
    generateFunctionMembershipConstraints();
    generateOptimalILPFormulation();

    stringstream ilp_formulation;
    vector<string>::iterator it;

    ilp_formulation << "\n// Objective function:\n";
    if(!conf->getBool(CONF_BBSISP_WCP_FILL_ISP_UP))
    {
        ilp_formulation << "min: wentry;\n";
    }
    else
    {
        ilp_formulation << "min: 1e10 wentry - sp;\n";
    }
    ilp_formulation << "\n// Flow constraints:\n";
//	sort(cfg_ilps.begin(),cfg_ilps.end());
    for(it = cfg_ilps.begin(); it != cfg_ilps.end(); it++)
    {
        ilp_formulation << *it;
    }
    ilp_formulation << "\n// Basic block cost contraints:\n";
//	sort(block_cost_contraints.begin(),block_cost_contraints.end());
    for(it = block_cost_contraints.begin(); it != block_cost_contraints.end(); it++)
    {
        ilp_formulation << *it;
    }
    ilp_formulation << "\n// Basic block size contraints:\n";
//	sort(block_size_constraints.begin(),block_size_constraints.end());
    for(it = block_size_constraints.begin(); it != block_size_constraints.end(); it++)
    {
        ilp_formulation << *it;
    }
    ilp_formulation << "\n// Function membership constraints:\n";
    for(it = function_membership_constraints.begin(); it != function_membership_constraints.end(); it++)
    {
        ilp_formulation << *it;
    }
    ilp_formulation << "\n// Binary domains:\n";
//	sort(binary_domains.begin(),binary_domains.end());
    for(it = binary_domains.begin(); it != binary_domains.end(); it++)
    {
        ilp_formulation << *it;
    }

    LOG_INFO(logger, "Formulation: " << ilp_formulation.str());

    vector<lp_result_set> lp_result = writeAndSolveILPFile(ilp_formulation.str());
    setAssignment(lp_result);
    setFunctionAssignment(lp_result);
    setVariables(lp_result);
}
Exemplo n.º 2
0
void FSISPOptimizerOLD::calculateKnapsackFunctionAssignment(void)
{
	if(ilp_knapsack_formulation.empty())
	{
		generateKnapsackILPFormulation();
	}

	writeKnapsackILPFile();

	LpSolver lps(ilp_knapsack_formulation, conf->getString(CONF_LP_SOLVE_PARAMETERS));
//	LpSolver lps(ilpfile_name, conf->getString(CONF_LP_SOLVE_PARAMETERS));
	setAssignment(lps.lpSolve());
}
Exemplo n.º 3
0
void BBSISPOptimizerJP::calculateBlockAssignment(void)
{
	clear();
	generateBBRecords();
	generateBBConnections();
	generateKnapsackILPFormulation();

	stringstream str;
	for(uint32_t i = 0; i < ilp_knapsack_formulation.size(); i++)
	{
		str << ilp_knapsack_formulation[i];
	}
	LOG_INFO(logger, "Formulation: " << str.str());

	vector<lp_result_set> lp_result = writeAndSolveILPFile(ilp_knapsack_formulation);
	setAssignment(lp_result);
	setVariables(lp_result);
}
Exemplo n.º 4
0
void InputSettingsWindow::inputEvent(uint16_t scancode) {
  if(!activeInput) return;
  if(!isActiveWindow() || isMinimized()) return;
  int16_t state = mapper().state(scancode);

  if(dynamic_cast<DigitalInput*>(activeInput)) {
    if(Keyboard::isAnyKey(scancode) && mapper().state(scancode)) {
      for(unsigned i = 0; i < Keyboard::Count; i++) {
        //don't map escape key, as it is reserved by the user interface
        if(scancode == keyboard(i)[Keyboard::Escape]) return;
      }

      setAssignment(string() << mapper().modifierString() << Scancode::encode(scancode));
    } else if(Keyboard::isAnyModifier(scancode) && optionAssignModifiers->isChecked()) {
      setAssignment(string() << Scancode::encode(scancode));
    } else if(Mouse::isAnyButton(scancode) && mapper().state(scancode)) {
      //ensure button was clicked inside list box
      unsigned wx = 0, wy = 0;
      QWidget *widget = message;
      while(widget) {
        wx += widget->geometry().x();
        wy += widget->geometry().y();
        widget = widget->parentWidget();
      }
      unsigned px = QCursor::pos().x();
      unsigned py = QCursor::pos().y();
      if(px < wx || px >= wx + message->size().width()) return;
      if(py < wy || py >= wy + message->size().height()) return;

      setAssignment(string() << mapper().modifierString() << Scancode::encode(scancode));
    } else if(Joypad::isAnyHat(scancode)) {
      string position;
      if(state == Joypad::HatUp) position = ".Up";
      else if(state == Joypad::HatDown) position = ".Down";
      else if(state == Joypad::HatLeft) position = ".Left";
      else if(state == Joypad::HatRight) position = ".Right";
      else return;

      setAssignment(string() << mapper().modifierString() << Scancode::encode(scancode) << position);
    } else if(Joypad::isAnyAxis(scancode) && mapper().distance(scancode) > 64) {
      if(mapper().calibrated == false) {
        MappedInput *temp = activeInput;
        activeInput = 0;
        mapper().calibrate();
        activeInput = temp;
      }

      if(mapper().isTrigger[Joypad::numberDecode(scancode)][Joypad::axisDecode(scancode)] == false) {
        string position;
        if(state < -24576) position = ".Lo";
        else if(state > +24576) position = ".Hi";
        else return;

        setAssignment(string() << mapper().modifierString() << Scancode::encode(scancode) << position);
      } else {
        if(state >= 0) return;

        setAssignment(string() << mapper().modifierString() << Scancode::encode(scancode) << ".Trigger");
      }
    } else if(Joypad::isAnyButton(scancode) && mapper().state(scancode)) {
      setAssignment(string() << mapper().modifierString() << Scancode::encode(scancode));
    }
  } else if(dynamic_cast<AnalogInput*>(activeInput)) {
    if(Mouse::isAnyButton(scancode)) {
      //ensure button was clicked inside list box
      unsigned wx = 0, wy = 0;
      QWidget *widget = message;
      while(widget) {
        wx += widget->geometry().x();
        wy += widget->geometry().y();
        widget = widget->parentWidget();
      }
      unsigned px = QCursor::pos().x();
      unsigned py = QCursor::pos().y();
      if(px < wx || px >= wx + message->size().width()) return;
      if(py < wy || py >= wy + message->size().height()) return;

      unsigned number = Mouse::numberDecode(scancode);
      unsigned button = Mouse::buttonDecode(scancode);
      if(button == 0) setAssignment(string() << Scancode::encode(mouse(number).axis(0)));
      if(button == 2) setAssignment(string() << Scancode::encode(mouse(number).axis(1)));
    } else if(Joypad::isAnyAxis(scancode) && mapper().distance(scancode) > 64) {
      if(mapper().calibrated == false) {
        MappedInput *temp = activeInput;
        activeInput = 0;
        mapper().calibrate();
        activeInput = temp;
      }

      if(mapper().isTrigger[Joypad::numberDecode(scancode)][Joypad::axisDecode(scancode)] == false) {
        if(state < -24576 || state > +24576) {
          setAssignment(string() << Scancode::encode(scancode));
        }
      }
    }
  }
}
Exemplo n.º 5
0
void InputSettingsWindow::yAxisAssign() {
  setAssignment(string() << Scancode::encode(mouse(activeMouse).axis(1)));
}