动态规划多阶段报童模型,c++ 实现, java 实现

news2025/4/19 13:43:37

借助 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, {} 值初始化,默认为 0
    double 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 hash
    bool operator==(const State &other) const {
        // 需要定义 `==`
        // const MyClass &other	保证 other 参数不可修改
        // const 在函数结尾 保证当前对象(this) 不可修改
        // 不会修改成员变量的方法 都可以在函数声明的结尾添加 const
        return period == other.period && initialInventory == other.initialInventory;
    }

    // 允许哈希结构体访问私有成员
    // friend struct
    friend struct std::hash<State>;

    // define operator < or give a self defined comparator for sorting map
    bool 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 vector

void 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 here
                    thisValue += 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 quantity
    constexpr 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 distribution
    constexpr double maxI = 500; // maximum possible inventory
    constexpr double minI = -300; // minimum possible inventory


    const 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);
        }

        @Override
        public int hashCode() {
            String hash = "";
            hash = hash + period + initialInventory;
            return hash.hashCode();
        }

        @Override
        public boolean equals(Object o) {
            if (o instanceof State)
                return ((State) o).period == this.period &&
                        ((State) o).initialInventory == this.initialInventory;
            else
                return false;
        }

        @Override
        public 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]; // demandAndPossibility
            double[] 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 loop
        double[] 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 integers
            for (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);

    }
}

本文来自互联网用户投稿,该文观点仅代表作者本人,不代表本站立场。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如若转载,请注明出处:http://www.coloradmin.cn/o/2309171.html

如若内容造成侵权/违法违规/事实不符,请联系多彩编程网进行投诉反馈,一经查实,立即删除!

相关文章

PE文件结构详解(DOS头/NT头/节表/导入表)使用010 Editor手动解析notepad++.exe的PE结构

一&#xff1a;DOS部分 DOS部分分为DOS MZ文件头和DOS块&#xff0c;其中DOS MZ头实际是一个64位的IMAGE_DOS——HEADER结构体。 DOS MZ头部结构体的内容如下&#xff0c;我们所需要关注的是前面两个字节&#xff08;e_magic&#xff09;和后面四个字节&#xff08;e_lfanew&a…

[含文档+PPT+源码等]精品基于Python实现的vue3+Django计算机课程资源平台

基于Python实现的Vue3Django计算机课程资源平台的背景&#xff0c;可以从以下几个方面进行阐述&#xff1a; 一、教育行业发展背景 1. 教育资源数字化趋势 随着信息技术的快速发展&#xff0c;教育资源的数字化已成为不可逆转的趋势。计算机课程资源作为教育领域的重要组成部…

vue3中ref和reactive响应式数据、ref模板引用(组合式和选项式区别)、组件ref的使用

目录 Ⅰ.ref 1.基本用法&#xff1a;ref响应式数据 2.ref模板引用 3.ref在v-for中的模板引用 ​4.ref在组件上使用 ​5.TS中ref数据标注类型 Ⅱ.reactive 1.基本用法&#xff1a;reactive响应式数据 2.TS中reactive标注类型 Ⅲ.ref和reactive的使用场景和区别 Ⅳ.小结…

Oracle VM VirtualBox 7.1 安装与虚拟机创建全流程指南(Windows平台)

一、软件定位与核心功能 Oracle VM VirtualBox 是开源跨平台虚拟化工具&#xff0c;支持在 Windows、Linux、macOS 系统上创建和管理虚拟机&#xff08;VM&#xff09;&#xff0c;其核心功能包括&#xff1a; 多系统兼容&#xff1a;可安装 Windows、Ubuntu、CentOS 等 50 操…

细说 Java GC 垃圾收集器

一、GC目标 业务角度&#xff0c;我们需要追求2个指标&#xff1a; 低延迟&#xff08;Latency&#xff09;&#xff1a;请求必须多少毫秒内完成响应&#xff1b;高吞吐&#xff08;Throughput&#xff09;&#xff1a;每秒完成多少次事务。 两者通常存在权衡关系&#xff0…

第2章 windows故障排除(网络安全防御实战--蓝军武器库)

网络安全防御实战--蓝军武器库是2020年出版的&#xff0c;已经过去3年时间了&#xff0c;最近利用闲暇时间&#xff0c;抓紧吸收&#xff0c;总的来说&#xff0c;第2章开始带你入门了&#xff0c;这里给出了几个windows重要的工具&#xff0c;说实话&#xff0c;好多我也是第一…

量子关联特性的多维度探索:五量子比特星型系统与两量子比特系统的对比分析

模拟一个五量子比特系统&#xff0c;其中四个量子比特&#xff08;编号为1, 2, 3, 4&#xff09;分别与第五个量子比特&#xff08;编号为5&#xff09;耦合&#xff0c;形成一个星型结构。分析量子比特1和2的纠缠熵随时间的变化。 系统的哈密顿量H描述了量子比特间的相互作用…

HarmonyOS学习第12天:解锁表格布局的奥秘

表格布局初相识 不知不觉&#xff0c;我们在 HarmonyOS 的学习旅程中已经走到了第 12 天。在之前的学习里&#xff0c;我们逐步掌握了 HarmonyOS 开发的各种基础与核心技能&#xff0c;比如组件的基本使用、布局的初步搭建等&#xff0c;这些知识就像一块块基石&#xff0c;为我…

《Python实战进阶》No 11:微服务架构设计与 Python 实现

第11集&#xff1a;微服务架构设计与 Python 实现 2025年3月3日更新了代码和微服务运行后的系统返回信息截图&#xff0c;所有代码在 python3.11.5虚拟环境下运行通过。 微服务架构通过将复杂应用拆分为独立部署的小型服务&#xff0c;显著提升了系统的可扩展性和维护性。本集…

Android15 Camera HAL Android.bp中引用Android.mk编译的libB.so

背景描述 Android15 Camera HAL使用Android.bp脚本来构建系统。假设Camera HAL中引用了另外一个HAL实现的so &#xff08;例如VPU HAL&#xff09;&#xff0c; 恰巧被引用的这个VPU HAL so是用Android.mk构建的&#xff0c;那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示例&#xff1a;统计唯一单词数代码 题目 分析 大佬写的很明白&#xff0c;看这儿 我讲讲…

postgresql源码学习(60)—— VFD的作用及机制

首先VFD是Virtual File Descriptor&#xff0c;即虚拟文件描述符&#xff0c;既然是虚拟的&#xff0c;一定先有物理的。 一、 物理文件描述符&#xff08;File Descriptor, FD&#xff09; 1. 什么是 FD 它是操作系统提供给用户程序访问和操作文件或其他 I/O 资源的抽象接口…

【CSS—前端快速入门】CSS 选择器

CSS 1. CSS介绍 1.1 什么是CSS? CSS(Cascading Style Sheet)&#xff0c;层叠样式表&#xff0c;用于控制页面的样式&#xff1b; CSS 能够对网页中元素位置的排版进行像素级精确控制&#xff0c;实现美化页面的效果&#xff1b;能够做到页面的样式和 结构分离&#xff1b; 1…

Linux安装jdk,node,mysql,redis

准备工作&#xff1a; 1.安装VMware软件&#xff0c;下载CentOs7镜像文件&#xff0c;在VMware安装CentOs7 2.宿主机安装Xshell用来操作linux 3. .宿主机安装Xftp用来在宿主机和虚拟机的linux传输文件 案例1&#xff1a;在 /home/soft文件夹解压缩jdk17&#xff0c;并配置环…

深度求索(DeepSeek)的AI革命:NLP、CV与智能应用的技术跃迁

Deepseek官网&#xff1a;DeepSeek 引言&#xff1a;AI技术浪潮中的深度求索 近年来&#xff0c;人工智能技术以指数级速度重塑全球产业格局。在这场技术革命中&#xff0c;深度求索&#xff08;DeepSeek&#xff09;凭借其前沿的算法研究、高效的工程化能力以及对垂直场景的…

Minio搭建并在SpringBoot中使用完成用户头像的上传

Minio使用搭建并上传用户头像到服务器操作,学习笔记 Minio介绍 minio官网 MinIO是一个开源的分布式对象存储服务器&#xff0c;支持S3协议并且可以在多节点上实现数据的高可用和容错。它采用Go语言开发&#xff0c;拥有轻量级、高性能、易部署等特点&#xff0c;并且可以自由…

阿里云 | 快速在网站上增加一个AI助手

创建智能体应用 如上所示&#xff0c;登录阿里云百炼人工智能业务控制台&#xff0c;创建智能体应用&#xff0c;智能体应用是一个agent&#xff0c;即提供个人或者企业的代理或中间件组件应用&#xff0c;对接阿里云大模型公共平台&#xff0c;为个人或者企业用户提供大模型应…

原型链与继承

#搞懂还是得自己动手# 原型链 function Person(name) { this.name name; } Person.prototype.sayName function() { console.log(this.name); };const p new Person("Alice"); 原型链关系图&#xff1a; 原型链&#xff1a;person->Person.prototype->O…

动态规划 ─── 算法5

动态规划&#xff08;Dynamic Programming&#xff0c;简称 DP&#xff09;是一种用于解决复杂问题的算法设计技术&#xff0c;特别适用于具有重叠子问题和最优子结构性质的问题。动态规划通过将问题分解为更小的子问题&#xff0c;并存储子问题的解来避免重复计算&#xff0c;…

博客系统--测试报告

博客系统--测试报告 项目背景项目功能功能测试①登录功能测试②发布博客功能测试③删除文章功能测试④功能测试总结&#xff1a; 自动化测试自动化脚本执行界面&#xff1a; 性能测试 本博文主要针对个人实现的项目《博客系统》去进行功能测试、自动化测试、性能测试&#xff0…