mars-sim icon indicating copy to clipboard operation
mars-sim copied to clipboard

Gets a quote of the value/price/quantity of an particular good across all settlements

Open mokun opened this issue 3 years ago • 18 comments

Is your feature request related to a problem? Please describe.

  1. Imagine the commander of a settlement would like to get a quote on the value, price and quantity of a good (part/resource/vehicle/equipment) across all settlements via the text console interface.
  2. He should be able to not just check on the value and price but also be able to print out this contract/report with confirmed mars date and time showing this price quote.
  3. Then he can start a delivery mission to purchase this item.

Describe the solution you'd like

  1. This is probably multi-step feature.
  2. First, create a command for choosing the item of interest
  3. Second, create a command for starting a delivery mission
  4. Third allow the player to negotiate the price
  5. As the bidder, he may choose to agree or disagree what price he would offer on an item and return with a price from a bidder.
  6. He also has options to choose what settlement (since distances on Mars still matters) to acquire from as Delivery Drone has limited range.
  7. Whatever both parties agree would form a contract and will be stored and is accessible/viewable even after the delivery is done.

mokun avatar Jun 14 '22 04:06 mokun

@bevans2000

Can you create the command to give a price quote ?

This is somehow similar to setting up a delivery or trading mission but it's via the text console.

Also, the player would be actively negotiating and controlling what price he's willing to pay, instead of the old, automated way that's based on the traders' skill from both side.

mokun avatar Jun 14 '22 04:06 mokun

Creating Missions via the Console would be very helpful as I see the Console Commands being part of the RestAPI (#542).

I'll have a look at this.

bevans2000 avatar Jun 14 '22 07:06 bevans2000

I suppose the player would be interested in comparing the price across all settlement on any resources that the player considers it as "excess".

So, what would it take to create a command for the player to see an ascending order of all resources showing possible profits in terms of % between his settlement and another settlement nearby ?

mokun avatar Jun 21 '22 03:06 mokun

Its not too difficult. It would need 2 parts. A utility class to workout the profit for the excess resources at their home Settlement against a selected Settlement. This logic could be reused elsewhere. Second part would be a Command to drive the utility. It turns of profit what is the cost price? You are thinking the profit is the difference between the Resource prices in the 2 Settlements.

bevans2000 avatar Jun 21 '22 05:06 bevans2000

How are profits calculated as all Good have the same price as it's a property on the Good class.

bevans2000 avatar Jun 21 '22 07:06 bevans2000

what is the cost price?

Good question. We'll need to come up with a fair and neat definition.

To me, it should be the cost of the output resources minus the cost of the input resources.

Do you agree with that ?

For now, I've only worked out less than half of this.

I've calculated the output base cost (in terms of the output resources) in computeBaseCost() in Good.

But I haven't figured out the input base cost "input base cost" (in terms of the input resources) yet.

mokun avatar Jun 21 '22 14:06 mokun

For now, I have computeCost() in Good as follows :

	/**
	 * Calculate the base cost of each good
	 */
	public void computeCost() {
		manufactureProcessInfos = ManufactureUtil.getManufactureProcessesWithGivenOutput(name);
		foodProductionProcessInfos = FoodProductionUtil.getFoodProductionProcessesWithGivenOutput(name);

//		componentManuInfos = ManufactureUtil.getManufactureProcessesWithGivenInput(name);
//		componentFoodInfos = FoodProductionUtil.getFoodProductionProcessesWithGivenInput(name);
//		resourceProcesses = BuildingConfig.getResourceProcessMap();

		// Compute the cost of output
		computeBaseCost();
		// Compute the cost of output
		computeOutputCost();
	}

mokun avatar Jun 21 '22 14:06 mokun

all Good have the same price as it's a property on the Good class.

Not exactly.

At the start, the price and value should be the same for all settlements.

But as time goes by, the price and value should fluctuate between them. At the end, no two settlement would have the same.

But to avoid deviating too much and for sanity's sake, I do save an average inter-market value as a bridge among the settlements. See below tuneToAverageValue() in GoodManager.

	private double tuneToAverageValue(Good good, double value) {
		// Gets the inter-market value among the settlements
		double average = good.getAverageGoodValue();
		double newAve0 = 0;

		if (average == 0) {
			newAve0 = value;
		}

		else {
			newAve0 = .1 * average + .9 * value;

			double newAve1 = 0;

			if (average > value)
				newAve1 = 1.1 * value;
			else
				newAve1 = 1.1 * average;

			newAve0 = Math.min(newAve0, newAve1);

			if (newAve0 > MAX_FINAL_VP)
				newAve0 = MAX_FINAL_VP;
		}

		good.setAverageGoodValue(newAve0);

		return newAve0;
	}

mokun avatar Jun 21 '22 14:06 mokun

Therefore, those methods in Good below are for finding and keeping the averages among all the settlement :

	public double getAverageGoodValue() {
		return averageGoodValue;
	}

	public void setAverageGoodValue(double value) {
		averageGoodValue = value;
	}

	public void adjustGoodValue() {
		// deflate the value by 5%
		if (averageGoodValue > 10)
			averageGoodValue = .95 * averageGoodValue;

		// Inflate the value by 5%
		else if (averageGoodValue < 1)
			averageGoodValue = 1.05 * averageGoodValue;
	}

mokun avatar Jun 21 '22 14:06 mokun

Each GoodManager is responsible for storing the demand, the supply, and the value of a good as follows :

	private Map<Integer, Double> goodsValues = new HashMap<>();
	private Map<Integer, Double> tradeCache = new HashMap<>();

	private Map<Integer, Double> amountDemandCache = new HashMap<>();
	private Map<Integer, Double> partDemandCache = new HashMap<>();
	private Map<Integer, Double> vehicleDemandCache = new HashMap<>();
	private Map<Integer, Double> equipmentDemandCache = new HashMap<>();

	private Map<Integer, Integer> deflationIndexMap = new HashMap<>();

	private Map<Integer, Double> amountSupplyCache = new HashMap<>();
	private Map<Integer, Double> partSupplyCache = new HashMap<>();

	private Map<Integer, Double> vehicleSupplyCache = new HashMap<>();
	private Map<Integer, Double> equipmentSupplyCache = new HashMap<>();
				
	private Map<String, Double> vehicleBuyValueCache;
	private Map<String, Double> vehicleSellValueCache;

mokun avatar Jun 21 '22 14:06 mokun

It turns of profit what is the cost price? You are thinking the profit is the difference between the Resource prices in the 2 Settlements.

By definition, the difference between Cost and Price is Profit.

Anyway, for now, in GoodsManager we have

	/**
	 * Gets the price per item for a good
	 *
	 * @param good
	 * @return
	 */
	public double getPricePerItem(Good good) {
		return good.getCostOutput();
	}

	/**
	 * Gets the price per item for a good
	 *
	 * @param id the good id
	 * @return
	 */
	public double getPricePerItem(int id) {
		return GoodsUtil.getResourceGood(id).getCostOutput();
	}

For now, the Cost is the same as the Price because I have wanted to do the following but haven't decided how to compute what MOD is for each type of goods as follow :

price = MOD * value + cost

One problem is that the Value of a good can fluctuate greatly As a result, it would greatly affect the Price. So MOD will be incredibly important for toning down or modulating the Value

mokun avatar Jun 21 '22 22:06 mokun

All these lookups of entity by integer is going to mount up to consume processing time. Both price and cost have to vary independently at all Settlements.

bevans2000 avatar Jun 21 '22 23:06 bevans2000

All these lookups of entity by integer is going to mount up to consume processing time.

We could let player to customize and set the frequency of the demand/supply/value/price adjustment

mokun avatar Jun 22 '22 02:06 mokun

I've just added another brand new column called "Cost" in the TradeTableModel as follows :

image

The relationship between cost and price and profit is as follows :

  1. profit = cost * factor * log(value + 1)
  2. price = cost * (1 + profit)

This thread is similar to https://github.com/mars-sim/mars-sim/issues/598

mokun avatar Jun 23 '22 00:06 mokun

@bevans2000 @Urwumpe

It turns of profit what is the cost price? You are thinking the profit is the difference between the Resource prices in the 2 Settlements.

Now settlements are able to compute the cost, price and profit more REALISTIC than before.

Now, let's say settlement A can sell 3 hammers. Each costs 1 to produce but is willing to sell one for 1.5. The profit will be 0.5

On the other hand, settlement B also have 3 hammers. It costs 1.5 and will cut 0.3 profit by selling it at 1.8

At the same time, settlement C has the best capability in making hammers. It costs only 0.5 to make and sell to 1.2 while taking 0.7 profit. Since it's the lowest price across the surface of Mars, people will trade with Settlement C for hammers.

Settlement Resource Cost $ Price $ Profit $
A hammer 1.0 1.5 0.5
B hammer 1.5 1.8 0.3
C hammer 0.5 1.2 0.7

Of course, a settlement will need to consider the fuel cost, the logistic cost, the time cost involved before deciding on a trade or prompt of producing it in-house.

Another aspect is to design the algorithm for various skill level traders to recognize whatever opportunity presented to make more profit -- if being economical is the only driving force of that settlement.

The commander may have directive in place to produce it on its own so that settlers would have a chance to flex the muscle and improve upon his material science skill level.

Later on, perhaps we could design a set of rules of acquisitions. A high level trader would make use of rules 1-10. But a low level trader knows rule 1-5, etc.

mokun avatar Jun 23 '22 20:06 mokun

@bevans2000

I'd like to explore more on setting up legal contracts for transactions.

Can you create a new console command for getting a quote on an item resource from all settlements ?

It's like in real world, creating a legal contract is crucial in business.

Therefore, it's also important when trading with other settlements.

A contract will include:

  1. a good with quantity
  2. its guarantee price
  3. time limit for this price to be valid
  4. deadline for it to be delivered. If passing the deadline, reduce the price by a certain percent based on the amount of time delayed (and, say, losing up to 20% of original price)

We can work on this further in future.

mokun avatar Oct 23 '22 18:10 mokun

@bevans2000

How are profits calculated as all Good have the same price as it's a property on the Good class.

Thanks for making a lot of progress in overhauling GoodsManager last year.

As you know, each settlement has its own demand and supply value on each resource.

I think we're close to making cost not the same for each settlement as well since cost has to do with how much you pay for in manufacturing it and the manu capacity is different in each base.

By extension, the price will be different as well.

mokun avatar Jun 23 '23 19:06 mokun

So do you still want to create this price quote capability for AI or player commander ?

Say a simple UI will entail

  1. a table showing the price of a listing of surplus parts offered by another settlement
  2. AI/player may authorize what are the parts they want to sell.
  3. AI/player may submit a quote to acquire parts.
  4. AI/player will decide if a quote submitted by others are profitable or not
  5. AI/player will commit to that quote or change it and send out a good faith estimate
  6. If both parties agree, then a trading/delivery mission / session begins.

So, can we use the new project mission to create a brand new

mokun avatar Jun 23 '23 19:06 mokun