项目结构:

/**
* encoding: utf-8
* 版权所有 2026 ©涂聚文有限公司 ®
* 许可信息查看:言語成了邀功盡責的功臣,還需要行爲每日來值班嗎
* 描述:Iterative Algorithms
* Author : geovindu,Geovin Du 涂聚文.
* IDE : IntelliJ IDEA 2024.3.6 Java 17
* # database : Oracle21c,MySQL 9.0,SQL Server 2019,PostgreSQL 17.1 Neo4j
* # OS : window10
* Datetime : 2026 - 2026/7/25 - 19:10
* User : geovindu
* Product : IntelliJ IDEA
* Project : JavaAlgorithms
* File : Settings.java
* explain : 学习 类
**/
package Iterative.config;
public final class Settings {
private Settings() {}
public static final double DIAMOND_WEIGHT_CARAT = 0.5;
public static final double DIAMOND_WEIGHT_COLOR = 0.3;
public static final double DIAMOND_WEIGHT_CLARITY = 0.2;
public static final double PRICE_ITER_STEP = 0.01;
public static final double MIN_MARKUP_COEFF = 1.3;
public static final double MAX_MARKUP_COEFF = 2.2;
}
/**
* encoding: utf-8
* 版权所有 2026 ©涂聚文有限公司 ®
* 许可信息查看:言語成了邀功盡責的功臣,還需要行爲每日來值班嗎
* 描述:Iterative Algorithms
* Author : geovindu,Geovin Du 涂聚文.
* IDE : IntelliJ IDEA 2024.3.6 Java 17
* # database : Oracle21c,MySQL 9.0,SQL Server 2019,PostgreSQL 17.1 Neo4j
* # OS : window10
* Datetime : 2026 - 2026/7/25 - 19:46
* User : geovindu
* Product : IntelliJ IDEA
* Project : JavaAlgorithms
* File : Diamond.java
* explain : 学习 类
**/
package Iterative.model;
import Iterative.config.Settings;
import java.util.Map;
public class Diamond {
private String stoneId;
private double carat;
private String color;
private String clarity;
private double costPrice;
public double calcComprehensiveScore() {
Map<String, Double> colorMap = Map.of(
"D", 100.0,
"E", 96.0,
"F", 92.0,
"G", 88.0,
"H", 84.0,
"I", 78.0
);
Map<String, Double> clarityMap = Map.of(
"FL", 100.0,
"VVS1", 95.0,
"VVS2", 90.0,
"VS1", 85.0,
"VS2", 80.0,
"SI1", 70.0
);
double cScore = carat * 100;
double colScore = colorMap.getOrDefault(color, 60.0);
double claScore = clarityMap.getOrDefault(clarity, 60.0);
return cScore * Settings.DIAMOND_WEIGHT_CARAT
+ colScore * Settings.DIAMOND_WEIGHT_COLOR
+ claScore * Settings.DIAMOND_WEIGHT_CLARITY;
}
// getter & setter
public String getStoneId() { return stoneId; }
public void setStoneId(String stoneId) { this.stoneId = stoneId; }
public double getCarat() { return carat; }
public void setCarat(double carat) { this.carat = carat; }
public String getColor() { return color; }
public void setColor(String color) { this.color = color; }
public String getClarity() { return clarity; }
public void setClarity(String clarity) { this.clarity = clarity; }
public double getCostPrice() { return costPrice; }
public void setCostPrice(double costPrice) { this.costPrice = costPrice; }
}
/**
* encoding: utf-8
* 版权所有 2026 ©涂聚文有限公司 ®
* 许可信息查看:言語成了邀功盡責的功臣,還需要行爲每日來值班嗎
* 描述:Iterative Algorithms
* Author : geovindu,Geovin Du 涂聚文.
* IDE : IntelliJ IDEA 2024.3.6 Java 17
* # database : Oracle21c,MySQL 9.0,SQL Server 2019,PostgreSQL 17.1 Neo4j
* # OS : window10
* Datetime : 2026 - 2026/7/25 - 19:47
* User : geovindu
* Product : IntelliJ IDEA
* Project : JavaAlgorithms
* File : JadeBlank.java
* explain : 学习 类
**/
package Iterative.model;
public class JadeBlank {
private String blankId;
private double length;
private double width;
private double thick;
private double costPrice;
private double usableRate;
public String getBlankId() { return blankId; }
public void setBlankId(String blankId) { this.blankId = blankId; }
public double getLength() { return length; }
public void setLength(double length) { this.length = length; }
public double getWidth() { return width; }
public void setWidth(double width) { this.width = width; }
public double getThick() { return thick; }
public void setThick(double thick) { this.thick = thick; }
public double getCostPrice() { return costPrice; }
public void setCostPrice(double costPrice) { this.costPrice = costPrice; }
public double getUsableRate() { return usableRate; }
public void setUsableRate(double usableRate) { this.usableRate = usableRate; }
}
/**
* encoding: utf-8
* 版权所有 2026 ©涂聚文有限公司 ®
* 许可信息查看:言語成了邀功盡責的功臣,還需要行爲每日來值班嗎
* 描述:Iterative Algorithms
* Author : geovindu,Geovin Du 涂聚文.
* IDE : IntelliJ IDEA 2024.3.6 Java 17
* # database : Oracle21c,MySQL 9.0,SQL Server 2019,PostgreSQL 17.1 Neo4j
* # OS : window10
* Datetime : 2026 - 2026/7/25 - 19:47
* User : geovindu
* Product : IntelliJ IDEA
* Project : JavaAlgorithms
* File : Product.java
* explain : 学习 类
**/
package Iterative.model;
public class Product {
private String productId;
private String name;
private double cost;
public String getProductId() { return productId; }
public void setProductId(String productId) { this.productId = productId; }
public String getName() { return name; }
public void setName(String name) { this.name = name; }
public double getCost() { return cost; }
public void setCost(double cost) { this.cost = cost; }
}
/**
* encoding: utf-8
* 版权所有 2026 ©涂聚文有限公司 ®
* 许可信息查看:言語成了邀功盡責的功臣,還需要行爲每日來值班嗎
* 描述:Iterative Algorithms
* Author : geovindu,Geovin Du 涂聚文.
* IDE : IntelliJ IDEA 2024.3.6 Java 17
* # database : Oracle21c,MySQL 9.0,SQL Server 2019,PostgreSQL 17.1 Neo4j
* # OS : window10
* Datetime : 2026 - 2026/7/25 - 19:47
* User : geovindu
* Product : IntelliJ IDEA
* Project : JavaAlgorithms
* File : RingMount.java
* explain : 学习 类
**/
package Iterative.model;
public class RingMount {
private String mountId;
private String material;
private double costPrice;
public String getMountId() { return mountId; }
public void setMountId(String mountId) { this.mountId = mountId; }
public String getMaterial() { return material; }
public void setMaterial(String material) { this.material = material; }
public double getCostPrice() { return costPrice; }
public void setCostPrice(double costPrice) { this.costPrice = costPrice; }
}
/**
* encoding: utf-8
* 版权所有 2026 ©涂聚文有限公司 ®
* 许可信息查看:言語成了邀功盡責的功臣,還需要行爲每日來值班嗎
* 描述:Iterative Algorithms
* Author : geovindu,Geovin Du 涂聚文.
* IDE : IntelliJ IDEA 2024.3.6 Java 17
* # database : Oracle21c,MySQL 9.0,SQL Server 2019,PostgreSQL 17.1 Neo4j
* # OS : window10
* Datetime : 2026 - 2026/7/25 - 19:52
* User : geovindu
* Product : IntelliJ IDEA
* Project : JavaAlgorithms
* File : BaseRepository.java
* explain : 学习 类
**/
package Iterative.repository;
import java.util.List;
public interface BaseRepository<T> {
List<T> listAll();
}
/**
* encoding: utf-8
* 版权所有 2026 ©涂聚文有限公司 ®
* 许可信息查看:言語成了邀功盡責的功臣,還需要行爲每日來值班嗎
* 描述:Iterative Algorithms
* Author : geovindu,Geovin Du 涂聚文.
* IDE : IntelliJ IDEA 2024.3.6 Java 17
* # database : Oracle21c,MySQL 9.0,SQL Server 2019,PostgreSQL 17.1 Neo4j
* # OS : window10
* Datetime : 2026 - 2026/7/25 - 19:53
* User : geovindu
* Product : IntelliJ IDEA
* Project : JavaAlgorithms
* File : DiamondRepository.java
* explain : 学习 类
**/
package Iterative.repository;
import Iterative.model.Diamond;
import java.util.List;
public class DiamondRepository implements BaseRepository<Diamond> {
private final List<Diamond> storage;
public DiamondRepository() {
Diamond d1 = new Diamond();
d1.setStoneId("D001");
d1.setCarat(0.52);
d1.setColor("H");
d1.setClarity("VS1");
d1.setCostPrice(24800);
Diamond d2 = new Diamond();
d2.setStoneId("D002");
d2.setCarat(0.48);
d2.setColor("G");
d2.setClarity("VS2");
d2.setCostPrice(22100);
Diamond d3 = new Diamond();
d3.setStoneId("D003");
d3.setCarat(0.55);
d3.setColor("I");
d3.setClarity("SI1");
d3.setCostPrice(21300);
storage = List.of(d1, d2, d3);
}
@Override
public List<Diamond> listAll() {
return List.copyOf(storage);
}
}
/**
* encoding: utf-8
* 版权所有 2026 ©涂聚文有限公司 ®
* 许可信息查看:言語成了邀功盡責的功臣,還需要行爲每日來值班嗎
* 描述:Iterative Algorithms
* Author : geovindu,Geovin Du 涂聚文.
* IDE : IntelliJ IDEA 2024.3.6 Java 17
* # database : Oracle21c,MySQL 9.0,SQL Server 2019,PostgreSQL 17.1 Neo4j
* # OS : window10
* Datetime : 2026 - 2026/7/25 - 19:54
* User : geovindu
* Product : IntelliJ IDEA
* Project : JavaAlgorithms
* File : JadeRepository.java
* explain : 学习 类
**/
package Iterative.repository;
import Iterative.model.JadeBlank;
import java.util.List;
public class JadeRepository implements BaseRepository<JadeBlank> {
private final List<JadeBlank> storage;
public JadeRepository() {
JadeBlank j1 = new JadeBlank();
j1.setBlankId("J001");
j1.setLength(32.5);
j1.setWidth(21.2);
j1.setThick(7.3);
j1.setCostPrice(6800);
j1.setUsableRate(0.86);
JadeBlank j2 = new JadeBlank();
j2.setBlankId("J002");
j2.setLength(30.1);
j2.setWidth(19.8);
j2.setThick(6.9);
j2.setCostPrice(6200);
j2.setUsableRate(0.91);
JadeBlank j3 = new JadeBlank();
j3.setBlankId("J003");
j3.setLength(36.0);
j3.setWidth(24.1);
j3.setThick(8.2);
j3.setCostPrice(7500);
j3.setUsableRate(0.79);
storage = List.of(j1, j2, j3);
}
@Override
public List<JadeBlank> listAll() {
return List.copyOf(storage);
}
}
/**
* encoding: utf-8
* 版权所有 2026 ©涂聚文有限公司 ®
* 许可信息查看:言語成了邀功盡責的功臣,還需要行爲每日來值班嗎
* 描述:Iterative Algorithms
* Author : geovindu,Geovin Du 涂聚文.
* IDE : IntelliJ IDEA 2024.3.6 Java 17
* # database : Oracle21c,MySQL 9.0,SQL Server 2019,PostgreSQL 17.1 Neo4j
* # OS : window10
* Datetime : 2026 - 2026/7/25 - 19:53
* User : geovindu
* Product : IntelliJ IDEA
* Project : JavaAlgorithms
* File : RingMountRepository.java
* explain : 学习 类
**/
package Iterative.repository;
import Iterative.model.RingMount;
import java.util.List;
public class RingMountRepository implements BaseRepository<RingMount> {
private final List<RingMount> storage;
public RingMountRepository() {
RingMount m1 = new RingMount();
m1.setMountId("M001");
m1.setMaterial("18K");
m1.setCostPrice(4200);
RingMount m2 = new RingMount();
m2.setMountId("M002");
m2.setMaterial("铂金");
m2.setCostPrice(5600);
storage = List.of(m1, m2);
}
@Override
public List<RingMount> listAll() {
return List.copyOf(storage);
}
}
/**
* encoding: utf-8
* 版权所有 2026 ©涂聚文有限公司 ®
* 许可信息查看:言語成了邀功盡責的功臣,還需要行爲每日來值班嗎
* 描述:Iterative Algorithms
* Author : geovindu,Geovin Du 涂聚文.
* IDE : IntelliJ IDEA 2024.3.6 Java 17
* # database : Oracle21c,MySQL 9.0,SQL Server 2019,PostgreSQL 17.1 Neo4j
* # OS : window10
* Datetime : 2026 - 2026/7/25 - 19:48
* User : geovindu
* Product : IntelliJ IDEA
* Project : JavaAlgorithms
* File : DiamondRecommendRequest.java
* explain : 学习 类
**/
package Iterative.schema.request;
public record DiamondRecommendRequest(double budget, String material) {}
/**
* encoding: utf-8
* 版权所有 2026 ©涂聚文有限公司 ®
* 许可信息查看:言語成了邀功盡責的功臣,還需要行爲每日來值班嗎
* 描述:Iterative Algorithms
* Author : geovindu,Geovin Du 涂聚文.
* IDE : IntelliJ IDEA 2024.3.6 Java 17
* # database : Oracle21c,MySQL 9.0,SQL Server 2019,PostgreSQL 17.1 Neo4j
* # OS : window10
* Datetime : 2026 - 2026/7/25 - 19:48
* User : geovindu
* Product : IntelliJ IDEA
* Project : JavaAlgorithms
* File : JadeMatchRequest.java
* explain : 学习 类
**/
package Iterative.schema.request;
public record JadeMatchRequest(
double minL, double maxL,
double minW, double maxW,
double minT, double maxT,
double priceMin, double priceMax
) {}
/**
* encoding: utf-8
* 版权所有 2026 ©涂聚文有限公司 ®
* 许可信息查看:言語成了邀功盡責的功臣,還需要行爲每日來值班嗎
* 描述:Iterative Algorithms
* Author : geovindu,Geovin Du 涂聚文.
* IDE : IntelliJ IDEA 2024.3.6 Java 17
* # database : Oracle21c,MySQL 9.0,SQL Server 2019,PostgreSQL 17.1 Neo4j
* # OS : window10
* Datetime : 2026 - 2026/7/25 - 19:49
* User : geovindu
* Product : IntelliJ IDEA
* Project : JavaAlgorithms
* File : PriceOptRequest.java
* explain : 学习 类
**/
package Iterative.schema.request;
public record PriceOptRequest(double baseCost, double minCoeff, double maxCoeff, double step) {}
/**
* encoding: utf-8
* 版权所有 2026 ©涂聚文有限公司 ®
* 许可信息查看:言語成了邀功盡責的功臣,還需要行爲每日來值班嗎
* 描述:Iterative Algorithms
* Author : geovindu,Geovin Du 涂聚文.
* IDE : IntelliJ IDEA 2024.3.6 Java 17
* # database : Oracle21c,MySQL 9.0,SQL Server 2019,PostgreSQL 17.1 Neo4j
* # OS : window10
* Datetime : 2026 - 2026/7/25 - 19:49
* User : geovindu
* Product : IntelliJ IDEA
* Project : JavaAlgorithms
* File : DiamondComboResult.java
* explain : 学习 类
**/
package Iterative.schema.response;
import Iterative.model.Diamond;
import Iterative.model.RingMount;
public record DiamondComboResult(Diamond diamond, RingMount mount, double totalCost, double score) {}
/**
* encoding: utf-8
* 版权所有 2026 ©涂聚文有限公司 ®
* 许可信息查看:言語成了邀功盡責的功臣,還需要行爲每日來值班嗎
* 描述:Iterative Algorithms
* Author : geovindu,Geovin Du 涂聚文.
* IDE : IntelliJ IDEA 2024.3.6 Java 17
* # database : Oracle21c,MySQL 9.0,SQL Server 2019,PostgreSQL 17.1 Neo4j
* # OS : window10
* Datetime : 2026 - 2026/7/25 - 19:50
* User : geovindu
* Product : IntelliJ IDEA
* Project : JavaAlgorithms
* File : JadeMatchResult.java
* explain : 学习 类
**/
package Iterative.schema.response;
import Iterative.model.JadeBlank;
public class JadeMatchResult {
private final String blankId;
private final double length;
private final double width;
private final double thick;
private final double costPrice;
private final double usableRate;
public JadeMatchResult(JadeBlank blank) {
this.blankId = blank.getBlankId();
this.length = blank.getLength();
this.width = blank.getWidth();
this.thick = blank.getThick();
this.costPrice = blank.getCostPrice();
this.usableRate = blank.getUsableRate();
}
public String getBlankId() { return blankId; }
public double getLength() { return length; }
public double getWidth() { return width; }
public double getThick() { return thick; }
public double getCostPrice() { return costPrice; }
public double getUsableRate() { return usableRate; }
}
/**
* encoding: utf-8
* 版权所有 2026 ©涂聚文有限公司 ®
* 许可信息查看:言語成了邀功盡責的功臣,還需要行爲每日來值班嗎
* 描述:Iterative Algorithms
* Author : geovindu,Geovin Du 涂聚文.
* IDE : IntelliJ IDEA 2024.3.6 Java 17
* # database : Oracle21c,MySQL 9.0,SQL Server 2019,PostgreSQL 17.1 Neo4j
* # OS : window10
* Datetime : 2026 - 2026/7/25 - 19:50
* User : geovindu
* Product : IntelliJ IDEA
* Project : JavaAlgorithms
* File : PriceOptResult.java
* explain : 学习 类
**/
package Iterative.schema.response;
public record PriceOptResult(double bestCoeff, double bestSellPrice, double maxGrossProfit) {}
/**
* encoding: utf-8
* 版权所有 2026 ©涂聚文有限公司 ®
* 许可信息查看:言語成了邀功盡責的功臣,還需要行爲每日來值班嗎
* 描述:Iterative Algorithms
* Author : geovindu,Geovin Du 涂聚文.
* IDE : IntelliJ IDEA 2024.3.6 Java 17
* # database : Oracle21c,MySQL 9.0,SQL Server 2019,PostgreSQL 17.1 Neo4j
* # OS : window10
* Datetime : 2026 - 2026/7/25 - 19:54
* User : geovindu
* Product : IntelliJ IDEA
* Project : JavaAlgorithms
* File : DiamondRecommendService.java
* explain : 学习 类
**/
package Iterative.service;
import Iterative.model.Diamond;
import Iterative.model.RingMount;
import Iterative.repository.BaseRepository;
import Iterative.schema.request.DiamondRecommendRequest;
import Iterative.schema.response.DiamondComboResult;
import java.util.List;
public class DiamondRecommendService {
private final BaseRepository<Diamond> diamondRepo;
private final BaseRepository<RingMount> mountRepo;
public DiamondRecommendService(BaseRepository<Diamond> diamondRepo,
BaseRepository<RingMount> mountRepo) {
this.diamondRepo = diamondRepo;
this.mountRepo = mountRepo;
}
public DiamondComboResult findBestCombo(DiamondRecommendRequest req) {
List<Diamond> diamonds = diamondRepo.listAll();
List<RingMount> mounts = mountRepo.listAll();
DiamondComboResult best = null;
double bestScore = -1.0;
for (Diamond dia : diamonds) {
for (RingMount mount : mounts) {
if (!mount.getMaterial().equals(req.material())) {
continue;
}
double total = dia.getCostPrice() + mount.getCostPrice();
if (total > req.budget()) {
continue;
}
double score = dia.calcComprehensiveScore();
if (score > bestScore) {
bestScore = score;
best = new DiamondComboResult(dia, mount, total, score);
}
}
}
return best;
}
}
/**
* encoding: utf-8
* 版权所有 2026 ©涂聚文有限公司 ®
* 许可信息查看:言語成了邀功盡責的功臣,還需要行爲每日來值班嗎
* 描述:Iterative Algorithms
* Author : geovindu,Geovin Du 涂聚文.
* IDE : IntelliJ IDEA 2024.3.6 Java 17
* # database : Oracle21c,MySQL 9.0,SQL Server 2019,PostgreSQL 17.1 Neo4j
* # OS : window10
* Datetime : 2026 - 2026/7/25 - 20:24
* User : geovindu
* Product : IntelliJ IDEA
* Project : JavaAlgorithms
* File : JadeCustomService.java
* explain : 学习 类
**/
package Iterative.service;
import Iterative.algorithm.IterativeMatcher;
import Iterative.model.JadeBlank;
import Iterative.repository.BaseRepository;
import Iterative.schema.request.JadeMatchRequest;
import Iterative.schema.response.JadeMatchResult;
import java.util.List;
public class JadeCustomService {
private final BaseRepository<JadeBlank> jadeRepo;
private final IterativeMatcher matcher;
public JadeCustomService(BaseRepository<JadeBlank> jadeRepo) {
this.jadeRepo = jadeRepo;
this.matcher = new IterativeMatcher();
}
public JadeMatchResult matchOptimalBlank(JadeMatchRequest req) {
List<JadeBlank> blanks = jadeRepo.listAll();
JadeBlank best = matcher.findOptimal(
blanks,
item -> {
boolean condSize = req.minL() <= item.getLength() && item.getLength() <= req.maxL()
&& req.minW() <= item.getWidth() && item.getWidth() <= req.maxW()
&& req.minT() <= item.getThick() && item.getThick() <= req.maxT();
boolean condPrice = req.priceMin() <= item.getCostPrice() && item.getCostPrice() <= req.priceMax();
return condSize && condPrice;
},
JadeBlank::getUsableRate
);
return best == null ? null : new JadeMatchResult(best);
}
}
/**
* encoding: utf-8
* 版权所有 2026 ©涂聚文有限公司 ®
* 许可信息查看:言語成了邀功盡責的功臣,還需要行爲每日來值班嗎
* 描述:Iterative Algorithms
* Author : geovindu,Geovin Du 涂聚文.
* IDE : IntelliJ IDEA 2024.3.6 Java 17
* # database : Oracle21c,MySQL 9.0,SQL Server 2019,PostgreSQL 17.1 Neo4j
* # OS : window10
* Datetime : 2026 - 2026/7/25 - 20:37
* User : geovindu
* Product : IntelliJ IDEA
* Project : JavaAlgorithms
* File : ProductPricingService.java
* explain : 学习 类
**/
package Iterative.service;
import Iterative.algorithm.IterativeOptimizer;
import Iterative.config.Settings;
import Iterative.schema.request.PriceOptRequest;
import Iterative.schema.response.PriceOptResult;
public class ProductPricingService {
private final IterativeOptimizer optimizer;
public ProductPricingService() {
this.optimizer = new IterativeOptimizer();
}
public PriceOptResult calcOptimalPrice(PriceOptRequest req) {
double baseCost = req.baseCost();
IterativeOptimizer.Result res = optimizer.optimize(
req.minCoeff(),
req.maxCoeff(),
req.step(),
coeff -> {
double sellPrice = baseCost * coeff;
double volume = Math.max(0, 120 - sellPrice / 45);
return (sellPrice - baseCost) * volume;
}
);
double bestSellPrice = Math.round(baseCost * res.bestParam() * 100.0) / 100.0;
return new PriceOptResult(res.bestParam(), bestSellPrice, res.maxTarget());
}
}
/**
* encoding: utf-8
* 版权所有 2026 ©涂聚文有限公司 ®
* 许可信息查看:言語成了邀功盡責的功臣,還需要行爲每日來值班嗎
* 描述:Iterative Algorithms
* Author : geovindu,Geovin Du 涂聚文.
* IDE : IntelliJ IDEA 2024.3.6 Java 17
* # database : Oracle21c,MySQL 9.0,SQL Server 2019,PostgreSQL 17.1 Neo4j
* # OS : window10
* Datetime : 2026 - 2026/7/25 - 19:50
* User : geovindu
* Product : IntelliJ IDEA
* Project : JavaAlgorithms
* File : IterativeMatcher.java
* explain : 学习 类
**/
package Iterative.algorithm;
import java.util.List;
import java.util.function.Function;
import java.util.function.Predicate;
/**
* 通用迭代匹配器 Iterative Algorithms
*/
public class IterativeMatcher {
public <T> T findOptimal(List<T> candidates,
Predicate<T> filter,
Function<T, Double> scoreFunc) {
int bestIndex = -1;
double bestScore = -1e18;
for (int i = 0; i < candidates.size(); i++) {
T item = candidates.get(i);
if (!filter.test(item)) {
continue;
}
double s = scoreFunc.apply(item);
if (s > bestScore) {
bestScore = s;
bestIndex = i;
}
}
if (bestIndex < 0) {
return null;
}
return candidates.get(bestIndex);
}
}
/**
* encoding: utf-8
* 版权所有 2026 ©涂聚文有限公司 ®
* 许可信息查看:言語成了邀功盡責的功臣,還需要行爲每日來值班嗎
* 描述:Iterative Algorithms
* Author : geovindu,Geovin Du 涂聚文.
* IDE : IntelliJ IDEA 2024.3.6 Java 17
* # database : Oracle21c,MySQL 9.0,SQL Server 2019,PostgreSQL 17.1 Neo4j
* # OS : window10
* Datetime : 2026 - 2026/7/25 - 19:51
* User : geovindu
* Product : IntelliJ IDEA
* Project : JavaAlgorithms
* File : IterativeOptimizer.java
* explain : 学习 类
**/
package Iterative.algorithm;
import java.util.function.Function;
public class IterativeOptimizer {
public Result optimize(double start, double end, double step, Function<Double, Double> evalFunc) {
double bestParam = start;
double maxTarget = Double.NEGATIVE_INFINITY;
double current = start;
while (current <= end) {
double val = evalFunc.apply(current);
if (val > maxTarget) {
maxTarget = val;
bestParam = current;
}
current += step;
}
// 保留两位小数
bestParam = Math.round(bestParam * 100.0) / 100.0;
maxTarget = Math.round(maxTarget * 100.0) / 100.0;
return new Result(bestParam, maxTarget);
}
public record Result(double bestParam, double maxTarget) {}
}
调用;
/**
* encoding: utf-8
* 版权所有 2026 ©涂聚文有限公司 ®
* 许可信息查看:言語成了邀功盡責的功臣,還需要行爲每日來值班嗎
* 描述:Iterative Algorithms
* Author : geovindu,Geovin Du 涂聚文.
* IDE : IntelliJ IDEA 2024.3.6 Java 17
* # database : Oracle21c,MySQL 9.0,SQL Server 2019,PostgreSQL 17.1 Neo4j
* # OS : window10
* Datetime : 2026 - 2026/7/25 - 20:35
* User : geovindu
* Product : IntelliJ IDEA
* Project : JavaAlgorithms
* File : IterativeBll.java
* explain : 学习 类
**/
package Bll;
import Iterative.config.Settings;
import Iterative.repository.DiamondRepository;
import Iterative.repository.JadeRepository;
import Iterative.repository.RingMountRepository;
import Iterative.schema.request.DiamondRecommendRequest;
import Iterative.schema.request.JadeMatchRequest;
import Iterative.schema.request.PriceOptRequest;
import Iterative.service.DiamondRecommendService;
import Iterative.service.JadeCustomService;
import Iterative.service.ProductPricingService;
public class IterativeBll {
static void demoRecommend() {
var diaRepo = new DiamondRepository();
var mountRepo = new RingMountRepository();
var svc = new DiamondRecommendService(diaRepo, mountRepo);
var req = new DiamondRecommendRequest(30000, "18K");
var res = svc.findBestCombo(req);
if (res != null) {
System.out.println("==== 钻戒最优组合 ====");
System.out.printf("主石:%s, %.2fct%n", res.diamond().getStoneId(), res.diamond().getCarat());
System.out.printf("戒托:%s%n", res.mount().getMountId());
System.out.printf("合计成本:%.2f,综合评分:%.2f%n", res.totalCost(), res.score());
}
}
static void demoJadeMatch() {
var repo = new JadeRepository();
var svc = new JadeCustomService(repo);
var req = new JadeMatchRequest(
28, 33,
18, 22,
6, 8,
5000, 7000
);
var res = svc.matchOptimalBlank(req);
if (res != null) {
System.out.println("\n==== 匹配翡翠毛料 ====");
System.out.printf("毛料ID:%s,利用率:%.2f%n", res.getBlankId(), res.getUsableRate());
}
}
static void demoPricing() {
var svc = new ProductPricingService();
var req = new PriceOptRequest(1680, Settings.MIN_MARKUP_COEFF, Settings.MAX_MARKUP_COEFF, Settings.PRICE_ITER_STEP);
var res = svc.calcOptimalPrice(req);
System.out.println("\n==== 动态定价结果 ====");
System.out.printf("最优加价系数:%.2f%n", res.bestCoeff());
System.out.printf("建议售价:%.2f%n", res.bestSellPrice());
System.out.printf("预期最大毛利:%.2f%n", res.maxGrossProfit());
}
public void Demo()
{
demoRecommend();
demoJadeMatch();
demoPricing();
}
}
输出:


379

被折叠的 条评论
为什么被折叠?



