示例#1
0
void
NdbapiDriver::initProperties() {
    CrundDriver::initProperties();

    cout << "setting ndb properties ..." << flush;

    ostringstream msg;

    mgmdConnect = toString(props[L"ndb.mgmdConnect"]);
    if (mgmdConnect.empty()) {
        mgmdConnect = string("localhost");
    }

    catalog = toString(props[L"ndb.catalog"]);
    if (catalog.empty()) {
        catalog = string("crunddb");
    }

    schema = toString(props[L"ndb.schema"]);
    if (schema.empty()) {
        schema = string("def");
    }

    //if (msg.tellp() == 0) {
    if (msg.str().empty()) {
        cout << "      [ok]" << endl;
    } else {
        cout << endl << msg.str() << endl;
    }

    descr = "ndbapi(" + mgmdConnect + ")";
}
示例#2
0
	/**
	 * Common function for command service callbacks.
	 *
	 * NOTE: success is bool in messages, but has unsigned char type in C++
	 */
	bool send_command_long_and_wait(bool broadcast,
			uint16_t command, uint8_t confirmation,
			float param1, float param2,
			float param3, float param4,
			float param5, float param6,
			float param7,
			unsigned char &success, uint8_t &result)
	{
		using mavlink::common::MAV_RESULT;

		unique_lock lock(mutex);

		L_CommandTransaction::iterator ack_it;

		/* check transactions */
		for (const auto &tr : ack_waiting_list) {
			if (tr.expected_command == command) {
				ROS_WARN_THROTTLE_NAMED(10, "cmd", "CMD: Command %u already in progress", command);
				return false;
			}
		}

		/**
		 * @note APM & PX4 master always send COMMAND_ACK. Old PX4 never.
		 * Don't expect any ACK in broadcast mode.
		 */
		bool is_ack_required = (confirmation != 0 || m_uas->is_ardupilotmega() || m_uas->is_px4()) && !broadcast;
		if (is_ack_required)
			ack_it = ack_waiting_list.emplace(ack_waiting_list.end(), command);

		command_long(broadcast,
				command, confirmation,
				param1, param2,
				param3, param4,
				param5, param6,
				param7);

		if (is_ack_required) {
			lock.unlock();
			bool is_not_timeout = wait_ack_for(*ack_it);
			lock.lock();

			success = is_not_timeout && ack_it->result == enum_value(MAV_RESULT::ACCEPTED);
			result = ack_it->result;

			ack_waiting_list.erase(ack_it);
		}
		else {
			success = true;
			result = enum_value(MAV_RESULT::ACCEPTED);
		}

		return true;
	}
示例#3
0
Conf& Conf::def_int(std::string name,
            int lower_bound,
            int upper_bound,
            int default_value) {
    assert2(lower_bound <= default_value && default_value <= upper_bound,
                MS() << "Default value for " << name << "not in range.");
    auto i = make_shared<Int>();
    i->lower_bound = lower_bound;
    i->upper_bound = upper_bound;
    i->default_value = default_value;
    i->value = default_value;

    items[name] = i;
    return *this;
}
示例#4
0
Conf& Conf::def_float(std::string name,
            double lower_bound,
            double upper_bound,
            double default_value) {
    assert2(lower_bound <= default_value && default_value <= upper_bound,
                MS() << "Default value for " << name << "not in range.");
    auto f = make_shared<Float>();
    f->lower_bound = lower_bound;
    f->upper_bound = upper_bound;
    f->default_value = default_value;
    f->value = default_value;

    items[name] = f;
    return *this;
}
示例#5
0
文件: tcp.cpp 项目: FOXTTER/mavros
MAVConnTCPClient::MAVConnTCPClient(uint8_t system_id, uint8_t component_id,
		std::string server_host, unsigned short server_port) :
	MAVConnInterface(system_id, component_id),
	tx_in_progress(false),
	tx_q {},
	rx_buf {},
	io_service(),
	io_work(new io_service::work(io_service)),
	socket(io_service)
{
	if (!resolve_address_tcp(io_service, conn_id, server_host, server_port, server_ep))
		throw DeviceError("tcp: resolve", "Bind address resolve failed");

	logInform(PFXd "Server address: %s", conn_id, to_string_ss(server_ep).c_str());

	try {
		socket.open(tcp::v4());
		socket.connect(server_ep);
	}
	catch (boost::system::system_error &err) {
		throw DeviceError("tcp", err);
	}

	// give some work to io_service before start
	io_service.post(std::bind(&MAVConnTCPClient::do_recv, this));

	// run io_service for async io
	io_thread = std::thread([this] () {
				utils::set_this_thread_name("mtcp%zu", conn_id);
				io_service.run();
			});
}
示例#6
0
	void command_int(bool broadcast,
			uint8_t frame, uint16_t command,
			uint8_t current, uint8_t autocontinue,
			float param1, float param2,
			float param3, float param4,
			int32_t x, int32_t y,
			float z)
	{
		using mavlink::common::MAV_COMPONENT;

		const uint8_t tgt_sys_id = (broadcast) ? 0 : m_uas->get_tgt_system();
		const uint8_t tgt_comp_id = (broadcast) ? 0 :
			(use_comp_id_system_control) ?
				enum_value(MAV_COMPONENT::COMP_ID_SYSTEM_CONTROL) : m_uas->get_tgt_component();

		mavlink::common::msg::COMMAND_INT cmd;
		cmd.target_system = tgt_sys_id;
		cmd.target_component = tgt_comp_id;
		cmd.frame = frame;
		cmd.command = command;
		cmd.current = current;
		cmd.autocontinue = autocontinue;
		cmd.param1 = param1;
		cmd.param2 = param2;
		cmd.param3 = param3;
		cmd.param4 = param4;
		cmd.x = x;
		cmd.y = y;
		cmd.z = z;

		UAS_FCU(m_uas)->send_message_ignore_drop(cmd);
	}
示例#7
0
文件: tcp.cpp 项目: FOXTTER/mavros
MAVConnTCPServer::MAVConnTCPServer(uint8_t system_id, uint8_t component_id,
		std::string server_host, unsigned short server_port) :
	MAVConnInterface(system_id, component_id),
	io_service(),
	acceptor(io_service)
{
	if (!resolve_address_tcp(io_service, conn_id, server_host, server_port, bind_ep))
		throw DeviceError("tcp-l: resolve", "Bind address resolve failed");

	logInform(PFXd "Bind address: %s", conn_id, to_string_ss(bind_ep).c_str());

	try {
		acceptor.open(tcp::v4());
		acceptor.set_option(tcp::acceptor::reuse_address(true));
		acceptor.bind(bind_ep);
		acceptor.listen();
	}
	catch (boost::system::system_error &err) {
		throw DeviceError("tcp-l", err);
	}

	// give some work to io_service before start
	io_service.post(std::bind(&MAVConnTCPServer::do_accept, this));

	// run io_service for async io
	io_thread = std::thread([this] () {
				utils::set_this_thread_name("mtcps%zu", conn_id);
				io_service.run();
			});
}
示例#8
0
Conf& Conf::def_choice(std::string name,
                       std::vector<std::string> choices,
                       std::string default_value) {
    assert2(in_vector(choices, default_value),
        MS() << default_value << " is not an option for " << name);
    assert2(choices.size() >= 2,
        MS() << "At least two choices are needed for " << name);
    auto c = make_shared<Choice>();
    c->choices = choices;
    c->default_value = default_value;
    c->value = default_value;


    items[name] = c;
    return *this;
}
示例#9
0
	void command_long(bool broadcast,
			uint16_t command, uint8_t confirmation,
			float param1, float param2,
			float param3, float param4,
			float param5, float param6,
			float param7)
	{
		using mavlink::common::MAV_COMPONENT;

		const uint8_t tgt_sys_id = (broadcast) ? 0 : m_uas->get_tgt_system();
		const uint8_t tgt_comp_id = (broadcast) ? 0 :
			(use_comp_id_system_control) ?
				enum_value(MAV_COMPONENT::COMP_ID_SYSTEM_CONTROL) : m_uas->get_tgt_component();
		const uint8_t confirmation_fixed = (broadcast) ? 0 : confirmation;

		mavlink::common::msg::COMMAND_LONG cmd;
		cmd.target_system = tgt_sys_id;
		cmd.target_component = tgt_comp_id;
		cmd.command = command;
		cmd.confirmation = confirmation_fixed;
		cmd.param1 = param1;
		cmd.param2 = param2;
		cmd.param3 = param3;
		cmd.param4 = param4;
		cmd.param5 = param5;
		cmd.param6 = param6;
		cmd.param7 = param7;

		UAS_FCU(m_uas)->send_message_ignore_drop(cmd);
	}
示例#10
0
 vector<BeamTreeResult<T>> best_trees(vector<Mat<T>> input, int beam_width) const {
     auto leaves = convert_to_leaves(input);
     vector<PartialTree> candidates = { PartialTree(leaves) };
     while (candidates[0].nodes.size() > 1) {
         vector<PartialTree> new_candidates;
         for (auto& candidate: candidates) {
             for (auto& new_candidate: cangen(candidate, beam_width)) {
                 new_candidates.emplace_back(new_candidate);
             }
         }
         sort(new_candidates.begin(), new_candidates.end(),
         [this](const PartialTree& c1, const PartialTree& c2) {
             return candidate_log_probability(c1) > candidate_log_probability(c2);
         });
         candidates = vector<PartialTree>(
                          new_candidates.begin(),
                          new_candidates.begin() + min((size_t)beam_width, new_candidates.size())
                      );
         for (size_t cidx = 0; cidx + 1 < candidates.size(); ++cidx) {
             assert2(candidates[cidx].nodes.size() == candidates[cidx + 1].nodes.size(),
                     "Generated candidates of different sizes.");
         }
     }
     vector<BeamTreeResult<T>> results;
     for (auto& tree: candidates) {
         results.emplace_back(tree.nodes[0], tree.derivation);
     }
     return results;
 }
示例#11
0
shared_ptr<visualizable::Tree> visualize_derivation(vector<uint> derivation, vector<string> words) {
    using visualizable::Tree;

    vector<shared_ptr<Tree>> result;
    std::transform(words.begin(), words.end(), std::back_inserter(result),
    [](const string& a) {
        return make_shared<Tree>(a);
    });
    for (auto merge_idx : derivation) {
        vector<shared_ptr<Tree>> new_result;
        for(size_t ridx = 0; ridx < merge_idx; ++ridx) {
            new_result.push_back(result[ridx]);
        }
        new_result.push_back(make_shared<Tree>(std::initializer_list<shared_ptr<Tree>> {
            result[merge_idx],
            result[merge_idx + 1]
        }));
        for(size_t ridx = merge_idx + 2; ridx < result.size(); ++ridx) {
            new_result.push_back(result[ridx]);
        }
        result = new_result;
    }
    assert2(result.size() == 1, "Szymon messed up.");

    return result[0];
}
示例#12
0
文件: tcp.cpp 项目: FOXTTER/mavros
void MAVConnTCPClient::client_connected(size_t server_channel)
{
	logInform(PFXd "Got client, id: %zu, address: %s",
			server_channel, conn_id, to_string_ss(server_ep).c_str());

	// start recv
	socket.get_io_service().post(std::bind(&MAVConnTCPClient::do_recv, this));
}
// Quantise a subband in in-place transform order
// This version of quantise_subbands assumes multiple quantisers per subband.
// It may be used for either quantising slices or for quantising subbands with codeblocks
const Array2D quantise_subbands(const Array2D& coefficients, const BlockVector& qIndices) {
  const Index transformHeight = coefficients.shape()[0];
  const Index transformWidth = coefficients.shape()[1];
  // TO DO: Check numberOfSubbands=3n+1 ?
  const int numberOfSubbands = qIndices.size();
  const int waveletDepth = (numberOfSubbands-1)/3;
  Index stride, offset; // stride is subsampling factor, offset is subsampling phase
  Array2D result(coefficients.ranges());

  // Create a view of the coefficients, representing the LL subband, quantise it,
  // then assign the result a view of the results array. This puts the quantised
  // LL subband into the result array in in-place transform order.
  // ArrayIndices2D objects specify the subset of array elements within a view,
  // that is they specify the subsampling factor and subsampling phase.
  stride = pow(2, waveletDepth);
  const ArrayIndices2D LLindices = // LLindices specifies the samples in the LL subband
    indices[Range(0,transformHeight,stride)][Range(0,transformWidth,stride)];
  result[LLindices] =
    quantise_LLSubband(coefficients[LLindices], qIndices[0]);

  // Next quantise the other subbands
  // Note: Level numbers go from zero for the lowest ("DC") frequencies to depth for
  // the high frequencies. This corresponds to the convention in the VC-2 specification.
  // Subands go from zero ("DC") to numberOfSubbands-1 for HH at the highest level
  for (char level=1, band=1; level<=waveletDepth; ++level) {
    stride = pow(2, waveletDepth+1-level);
    offset = stride/2;
    // Create a view of coefficients corresponding to a subband, then quantise it
    //Quantise HL subband
    const ArrayIndices2D HLindices = // HLindices specifies the samples in the HL subband
      indices[Range(0,transformHeight,stride)][Range(offset,transformWidth,stride)];
    result[HLindices] = quantise_block(coefficients[HLindices], qIndices[band++]);
    //Quantise LH subband
    const ArrayIndices2D LHindices = // LHindices specifies the samples in the LH subband
      indices[Range(offset,transformHeight,stride)][Range(0,transformWidth,stride)];
    result[LHindices] = quantise_block(coefficients[LHindices], qIndices[band++]);
    //Quantise HH subband
    const ArrayIndices2D HHindices = // HHindices specifies the samples in the HH subband
      indices[Range(offset,transformHeight,stride)][Range(offset,transformWidth,stride)];
    result[HHindices] = quantise_block(coefficients[HHindices], qIndices[band++]);
  }

  return result;
}
示例#14
0
	bool arming_cb(mavros_msgs::CommandBool::Request &req,
			mavros_msgs::CommandBool::Response &res)
	{
		using mavlink::common::MAV_CMD;
		return send_command_long_and_wait(false,
				enum_value(MAV_CMD::COMPONENT_ARM_DISARM), 1,
				(req.value) ? 1.0 : 0.0,
				0, 0, 0, 0, 0, 0,
				res.success, res.result);
	}
示例#15
0
	bool set_home_cb(mavros_msgs::CommandHome::Request &req,
			mavros_msgs::CommandHome::Response &res)
	{
		using mavlink::common::MAV_CMD;
		return send_command_long_and_wait(false,
				enum_value(MAV_CMD::DO_SET_HOME), 1,
				(req.current_gps) ? 1.0 : 0.0,
				0, 0, 0, req.latitude, req.longitude, req.altitude,
				res.success, res.result);
	}
示例#16
0
    virtual void run(unsigned int generations,
                     unsigned int logFrequency = 100) {
        // Generation: create the new members
        for (auto i = 0U; i < PopSize; ++i) {
            population.push_back(generator());
        }

        for (auto generation = 0U; generation < generations; ++generation) {
            // Crossover: Add missing members
            auto popSizePostSelection = population.size();
            while (population.size() < PopSize) {
                population.push_back(
                    crossover(population[random_uint(popSizePostSelection)],
                              population[random_uint(popSizePostSelection)]));
            }

            // Mutation: Mutate at least rate*popsize members
            for (size_t i = 0; i < PopSize * mutationRate; ++i) {
                auto index = random_uint(PopSize);
                mutator(population[index]);
            }

            // Selection: Destroy the least fit members
            selector(population, evaluator);

            if (evaluator(population[0]) > bestScore) {
                bestMember = population[0];
                bestScore = evaluator(population[0]);
            }

            if (generation % logFrequency == 0) {
                std::cout << "Generation(" << generation
                          << ") - Fitness:" << bestScore << std::endl;
            }
        }
        std::cout << "Best: ";
        for (const auto& allele : bestMember) {
            std::cout << allele << " ";
        }
        std::cout << std::endl << "Fitness: " << evaluator(bestMember)
                  << std::endl;
    }
示例#17
0
        bool trigger_control_cb(mavros_msgs::CommandTriggerControl::Request &req,
			mavros_msgs::CommandTriggerControl::Response &res)
	{
		using mavlink::common::MAV_CMD;
		return send_command_long_and_wait(false,
				enum_value(MAV_CMD::DO_TRIGGER_CONTROL), 1,
				(req.trigger_enable)? 1.0 : 0.0,
				req.integration_time,
				0, 0, 0, 0, 0,
				res.success, res.result);
	}
示例#18
0
	bool land_cb(mavros_msgs::CommandTOL::Request &req,
			mavros_msgs::CommandTOL::Response &res)
	{
		using mavlink::common::MAV_CMD;
		return send_command_long_and_wait(false,
				enum_value(MAV_CMD::NAV_LAND), 1,
				0, 0, 0,
				req.yaw,
				req.latitude, req.longitude, req.altitude,
				res.success, res.result);
	}
示例#19
0
void MavRos::mavlink_pub_cb(const mavlink_message_t *mmsg, Framing framing)
{
	auto rmsg = boost::make_shared<mavros_msgs::Mavlink>();

	if  (mavlink_pub.getNumSubscribers() == 0)
		return;

	rmsg->header.stamp = ros::Time::now();
	mavros_msgs::mavlink::convert(*mmsg, *rmsg, enum_value(framing));
	mavlink_pub.publish(rmsg);
}
示例#20
0
	inline void set_target(MsgT &cmd, bool broadcast)
	{
		using mavlink::common::MAV_COMPONENT;

		const uint8_t tgt_sys_id = (broadcast) ? 0 : m_uas->get_tgt_system();
		const uint8_t tgt_comp_id = (broadcast) ? 0 :
			(use_comp_id_system_control) ?
				enum_value(MAV_COMPONENT::COMP_ID_SYSTEM_CONTROL) : m_uas->get_tgt_component();

		cmd.target_system = tgt_sys_id;
		cmd.target_component = tgt_comp_id;
	}
示例#21
0
文件: tcp.cpp 项目: FOXTTER/mavros
void MAVConnTCPServer::client_closed(std::weak_ptr<MAVConnTCPClient> weak_instp)
{
	if (auto instp = weak_instp.lock()) {
		bool locked = mutex.try_lock();
		logInform(PFXd "Client connection closed, id: %p, address: %s",
				conn_id, instp.get(), to_string_ss(instp->server_ep).c_str());

		client_list.remove(instp);

		if (locked)
			mutex.unlock();
	}
}
示例#22
0
	bool trigger_interval_cb(mavros_msgs::CommandTriggerInterval::Request &req,
			mavros_msgs::CommandTriggerInterval::Response &res)
	{
		using mavlink::common::MAV_CMD;

		// trigger interval can only be set when triggering is disabled
		return send_command_long_and_wait(false,
				enum_value(MAV_CMD::DO_SET_CAM_TRIGG_INTERVAL), 1,
				req.cycle_time,
				req.integration_time,
				0, 0, 0, 0, 0,
				res.success, res.result);
	}
        void Build() {
            std::vector<utils::slice> key_slices;

            for (size_t i = 0; i < keys_.size(); i++) {
                key_slices.push_back(slice(keys_[i]));
            }

            filter_.clear();
            policy_->create_filter(&key_slices[0], key_slices.size(), &filter_);
            keys_.clear();

            if (kVerbose >= 2) DumpFilter();
        }
示例#24
0
	void player_right_clicked(int x, int y)
	{
		if (world_state != WORLDSTATE_NOLOAD) {return;}
		if ((*global).active_screen != SCREEN_WORLD){return;}
		if ((*global).game_pause) {return;}

		if ( util.is_same_tile(x,y, (*global).player.player_at_x_int, (*global).player.player_at_y_int))
		{
			return;
		}

		t_o_interact.player_to_teleport_to(x,y);
	}
示例#25
0
    /**
    Given an ordered set of n nodes, find the best contiguous
    pairs to join to form n-1 nodes. Return the `beam_width`
    best set of nodes with the resulting join applied.

    Inputs
    ------

    vector<Node> states : nodes to join
    int      beam_width : number of joins to consider

    Outputs
    -------

    vector<Candidate> new states : new sets with joined nodes
    **/
    vector<PartialTree> cangen(PartialTree candidate, int beam_width) const {
        assert2(candidate.nodes.size() >= 2,
                "Must at least have 2 states to join for candidate generation.");
        int num_candidates = min((size_t)beam_width, candidate.nodes.size() - 1);

        vector<Node> possible_joins;
        vector<Mat<T>> scores;
        for (size_t sidx = 0; sidx + 1 < candidate.nodes.size(); ++sidx) {
            possible_joins.emplace_back(
                Mat<T>(),
                join_states(candidate.nodes[sidx], candidate.nodes[sidx + 1])
            );
            scores.emplace_back(prob_decoder.activate(possible_joins.back().state.hidden));
        }
        auto normalized_scores = MatOps<T>::softmax(scores);
        for (size_t sidx = 0; sidx + 1 < candidate.nodes.size(); ++sidx) {
            possible_joins[sidx].log_probability =
                normalized_scores[sidx].log() +
                candidate.nodes[sidx].log_probability +
                candidate.nodes[sidx + 1].log_probability;
        }

        // initialize original index locations
        vector<size_t> idx(possible_joins.size());
        for (size_t i = 0; i < idx.size(); ++i)
            idx[i] = i;

        // sort indexes based on comparing values in v
        sort(idx.begin(), idx.end(), [&possible_joins](size_t i1, size_t i2) {
            return possible_joins[i1].log_probability.w(0) > possible_joins[i2].log_probability.w(0);
        });
        vector<PartialTree> results;

        for (size_t cidx = 0; cidx < num_candidates; ++cidx) {
            vector<Node> result;
            size_t join_idx = idx[cidx];
            for (size_t sidx = 0; sidx < join_idx; ++sidx)
                result.emplace_back(candidate.nodes[sidx]);
            result.emplace_back(possible_joins[join_idx]);
            for (size_t sidx = join_idx + 2; sidx < candidate.nodes.size(); ++sidx) {
                result.emplace_back(candidate.nodes[sidx]);
            }
            assert(result.size() == candidate.nodes.size() - 1);
            auto new_derivation = candidate.derivation; // copy
            // here cidx encodes the decision we made to join nodes cidx and cidx + 1.
            new_derivation.push_back(cidx);
            results.emplace_back(PartialTree(result, new_derivation));
        }

        return results;
    }
示例#26
0
/* ヤキトリマークの表示 */
void GameTableScreen::TrayReconst::ShowYakitori(const GameTable* gameStat) {
	for (PlayerID i = 0; i < Players; ++i) {
		if (!gameStat->Player[i].YakitoriFlag) continue;
		switch (playerRelative(i, gameStat->PlayerID)) {
		case sSelf:
			{
				RECT rect = {
					(PlateWidthH + PlatePadding * 2) * (PlateID_Yakitori    ) + PlatePadding, (PlateHeightH + PlatePadding * 2) * (0    ) + PlatePadding,
					(PlateWidthH + PlatePadding * 2) * (PlateID_Yakitori + 1) - PlatePadding, (PlateHeightH + PlatePadding * 2) * (0 + 1) - PlatePadding,
				};
				SpriteRenderer::instantiate(caller->caller->getDevice())->ShowSprite(tChiicha, YakitoriPosH, YakitoriPosV,
					PlateWidthH, PlateHeightH, 0xffffffff, &rect, PlateWidthH / 2, PlateHeightH / 2);
			}
			break;
		case sOpposite:
			{
				RECT rect = {
					(PlateWidthH + PlatePadding * 2) * (PlateID_Yakitori    ) + PlatePadding, (PlateHeightH + PlatePadding * 2) * (1    ) + PlatePadding,
					(PlateWidthH + PlatePadding * 2) * (PlateID_Yakitori + 1) - PlatePadding, (PlateHeightH + PlatePadding * 2) * (1 + 1) - PlatePadding,
				};
				SpriteRenderer::instantiate(caller->caller->getDevice())->ShowSprite(tChiicha, TableSize - YakitoriPosH, TableSize - YakitoriPosV,
					PlateWidthH, PlateHeightH, 0xffffffff, &rect, PlateWidthH / 2, PlateHeightH / 2);
			}
			break;
		case sRight:
			{
				RECT rect = {
					(PlateWidthV + PlatePadding * 2) * (PlateID_Yakitori    ) + PlatePadding, (PlateHeightV + PlatePadding * 2) * (0    ) + PlatePadding + (PlateHeightH + PlatePadding * 2) * 2,
					(PlateWidthV + PlatePadding * 2) * (PlateID_Yakitori + 1) - PlatePadding, (PlateHeightV + PlatePadding * 2) * (0 + 1) - PlatePadding + (PlateHeightH + PlatePadding * 2) * 2,
				};
				SpriteRenderer::instantiate(caller->caller->getDevice())->ShowSprite(tChiicha, YakitoriPosV, TableSize - YakitoriPosH,
					PlateWidthV, PlateHeightV, 0xffffffff, &rect, PlateWidthV / 2, PlateHeightV / 2);
			}
			break;
		case sLeft:
			{
				RECT rect = {
					(PlateWidthV + PlatePadding * 2) * (PlateID_Yakitori    ) + PlatePadding, (PlateHeightV + PlatePadding * 2) * (1    ) + PlatePadding + (PlateHeightH + PlatePadding * 2) * 2,
					(PlateWidthV + PlatePadding * 2) * (PlateID_Yakitori + 1) - PlatePadding, (PlateHeightV + PlatePadding * 2) * (1 + 1) - PlatePadding + (PlateHeightH + PlatePadding * 2) * 2,
				};
				SpriteRenderer::instantiate(caller->caller->getDevice())->ShowSprite(tChiicha, TableSize - YakitoriPosV, YakitoriPosH,
					PlateWidthV, PlateHeightV, 0xffffffff, &rect, PlateWidthV / 2, PlateHeightV / 2);
			}
			break;
		}
	}
}
示例#27
0
/* 起家マークの表示 */
void GameTableScreen::TrayReconst::ShowChiicha(const GameTable* gameStat) {
	switch (playerRelative(0, gameStat->PlayerID)) {
	case sSelf:
		{
			RECT rect = {
				static_cast<int32_t>((PlateWidthH + PlatePadding * 2) * (gameStat->GameRound / Players    ) + PlatePadding), static_cast<int32_t>((PlateHeightH + PlatePadding * 2) * (0    ) + PlatePadding),
				static_cast<int32_t>((PlateWidthH + PlatePadding * 2) * (gameStat->GameRound / Players + 1) - PlatePadding), static_cast<int32_t>((PlateHeightH + PlatePadding * 2) * (0 + 1) - PlatePadding),
			};
			SpriteRenderer::instantiate(caller->caller->getDevice())->ShowSprite(tChiicha, PlatePosH, PlatePosV,
				PlateWidthH, PlateHeightH, 0xffffffff, &rect, PlateWidthH / 2, PlateHeightH / 2);
		}
		break;
	case sOpposite:
		{
			RECT rect = {
				static_cast<int32_t>((PlateWidthH + PlatePadding * 2) * (gameStat->GameRound / Players    ) + PlatePadding), static_cast<int32_t>((PlateHeightH + PlatePadding * 2) * (1    ) + PlatePadding),
				static_cast<int32_t>((PlateWidthH + PlatePadding * 2) * (gameStat->GameRound / Players + 1) - PlatePadding), static_cast<int32_t>((PlateHeightH + PlatePadding * 2) * (1 + 1) - PlatePadding),
			};
			SpriteRenderer::instantiate(caller->caller->getDevice())->ShowSprite(tChiicha, TableSize - PlatePosH, TableSize - PlatePosV,
				PlateWidthH, PlateHeightH, 0xffffffff, &rect, PlateWidthH / 2, PlateHeightH / 2);
		}
		break;
	case sRight:
		{
			RECT rect = {
				static_cast<int32_t>((PlateWidthV + PlatePadding * 2) * (gameStat->GameRound / Players    ) + PlatePadding), static_cast<int32_t>((PlateHeightV + PlatePadding * 2) * (0    ) + PlatePadding + (PlateHeightH + PlatePadding * 2) * 2),
				static_cast<int32_t>((PlateWidthV + PlatePadding * 2) * (gameStat->GameRound / Players + 1) - PlatePadding), static_cast<int32_t>((PlateHeightV + PlatePadding * 2) * (0 + 1) - PlatePadding + (PlateHeightH + PlatePadding * 2) * 2),
			};
			SpriteRenderer::instantiate(caller->caller->getDevice())->ShowSprite(tChiicha, PlatePosV, TableSize - PlatePosH,
				PlateWidthV, PlateHeightV, 0xffffffff, &rect, PlateWidthV / 2, PlateHeightV / 2);
		}
		break;
	case sLeft:
		{
			RECT rect = {
				static_cast<int32_t>((PlateWidthV + PlatePadding * 2) * (gameStat->GameRound / Players    ) + PlatePadding), static_cast<int32_t>((PlateHeightV + PlatePadding * 2) * (1    ) + PlatePadding + (PlateHeightH + PlatePadding * 2) * 2),
				static_cast<int32_t>((PlateWidthV + PlatePadding * 2) * (gameStat->GameRound / Players + 1) - PlatePadding), static_cast<int32_t>((PlateHeightV + PlatePadding * 2) * (1 + 1) - PlatePadding + (PlateHeightH + PlatePadding * 2) * 2),
			};
			SpriteRenderer::instantiate(caller->caller->getDevice())->ShowSprite(tChiicha, TableSize - PlatePosV, PlatePosH,
				PlateWidthV, PlateHeightV, 0xffffffff, &rect, PlateWidthV / 2, PlateHeightV / 2);
		}
		break;
	}
}
int main(int argc, char * argv[]) {
    GFLAGS_NAMESPACE::ParseCommandLineFlags(&argc, &argv, true);
    cout << "dbpath = " << FLAGS_dbpath << endl;
    // Open a database file
    SQLite::Database    db(FLAGS_dbpath);
    // Load mapping from concepts to names
    vector<string> index2concept;
    if (!utils::file_exists(FLAGS_clean_index2target)) {
        std::atomic<int> i(0);
        auto concept_redirections = utils::load_redirection_list(FLAGS_redirections, [&i](std::string&& s)->std::string {
            if (++i % 1000 == 0) {
                std::cout << i << " cleaned redirection names \r" << std::flush;
            }
            return utils::join(
                utils::xml_cleaner::split_punct_keep_brackets(s),
                " ");
        }, FLAGS_j);
        index2concept = utils::load_list(FLAGS_index2target);

        for (auto& concept : index2concept) {
            if (concept_redirections.find(concept) != concept_redirections.end()) {
                concept = utils::capitalize(concept_redirections.at(concept));
            } else {
                concept = utils::capitalize(concept);
            }
        }
        utils::save_list(index2concept, FLAGS_clean_index2target);
    } else {
        index2concept = utils::load_list(FLAGS_clean_index2target);
    }
    // Load some examples from DB
    SQLite::Statement   query(db, "SELECT lines FROM articles");
    // Convert protobuf -> vector<string>
    auto els = load_protobuff_dataset(query, index2concept, 100);
    cout << "got labeled examples" << endl;
    for (auto& el : els) {
        std::cout << utils::join(el[0], " ")
                  << " (\033[4m" << utils::join(el[1], "\x1B[m, \033[4m") << "\x1B[m)" << std::endl;
    }
}
示例#29
0
文件: tcp.cpp 项目: FOXTTER/mavros
static bool resolve_address_tcp(io_service &io, size_t chan, std::string host, unsigned short port, tcp::endpoint &ep)
{
	bool result = false;
	tcp::resolver resolver(io);
	error_code ec;

	tcp::resolver::query query(host, "");
	std::for_each(resolver.resolve(query, ec), tcp::resolver::iterator(),
			[&](const tcp::endpoint & q_ep) {
				ep = q_ep;
				ep.port(port);
				result = true;
				logDebug(PFXd "host %s resolved as %s", chan, host.c_str(), to_string_ss(ep).c_str());
			});

	if (ec) {
		logWarn(PFXd "resolve error: %s", chan, ec.message().c_str());
		result = false;
	}

	return result;
}
示例#30
0
void training_loop(std::shared_ptr<Solver::AbstractSolver<REAL_t>> solver,
                   model_t& model,
                   std::function<vector<uint>(vector<uint>&)> pred_fun,
                   vector<numeric_example_t>& train,
                   vector<numeric_example_t>& validate) {
    auto& vocab = arithmetic::vocabulary;

    auto params = model.parameters();

    int epoch = 0;
    int difficulty_waiting = 0;
    auto end_symbol_idx = vocab.word2index[utils::end_symbol];

    int beam_width = FLAGS_beam_width;

    if (beam_width < 1)
        utils::exit_with_message(MS() << "Beam width must be strictly positive (got " << beam_width << ")");

    Throttled throttled_examples;
    Throttled throttled_validation;

    bool target_accuracy_reached = false;

    while (!target_accuracy_reached && epoch++ < FLAGS_graduation_time) {

        auto indices = utils::random_arange(train.size());
        auto indices_begin = indices.begin();

        REAL_t minibatch_error = 0.0;

        // one minibatch
        for (auto indices_begin = indices.begin();
                indices_begin < indices.begin() + std::min((size_t)FLAGS_minibatch, train.size());
                indices_begin++) {
            // <training>
            auto& example = train[*indices_begin];

            auto error = model.error(example, beam_width);
            error.grad();
            graph::backward();
            minibatch_error += error.w(0);
            // </training>
            // // <reporting>
            throttled_examples.maybe_run(seconds(10), [&]() {
                graph::NoBackprop nb;
                auto random_example_index = utils::randint(0, validate.size() -1);
                auto& expression = validate[random_example_index].first;
                auto predictions = model.predict(expression,
                                                 beam_width,
                                                 MAX_OUTPUT_LENGTH,
                                                 vocab.word2index.at(utils::end_symbol));

                auto expression_string = arithmetic::vocabulary.decode(&expression);
                if (expression_string.back() == utils::end_symbol)
                    expression_string.resize(expression_string.size() - 1);
                std::cout << utils::join(expression_string) << std::endl;


                vector<string> prediction_string;
                vector<double> prediction_probability;

                for (auto& prediction : predictions) {
                    if (validate[random_example_index].second == prediction.prediction) {
                        std::cout << utils::green;
                    }
                    prediction_probability.push_back(prediction.get_probability().w(0));
                    std::cout << "= (" << std::setprecision( 3 ) << prediction.get_probability().log().w(0) << ") ";
                    auto digits = vocab.decode(&prediction.prediction);
                    if (digits.back() == utils::end_symbol)
                        digits.pop_back();
                    auto joined_digits = utils::join(digits);
                    prediction_string.push_back(joined_digits);
                    std::cout << joined_digits << utils::reset_color << std::endl;
                }
                auto vgrid = make_shared<visualizable::GridLayout>();

                assert2(predictions[0].derivations.size() == predictions[0].nodes.size(),
                        "Szymon messed up.");
                for (int didx = 0;
                        didx < min((size_t)FLAGS_visualizer_trees, predictions[0].derivations.size());
                        ++didx) {
                    auto visualization = visualize_derivation(
                                             predictions[0].derivations[didx],
                                             vocab.decode(&expression)
                                         );
                    auto tree_prob = predictions[0].nodes[didx].log_probability.exp().w(0,0);
                    vgrid->add_in_column(0, make_shared<visualizable::Probability<double>>(tree_prob));
                    vgrid->add_in_column(0, visualization);
                }
                vgrid->add_in_column(1, make_shared<visualizable::Sentence<double>>(expression_string));
                vgrid->add_in_column(1, make_shared<visualizable::FiniteDistribution<double>>(
                                         prediction_probability,
                                         prediction_string
                                     ));

                if (visualizer)
                    visualizer->feed(vgrid->to_json());

            });
            double current_accuracy = -1;
            throttled_validation.maybe_run(seconds(30), [&]() {
                current_accuracy = arithmetic::average_recall(validate, pred_fun, FLAGS_j);
                std::cout << "epoch: " << epoch << ", accuracy = " << std::setprecision( 3 )
                          << 100.0 * current_accuracy << "%" << std::endl;
            });
            if (current_accuracy != -1 && current_accuracy > 0.9) {
                std::cout << "Current accuracy is now " << current_accuracy << std::endl;
                target_accuracy_reached = true;
                break;
            }
            // </reporting>
        }
        solver->step(params); // One step of gradient descent
        epoch++;
    }
}