动态规划多阶段报童模型,c++ 实现, java 实现
借助 chaptgpt 和 deepseek,成功实现了c++上的多阶段报童模型的动态规划。花费了几天,将以前的 java 程序用 c++ 实现。
文章目录
- C++ 代码
- Java 代码
总结:
- c++ 还是比 java 快点,30个阶段快了零点几秒
- c++ 使用了 unordered_map ,存储递归数据
- java 使用了 ConcurrentSkipListMap 存储递归数据,这个可以按照排序器自动排序
- 若 c++ 也用可以排序的 map,速度反而比 java 慢了。理论上c++会快,但估计需要其他的一些功能设置
- c++ 运行时要开启 -o2 或 -o3 优化加速


C++ 代码
//
// Created by Zhen Chen on 2025/2/26.
//#include <chrono>
#include <iostream>
#include <limits>
#include <boost/functional/hash.hpp>
#include <unordered_map>
#include <iostream>
#include <map>
#include <span>
#include <csignal>class State {int period{}; // c++11, {} 值初始化,默认为 0double initialInventory{};public:State();explicit State(int period, double initialInventory);[[nodiscard]] double getInitialInventory() const;[[nodiscard]] int getPeriod() const;void print() const;// hashmap must define operator == and a struct to compute hashbool operator==(const State &other) const {// 需要定义 `==`// const MyClass &other 保证 other 参数不可修改// const 在函数结尾 保证当前对象(this) 不可修改// 不会修改成员变量的方法 都可以在函数声明的结尾添加 constreturn period == other.period && initialInventory == other.initialInventory;}// 允许哈希结构体访问私有成员// friend structfriend struct std::hash<State>;// define operator < or give a self defined comparator for sorting mapbool operator<(const State &other) const {if (period < other.period) {return true;}if (period == other.period) {if (initialInventory < other.initialInventory) {return true;}return false;}return false;}
};// `std::hash<State>` 需要特化
template<> // 表示模版特化, override 标准库中的 hash 生成函数
struct std::hash<State> {// size_t 表示无符号整数size_t operator()(const State &s) const noexcept {// noexcept 表示这个函数不会抛出异常// boost 的哈希计算更安全std::size_t seed = 0;boost::hash_combine(seed, s.period);boost::hash_combine(seed, s.initialInventory);return seed;// return std::hash<int>()(s.period) ^ std::hash<double>()(s.initialInventory) << 1; // 计算哈希值// std::hash<int>() 是一个 std::hash<int> 类型的对象,调用 () 运算符可以计算 obj.id(整数)的哈希值// ^(异或)是位运算,不会造成进位,适合合并多个哈希值// 这里的 << 1 左移 1 位(相当于乘 2),让哈希值更加分散,避免简单叠加导致哈希冲突}
};State::State() = default;State::State(const int period, const double initialInventory): period(period), initialInventory(initialInventory) {
};double State::getInitialInventory() const {return initialInventory;
}int State::getPeriod() const {return period;
}void State::print() const {std::cout << "period: " << period << ", ini I: " << initialInventory << std::endl;
}class ProbabilityMassFunctions {double truncatedQuantile;double stepSize;std::string distributionName;public:ProbabilityMassFunctions(double truncatedQuantile, double stepSize, std::string distributionName);// std::string getName();void checkName() const;static double poissonPMF(int k, double lambda);[[nodiscard]] std::vector<std::vector<std::vector<double> > > getPMF(std::span<double> demands) const;[[nodiscard]] std::vector<std::vector<std::vector<double> > >getPMFPoisson(std::span<double> demands) const;static int poissonQuantile(double p, double lambda);static double poissonCDF(int k, double lambda);
};// initializing the class
ProbabilityMassFunctions::ProbabilityMassFunctions(const double truncatedQuantile, const double stepSize, std::string distributionName): truncatedQuantile(truncatedQuantile), stepSize(stepSize), distributionName(std::move(distributionName)) {checkName();
} // std::move for efficiency passing in string and vectorvoid ProbabilityMassFunctions::checkName() const {auto name = distributionName;std::ranges::transform(name, name.begin(), ::tolower);if (name != "poisson") {std::cout << " distribution not found or to do next for this distribution\n";raise(-1);}
}// get the probability mass function value of Poisson
double ProbabilityMassFunctions::poissonPMF(const int k, const double lambda) {if (k < 0 || lambda <= 0) return 0.0; // 确保参数合法return (std::pow(lambda, k) * std::exp(-lambda)) / std::tgamma(k + 1);// tgamma(k+1) is a gamma function, 等同于factorial(k)
}// get cumulative distribution function value of Poisson
double ProbabilityMassFunctions::poissonCDF(const int k, const double lambda) {double cumulative = 0.0;double term = std::exp(-lambda);for (int i = 0; i <= k; ++i) {cumulative += term;if (i < k)term *= lambda / (i + 1); // 递推计算 P(X=i)}return cumulative;
}// get inverse cumulative distribution function value of Poisson
int ProbabilityMassFunctions::poissonQuantile(const double p, const double lambda) {int low = 0, high = std::max(100, static_cast<int>(lambda * 3)); // 初始搜索区间while (low < high) {if (const int mid = (low + high) / 2; poissonCDF(mid, lambda) < p) {low = mid + 1;} else {high = mid;}}return low;
}// get probability mass function values for each period of Poisson
std::vector<std::vector<std::vector<double> > > ProbabilityMassFunctions::
getPMF(const std::span<double> demands) const {if (distributionName == "poisson") {return getPMFPoisson(demands);}return {};
}// get probability mass function values for each period of Poisson
std::vector<std::vector<std::vector<double> > > ProbabilityMassFunctions::
getPMFPoisson(const std::span<double> demands) const {const auto T = demands.size();int supportLB[T];int supportUB[T];for (int i = 0; i < T; ++i) {supportUB[i] = poissonQuantile(truncatedQuantile, demands[i]);supportLB[i] = poissonQuantile(1 - truncatedQuantile, demands[i]);}std::vector<std::vector<std::vector<double> > > pmf(T, std::vector<std::vector<double> >());for (int t = 0; t < T; ++t) {const int demandLength = static_cast<int>((supportUB[t] - supportLB[t] + 1) / stepSize);pmf[t] = std::vector<std::vector<double> >(demandLength, std::vector<double>());for (int j = 0; j < demandLength; ++j) {pmf[t][j] = std::vector<double>(2);pmf[t][j][0] = supportLB[t] + j * stepSize;const int demand = static_cast<int>(pmf[t][j][0]);pmf[t][j][1] = poissonPMF(demand, demands[t]) / (2 * truncatedQuantile - 1);}}return pmf;
}class NewsvendorDP {int T;int capacity;double stepSize;double fixOrderCost;double unitVariOrderCost;double unitHoldCost;double unitPenaltyCost;double truncatedQuantile;double max_I;double min_I;std::vector<std::vector<std::vector<double> > > pmf;std::unordered_map<State, double> cacheActions{};std::unordered_map<State, double> cacheValues{};// std::map<State, double> cacheActions{};
// std::map<State, double> cacheValues{};public:NewsvendorDP(size_t T, int capacity, double stepSize, double fixOrderCost, double unitVariOrderCost,double unitHoldCost, double unitPenaltyCost, double truncatedQuantile, double max_I, double min_I,std::vector<std::vector<std::vector<double> > > pmf);[[nodiscard]] std::vector<double> feasibleActions() const;[[nodiscard]] State stateTransitionFunction(const State &state, double action, double demand) const;[[nodiscard]] double immediateValueFunction(const State &state, double action, double demand) const;[[nodiscard]] double getOptAction(const State &tate);[[nodiscard]] auto getTable() const;double recursion(const State &state);
};NewsvendorDP::NewsvendorDP(const size_t T, const int capacity,const double stepSize, const double fixOrderCost,const double unitVariOrderCost,const double unitHoldCost, const double unitPenaltyCost,const double truncatedQuantile, const double max_I,const double min_I,std::vector<std::vector<std::vector<double> > > pmf): T(static_cast<int>(T)),capacity(capacity),stepSize(stepSize),fixOrderCost(fixOrderCost),unitVariOrderCost(unitVariOrderCost),unitHoldCost(unitHoldCost), unitPenaltyCost(unitPenaltyCost), truncatedQuantile(truncatedQuantile),max_I(max_I), min_I(min_I), pmf(std::move(pmf)) {
};std::vector<double> NewsvendorDP::feasibleActions() const {const int QNum = static_cast<int>(capacity / stepSize);std::vector<double> actions(QNum);for (int i = 0; i < QNum; i = i + 1) {actions[i] = i * stepSize;}return actions;
}State NewsvendorDP::stateTransitionFunction(const State &state, const double action, const double demand) const {double nextInventory = state.getInitialInventory() + action - demand;if (state.getPeriod() == 1) {(void) nextInventory;}if (nextInventory > 0) {(void) nextInventory;}nextInventory = nextInventory > max_I ? max_I : nextInventory;nextInventory = nextInventory < min_I ? min_I : nextInventory;const int nextPeriod = state.getPeriod() + 1;// C++11 引入了统一的列表初始化(Uniform Initialization),鼓励使用大括号 {} 初始化类const auto newState = State{nextPeriod, nextInventory};return newState;
}double NewsvendorDP::immediateValueFunction(const State &state, const double action, const double demand) const {const double fixCost = action > 0 ? fixOrderCost : 0;const double variCost = action * unitVariOrderCost;double nextInventory = state.getInitialInventory() + action - demand;nextInventory = nextInventory > max_I ? max_I : nextInventory;nextInventory = nextInventory < min_I ? min_I : nextInventory;const double holdCost = std::max(unitHoldCost * nextInventory, 0.0);const double penaltyCost = std::max(-unitPenaltyCost * nextInventory, 0.0);const double totalCost = fixCost + variCost + holdCost + penaltyCost;return totalCost;
}double NewsvendorDP::getOptAction(const State &state) {return cacheActions[state];
}auto NewsvendorDP::getTable() const {size_t stateNums = cacheActions.size();std::vector<std::vector<double> > table(stateNums, std::vector<double>(3));int index = 0;for (const auto &[fst, snd]: cacheActions) {table[index][0] = fst.getPeriod();table[index][1] = fst.getInitialInventory();table[index][2] = snd;index++;}return table;
}double NewsvendorDP::recursion(const State &state) {double bestQ = 0.0;double bestValue = std::numeric_limits<double>::max();const std::vector<double> actions = feasibleActions();for (const double action: feasibleActions()) {double thisValue = 0;for (auto demandAndProb: pmf[state.getPeriod() - 1]) {thisValue += demandAndProb[1] * immediateValueFunction(state, action, demandAndProb[0]);if (state.getPeriod() < T) {auto newState = stateTransitionFunction(state, action, demandAndProb[0]);(void) action;if (cacheValues.contains(newState)) {// some issues herethisValue += demandAndProb[1] * cacheValues[newState];} else {thisValue += demandAndProb[1] * recursion(newState);}}}if (thisValue < bestValue) {bestValue = thisValue;bestQ = action;}}cacheActions[state] = bestQ;cacheValues[state] = bestValue;return bestValue;
}int main() {std::vector<double> demands(30, 20);const std::string distribution_type = "poisson";constexpr int capacity = 100; // maximum ordering quantityconstexpr double stepSize = 1.0;constexpr double fixOrderCost = 0;constexpr double unitVariOderCost = 1;constexpr double unitHoldCost = 2;constexpr double unitPenaltyCost = 10;constexpr double truncQuantile = 0.9999; // truncated quantile for the demand distributionconstexpr double maxI = 500; // maximum possible inventoryconstexpr double minI = -300; // minimum possible inventoryconst auto pmf = ProbabilityMassFunctions(truncQuantile, stepSize, distribution_type).getPMF(demands);const size_t T = demands.size();auto model = NewsvendorDP(T, capacity, stepSize, fixOrderCost, unitVariOderCost, unitHoldCost, unitPenaltyCost,truncQuantile, maxI, minI, pmf);const auto initialState = State(1, 0);const auto start_time = std::chrono::high_resolution_clock::now();const auto optValue = model.recursion(initialState);const auto end_time = std::chrono::high_resolution_clock::now();const std::chrono::duration<double> duration = end_time - start_time;std::cout << "planning horizon is " << T << " periods" << std::endl;std::cout << "running time of C++ is " << duration << std::endl;std::cout << "Final optimal value is: " << optValue << std::endl;const auto optQ = model.getOptAction(initialState);std::cout << "Optimal Q is: " << optQ << std::endl;// auto table = model.getTable();return 0;
}
Java 代码
import java.util.*;
import java.util.concurrent.ConcurrentHashMap;
import java.util.concurrent.ConcurrentSkipListMap;
import java.util.function.Function;
import java.util.stream.DoubleStream;
import java.util.stream.IntStream;public class CLSP {double[][][] pmf;public CLSP(double[][][] pmf) {this.pmf = pmf;}class State {int period;double initialInventory;public State(int period, double initialInventory) {this.period = period;this.initialInventory = initialInventory;}public double[] getFeasibleActions() {return actionGenerator.apply(this);}@Overridepublic int hashCode() {String hash = "";hash = hash + period + initialInventory;return hash.hashCode();}@Overridepublic boolean equals(Object o) {if (o instanceof State)return ((State) o).period == this.period &&((State) o).initialInventory == this.initialInventory;elsereturn false;}@Overridepublic String toString() {return "period = " + period + ", " + "initialInventory = " + initialInventory;}}Function<State, double[]> actionGenerator;interface StateTransitionFunction<S, A, R, S2> {public S2 apply(S s, A a, R r);}StateTransitionFunction<State, Double, Double, State> stateTransition;interface ImmediateValueFunction<S, A, R, V> {public V apply(S s, A a, R r);}ImmediateValueFunction<State, Double, Double, Double> immediateValue;Comparator<State> keyComparator = (o1, o2) -> o1.period > o2.period ? 1 :o1.period == o2.period ? Double.compare(o1.initialInventory, o2.initialInventory) : -1;//ConcurrentSkipListMap<State, Double> cacheActions = new ConcurrentSkipListMap<>(keyComparator);ConcurrentSkipListMap<State, Double> cacheValues = new ConcurrentSkipListMap<>(keyComparator);double f(State state) {return cacheValues.computeIfAbsent(state, s -> {
// double val = Arrays.stream(s.getFeasibleActions())
// .map(orderQty -> Arrays.stream(pmf[s.period - 1])
// .mapToDouble(p -> p[1] * immediateValue.apply(s, orderQty, p[0]) +
// (s.period < pmf.length ?
// p[1] * f(stateTransition.apply(s, orderQty, p[0])) : 0))
// .sum())
// .min()
// .getAsDouble();
// double bestOrderQty = Arrays.stream(s.getFeasibleActions())
// .filter(orderQty -> Arrays.stream(pmf[s.period - 1])
// .mapToDouble(p -> p[1] * immediateValue.apply(s, orderQty, p[0]) +
// (s.period < pmf.length ?
// p[1] * f(stateTransition.apply(s, orderQty, p[0])) : 0))
// .sum() == val)
// .findAny()
// .getAsDouble();
// cacheActions.putIfAbsent(s, bestOrderQty);
// return val;
// });
// }double[] feasibleActions = state.getFeasibleActions();double[][] dAndP = pmf[state.period - 1]; // demandAndPossibilitydouble[] QValues = new double[feasibleActions.length];double val = Double.MAX_VALUE;double bestOrderQty = 0;for (int i = 0; i < feasibleActions.length; i++) {double orderQty = feasibleActions[i];double thisQValue = 0;for (int j = 0; j < dAndP.length; j++) {thisQValue += dAndP[j][1] * immediateValue.apply(state, orderQty, dAndP[j][0]);if (state.period < pmf.length) {State newState = stateTransition.apply(state, orderQty, dAndP[j][0]);thisQValue += dAndP[j][1] * f(newState);}}QValues[i] = thisQValue;if (QValues[i] < val) {val = QValues[i];bestOrderQty = orderQty;}}this.cacheActions.putIfAbsent(state, bestOrderQty);
// cacheValues.put(state, val);return val;});}public static void main(String[] args) {double initialInventory = 0;double[] meanDemand = new double[30];Arrays.fill(meanDemand, 20);double truncationQuantile = 0.9999;double stepSize = 1;double minState = -150;double maxState = 300;int T = meanDemand.length;double fixedOrderingCost = 0;double proportionalOrderingCost = 1;double holdingCost = 2;double penaltyCost = 10;int maxOrderQuantity = 100;Distribution[] distributions = IntStream.iterate(0, i -> i + 1).limit(T).mapToObj(i -> new PoissonDist(meanDemand[i]))
// .mapToObj(i -> new UniformDist(0, meanDemand[i]))//.mapToObj(i -> new NormalDist(meanDemand[i], 0.25 * meanDemand[i])).toArray(Distribution[]::new); // replace for loopdouble[] supportLB = IntStream.iterate(0, i -> i + 1).limit(T).mapToDouble(i -> distributions[i].inverseF(1 - truncationQuantile)).toArray();double[] supportUB = IntStream.iterate(0, i -> i + 1).limit(T).mapToDouble(i -> distributions[i].inverseF(truncationQuantile)).toArray();double[][][] pmf = new double[T][][];for (int i = 0; i < T; i++) {int demandLength = (int) ((supportUB[i] - supportLB[i] + 1) / stepSize);pmf[i] = new double[demandLength][];// demand values are all integersfor (int j = 0; j < demandLength; j++) {pmf[i][j] = new double[2];pmf[i][j][0] = supportLB[i] + j * stepSize;int demand = (int) pmf[i][j][0];if (distributions[0] instanceof DiscreteDistribution) {// double probabilitySum = distributions[i].cdf(supportUB[i]) - distributions[i].cdf(supportLB[i]);double probabilitySum = 2 * truncationQuantile - 1;pmf[i][j][1] = ((DiscreteDistribution) distributions[i]).prob(demand) / probabilitySum;} else {double probabilitySum = distributions[i].cdf(supportUB[i] + 0.5 * stepSize)- distributions[i].cdf(supportLB[i] - 0.5 * stepSize);pmf[i][j][1] = (distributions[i].cdf(pmf[i][j][0] + 0.5 * stepSize)- distributions[i].cdf(pmf[i][j][0] - 0.5 * stepSize)) / probabilitySum;}}}CLSP inventory = new CLSP(pmf);inventory.actionGenerator = s -> {return DoubleStream.iterate(0, i -> i + stepSize).limit(maxOrderQuantity + 1).toArray();};inventory.stateTransition = (state, action, randomDemand) -> {double nextInventory = state.initialInventory + action - randomDemand;nextInventory = nextInventory > maxState ? maxState : nextInventory;nextInventory = nextInventory < minState ? minState : nextInventory;return inventory.new State(state.period + 1, nextInventory);};inventory.immediateValue = (state, action, randomDemand) ->{double fixedCost = action > 0 ? fixedOrderingCost : 0;double variableCost = proportionalOrderingCost * action;double inventoryLevel = state.initialInventory + action - randomDemand;double holdingCosts = holdingCost * Math.max(inventoryLevel, 0);double penaltyCosts = penaltyCost * Math.max(-inventoryLevel, 0);double totalCosts = fixedCost + variableCost + holdingCosts + penaltyCosts;return totalCosts;};int period = 1;State initialState = inventory.new State(period, initialInventory);long currTime2 = System.currentTimeMillis();double finalValue = inventory.f(initialState);double time = (System.currentTimeMillis() - currTime2) / 1000.000;System.out.println("planning horizon is " + meanDemand.length + " periods");System.out.println("running time of Java is " + time + " s");System.out.println("final optimal expected value is: " + finalValue);double optQ = inventory.cacheActions.get(inventory.new State(period, initialInventory));System.out.println("optimal order quantity in the first priod is : " + optQ);}
}相关文章:
动态规划多阶段报童模型,c++ 实现, java 实现
借助 chaptgpt 和 deepseek,成功实现了c上的多阶段报童模型的动态规划。花费了几天,将以前的 java 程序用 c 实现。 文章目录 C 代码Java 代码 总结: c 还是比 java 快点,30个阶段快了零点几秒c 使用了 unordered_map ࿰…...
hivePB级迁移方案
1、评估磁盘空间大小、调整副本数、设置heapsize大小 2、distcp -i -skipcrccheck 源端到目标端,迁移 3、元数据迁移,建表,替换location地址,或者导出db 4、表分区修复 5、配置增量T-1迁移或者T-2 6、校验历史分区脚本&#…...
Transformer 代码剖析2 - 模型训练 (pytorch实现)
一、模型初始化模块 参考:项目代码 1.1 参数统计函数 def count_parameters(model):return sum(p.numel() for p in model.parameters() if p.requires_grad)#mermaid-svg-OL9twT8AmPz3Bp0O {font-family:"trebuchet ms",verdana,arial,sans-serif;fon…...
PE文件结构详解(DOS头/NT头/节表/导入表)使用010 Editor手动解析notepad++.exe的PE结构
一:DOS部分 DOS部分分为DOS MZ文件头和DOS块,其中DOS MZ头实际是一个64位的IMAGE_DOS——HEADER结构体。 DOS MZ头部结构体的内容如下,我们所需要关注的是前面两个字节(e_magic)和后面四个字节(e_lfanew&a…...
[含文档+PPT+源码等]精品基于Python实现的vue3+Django计算机课程资源平台
基于Python实现的Vue3Django计算机课程资源平台的背景,可以从以下几个方面进行阐述: 一、教育行业发展背景 1. 教育资源数字化趋势 随着信息技术的快速发展,教育资源的数字化已成为不可逆转的趋势。计算机课程资源作为教育领域的重要组成部…...
vue3中ref和reactive响应式数据、ref模板引用(组合式和选项式区别)、组件ref的使用
目录 Ⅰ.ref 1.基本用法:ref响应式数据 2.ref模板引用 3.ref在v-for中的模板引用 4.ref在组件上使用 5.TS中ref数据标注类型 Ⅱ.reactive 1.基本用法:reactive响应式数据 2.TS中reactive标注类型 Ⅲ.ref和reactive的使用场景和区别 Ⅳ.小结…...
Oracle VM VirtualBox 7.1 安装与虚拟机创建全流程指南(Windows平台)
一、软件定位与核心功能 Oracle VM VirtualBox 是开源跨平台虚拟化工具,支持在 Windows、Linux、macOS 系统上创建和管理虚拟机(VM),其核心功能包括: 多系统兼容:可安装 Windows、Ubuntu、CentOS 等 50 操…...
细说 Java GC 垃圾收集器
一、GC目标 业务角度,我们需要追求2个指标: 低延迟(Latency):请求必须多少毫秒内完成响应;高吞吐(Throughput):每秒完成多少次事务。 两者通常存在权衡关系࿰…...
云原生网络篇——万级节点服务网格与智能流量治理
引言:网络即神经系统 2023年双十一期间,某电商平台的支付网关因瞬时流量激增导致服务网格控制面崩溃,造成2.7亿元交易失败。而另一家跨国流媒体公司通过智能流量治理系统,在跨三大洲的云环境中实现了200万QPS的稳定传输。这两个案…...
请解释 React 中的 Hooks,何时使用 Hooks 更合适?
一、Hooks 核心理解 1. 什么是 Hooks? Hooks 是 React 16.8 引入的函数式编程范式,允许在函数组件中使用状态管理和生命周期能力。就像给函数组件装上了"智能芯片",让原本只能做简单展示的组件具备了处理复杂逻辑的能力。 2. 类…...
《国密算法开发实战:从合规落地到性能优化》
前言 随着信息技术的飞速发展,信息安全已成为全球关注的焦点。在数字化时代,数据的保密性、完整性和可用性直接关系到国家、企业和个人的利益。为了保障信息安全,密码技术作为核心支撑,发挥着至关重要的作用。国密算法,即国家密码算法,是我国自主设计和推广的一系列密码…...
第2章 windows故障排除(网络安全防御实战--蓝军武器库)
网络安全防御实战--蓝军武器库是2020年出版的,已经过去3年时间了,最近利用闲暇时间,抓紧吸收,总的来说,第2章开始带你入门了,这里给出了几个windows重要的工具,说实话,好多我也是第一…...
DifyでOracle Base Database Service(23ai)を利用する設定手順
[TOC](DifyでOracle Base Database Service(23ai)を利用する設定手順) はじめに 本記事では、DifyプラットフォームとOracle Base Database Service(23aiエディション)を連携させる方法を解説します。クラウド環境における大規模データ処理を想定した設…...
量子关联特性的多维度探索:五量子比特星型系统与两量子比特系统的对比分析
模拟一个五量子比特系统,其中四个量子比特(编号为1, 2, 3, 4)分别与第五个量子比特(编号为5)耦合,形成一个星型结构。分析量子比特1和2的纠缠熵随时间的变化。 系统的哈密顿量H描述了量子比特间的相互作用…...
初识C语言之操作符详解(上)
一.操作符分类 1.算数操作符: - * / % 2.移位操作符:<< >> 3.位操作符:& | ʌ 4.赋值操作符: - * / % << >> & | ʌ 5.单目操作符࿱…...
HarmonyOS学习第12天:解锁表格布局的奥秘
表格布局初相识 不知不觉,我们在 HarmonyOS 的学习旅程中已经走到了第 12 天。在之前的学习里,我们逐步掌握了 HarmonyOS 开发的各种基础与核心技能,比如组件的基本使用、布局的初步搭建等,这些知识就像一块块基石,为我…...
【心得】一文梳理高频面试题 HTTP 1.0/HTTP 1.1/HTTP 2.0/HTTP 3.0的区别并附加记忆方法
面试时很容易遇到的一个问题—— HTTP 1.0/HTTP 1.1/HTTP 2.0/HTTP 3.0的区别,其实这四个版本的发展实际上是一环扣一环的,是逐步完善的,本文希望帮助读者梳理清楚各个版本之间的区别,并且给出当前各个版本的应用情况,…...
《Python实战进阶》No 11:微服务架构设计与 Python 实现
第11集:微服务架构设计与 Python 实现 2025年3月3日更新了代码和微服务运行后的系统返回信息截图,所有代码在 python3.11.5虚拟环境下运行通过。 微服务架构通过将复杂应用拆分为独立部署的小型服务,显著提升了系统的可扩展性和维护性。本集…...
电商平台项目需求文档(精简版)
以下是电商平台项目需求文档样例(精简版),包含核心功能模块和技术实现要求: 电商平台项目需求文档 一、项目概述 项目名称:ECP-全栈电商平台(ECP - E-Commerce Platform) 技术定位:…...
Android15 Camera HAL Android.bp中引用Android.mk编译的libB.so
背景描述 Android15 Camera HAL使用Android.bp脚本来构建系统。假设Camera HAL中引用了另外一个HAL实现的so (例如VPU HAL), 恰巧被引用的这个VPU HAL so是用Android.mk构建的,那Camera HAL Android.bp在直接引用这个Android.mk编…...
P8720 [蓝桥杯 2020 省 B2] 平面切分--set、pair
P8720 [蓝桥杯 2020 省 B2] 平面切分--set、pair 题目 分析一、pair1.1pair与vector的区别1.2 两者使用场景两者组合使用 二、set2.1核心特点2.2set的基本操作2.3 set vs unordered_set示例:统计唯一单词数代码 题目 分析 大佬写的很明白,看这儿 我讲讲…...
postgresql源码学习(60)—— VFD的作用及机制
首先VFD是Virtual File Descriptor,即虚拟文件描述符,既然是虚拟的,一定先有物理的。 一、 物理文件描述符(File Descriptor, FD) 1. 什么是 FD 它是操作系统提供给用户程序访问和操作文件或其他 I/O 资源的抽象接口…...
【CSS—前端快速入门】CSS 选择器
CSS 1. CSS介绍 1.1 什么是CSS? CSS(Cascading Style Sheet),层叠样式表,用于控制页面的样式; CSS 能够对网页中元素位置的排版进行像素级精确控制,实现美化页面的效果;能够做到页面的样式和 结构分离; 1…...
Linux安装jdk,node,mysql,redis
准备工作: 1.安装VMware软件,下载CentOs7镜像文件,在VMware安装CentOs7 2.宿主机安装Xshell用来操作linux 3. .宿主机安装Xftp用来在宿主机和虚拟机的linux传输文件 案例1:在 /home/soft文件夹解压缩jdk17,并配置环…...
深度求索(DeepSeek)的AI革命:NLP、CV与智能应用的技术跃迁
Deepseek官网:DeepSeek 引言:AI技术浪潮中的深度求索 近年来,人工智能技术以指数级速度重塑全球产业格局。在这场技术革命中,深度求索(DeepSeek)凭借其前沿的算法研究、高效的工程化能力以及对垂直场景的…...
Minio搭建并在SpringBoot中使用完成用户头像的上传
Minio使用搭建并上传用户头像到服务器操作,学习笔记 Minio介绍 minio官网 MinIO是一个开源的分布式对象存储服务器,支持S3协议并且可以在多节点上实现数据的高可用和容错。它采用Go语言开发,拥有轻量级、高性能、易部署等特点,并且可以自由…...
【鸿蒙Next】 测试包 签名、打包、安装 整体过程记录
签名打包记录: HarmonyOS应用签名、打Hap包、Hap调试包真机安装步骤 https://blog.csdn.net/qq_34462735/article/details/135226332 测试包真机安装方式二 DevEco Testing 鸿蒙应用示例:DevEco Testing 工具的常用功能及使用场景 https://blog.csd…...
阿里云 | 快速在网站上增加一个AI助手
创建智能体应用 如上所示,登录阿里云百炼人工智能业务控制台,创建智能体应用,智能体应用是一个agent,即提供个人或者企业的代理或中间件组件应用,对接阿里云大模型公共平台,为个人或者企业用户提供大模型应…...
Raspberry Pi边缘计算网关设计与LoRa通信实现
Raspberry Pi边缘计算网关设计与LoRa通信实现 摘要第一章 绪论1.1 研究背景1.2 研究现状1.3 论文结构 第二章 相关技术理论2.1 边缘计算体系架构2.2 LoRa通信技术2.3 Raspberry Pi硬件生态 第三章 系统架构设计3.1 硬件架构设计3.2 软件架构设计3.3 混合通信协议设计 第四章 硬…...
原型链与继承
#搞懂还是得自己动手# 原型链 function Person(name) { this.name name; } Person.prototype.sayName function() { console.log(this.name); };const p new Person("Alice"); 原型链关系图: 原型链:person->Person.prototype->O…...
