Fractal Softworks Forum

Please login or register.

Login with username, password and session length
Advanced search  

News:

Starsector 0.97a is out! (02/02/24); New blog post: Simulator Enhancements (03/13/24)

Pages: 1 [2]

Author Topic: Economy issues with dynamically generated sector  (Read 5846 times)

Alex

  • Administrator
  • Admiral
  • *****
  • Posts: 23988
    • View Profile
Re: Economy issues with dynamically generated sector
« Reply #15 on: October 02, 2015, 10:38:39 PM »

It could happen, yeah. The economy produces/buys/sells things in chunks, so it never exactly balances out and there is likely to be some degree of back and forth when it's near the balance point.
Logged

Histidine

  • Admiral
  • *****
  • Posts: 4661
    • View Profile
    • GitHub profile
Re: Economy issues with dynamically generated sector
« Reply #16 on: December 08, 2015, 03:44:19 AM »

So it seems my after-the-fact economy balancer (add/remove market conditions based on estimated supply/demand) is not up to the task before it. Before I carve it up and put it together again, a few questions:

First: Can I count on market.getCommodityData(commodity).getDemand().getDemand().modified to return reasonably accurate values if called before the economy load phase at start? Should I call market.reapplyConditions() first?

Second: in Population.java:
Code: java
		float crewAndMarines = market.getDemand(Commodities.MARINES).getRollingAverageStockpileUtility();
crewAndMarines += market.getDemand(Commodities.REGULAR_CREW).getRollingAverageStockpileUtility();

market.getDemand(Commodities.SUPPLIES).getDemand().modifyFlat(id, crewAndMarines * ConditionData.POPULATION_SUPPLIES_FOR_CREW_MARINES);
Barring the getDemand() thing, is there a way to get how much supplies will be demanded in this fashion? Or at least some rule of thumb I can use?
« Last Edit: December 08, 2015, 03:50:05 PM by Histidine »
Logged

Alex

  • Administrator
  • Admiral
  • *****
  • Posts: 23988
    • View Profile
Re: Economy issues with dynamically generated sector
« Reply #17 on: December 08, 2015, 10:35:20 AM »

    First: Can I count on market.getCommodityData(commodity).getDemand().getDemand().modified to return reasonably accurate values if called before the economy load phase at start? Should I call market.reapplyConditions() first?[/li][/list]

    You mean in ModPlugin.onNewGame(), right? Before ModPlugin.onNewGameAfterEconomyLoad()?

    At that point, the MarketAPI objects don't even exist.


    Second: in Population.java:
    Code: java
    		float crewAndMarines = market.getDemand(Commodities.MARINES).getRollingAverageStockpileUtility();
    crewAndMarines += market.getDemand(Commodities.REGULAR_CREW).getRollingAverageStockpileUtility();

    market.getDemand(Commodities.SUPPLIES).getDemand().modifyFlat(id, crewAndMarines * ConditionData.POPULATION_SUPPLIES_FOR_CREW_MARINES);
    Barring the getDemand() thing, is there a way to get how much supplies will be demanded in this fashion? Or at least some rule of thumb I can use?

    I don't think so, and that's a problem. I think this is one of the things that's making it difficult for the economy to stabilize; I'll have to take a closer look at it at some point.

    For now, I would suggest trying a couple of things:
    1) Reducing "price variability" for all commodities, to something in the 1-3 range. If it's at 0, prices won't be affect by supply/demand at all. This will affect shortage/disruption events, though, likely making them less profitable. Probably the easier option with more downsides.

    2) You might "fudge" the economy after it's loaded, which I'd imagine is what you're already thinking about. So, say you want to make sure supplies are balanced supply/demand wise. In onNewGameAfterEconomyLoad(), you might then:
    - Set the average and current stockpiles of supplies everywhere to be equal to the local demand, just so it starts from a good place
    - Compute the total demand
    - Do whatever market condition fudging necessary to make supply match demand. In a more direct way, i.e. not just adding autofactories (which need a chain of commodities to work properly - if you're lacking ore or whatnot, you may end up underproducing supplies), but just adding a fixed +X supplies supply to autofactories.

    In fact, if you do this every month or so, that seems like it wouldn't even be computationally expensive. Figure out total demand for supplies, figure out supply production, and figure out what X should be based on that. All linear time with small data sets.
    Logged

    Histidine

    • Admiral
    • *****
    • Posts: 4661
      • View Profile
      • GitHub profile
    Re: Economy issues with dynamically generated sector
    « Reply #18 on: December 08, 2015, 08:50:27 PM »

    Hmm, reducing variability for at least some commodities might be a good idea if my first retry doesn't work.
    Tampering with the output of market conditions as proposed feels pretty... unclean, but I guess it's an option if I really, really need it...

      First: Can I count on market.getCommodityData(commodity).getDemand().getDemand().modified to return reasonably accurate values if called before the economy load phase at start? Should I call market.reapplyConditions() first?[/li][/list]

      You mean in ModPlugin.onNewGame(), right? Before ModPlugin.onNewGameAfterEconomyLoad()?

      At that point, the MarketAPI objects don't even exist.
      What I do at present:
      Spoiler
      Code
      "newGameCreationEntryPoint":"exerelin.world.ExerelinSectorGen",

      From its generate() method, ExerelinSectorGen calls:
      Code: java
      	protected MarketAPI addMarketToEntity(SectorEntityToken entity, EntityData data, String factionId)
      {
      [...]
      MarketAPI newMarket = Global.getFactory().createMarket(entity.getId() /*+ "_market"*/, entity.getName(), marketSize);
      [...]
      newMarket.addCondition(...);
      [...]
      // example
      domesticGoodsDemand += ExerelinUtilsMarket.getCommodityDemand(newMarket, Commodities.DOMESTIC_GOODS), true);
      }

      Code: java
      	public static float getCommodityDemand(MarketAPI market, String commodity, boolean consumingOnly)
      {
      float demand = market.getCommodityData(commodity).getDemand().getDemand().modified;
      if (consumingOnly) demand -= market.getCommodityData(commodity).getDemand().getNonConsumingDemand().modified;
      return demand;
      }
      [close]

      So if the MarketAPI doesn't actually exist at this point, am I working with a temporary object? If so, can I still get the commodity demand in this manner?

      (Anyway I'll probably end up doing it the other way I had planned: manually calculating the demand created by each market condition, by replicating the code from the condition class's apply() method)
      « Last Edit: December 08, 2015, 08:52:11 PM by Histidine »
      Logged

      speeder

      • Captain
      • ****
      • Posts: 364
        • View Profile
      Re: Economy issues with dynamically generated sector
      « Reply #19 on: December 09, 2015, 03:52:29 PM »

      Histidine I think I just noticed something on my own mod (that is now running with only vanilla) that you might find relevant:

      Seemly over time vanilla settings tend to eat up all supplies.

      My mod can "stabilize" the economy much faster (it updates the economy every day, in a bit smaller steps, also update events every 15 days).

      I noticed Jangala on my mod, unless I reduced the initial economy calculation (vanilla is 1000 days, with 30 days update, thus 33 updates, my mod updates 365 days before running) would always have supplies priced around 320.

      I then made an event that fire every 15 days, and print to me the CommodityStatTracker info on Supplies...

      Basically, after a while the economy settles producing 40.000 supplies and demanding 90.000 supplies, and the average supply price settles at 240.

      I went to check that on market conditions, and seemly there are several conditions that consume supplies, but only heavy industry make them, considering heavy industry is seemly not that common... (at least when playing normally I never find where to sell metals and whatnot).


      This MAYBE is result of me ***-up something, so don't rely on my numbers, but I tought you mind find that information interesting.


      EDIT:

      I checked more, including cheating to teleport to heavy industries, and found out the issue is seemly volatiles and organics being undersupplied.

      When Alex updated to 0.7 he seemly boosted them both, spamming markets and making people complain, then he removed them back (and fixed a bug with volatiles being created in ludicrous amounts).

      Now everyone is missing those, if you change "minsupply" from 10 to 1 on the settings, then the problem become even more obvious, and almost all markets drop their "demand met" number visible on the interface to about 40%.
      « Last Edit: December 09, 2015, 04:17:06 PM by speeder »
      Logged

      Alex

      • Administrator
      • Admiral
      • *****
      • Posts: 23988
        • View Profile
      Re: Economy issues with dynamically generated sector
      « Reply #20 on: December 09, 2015, 05:05:00 PM »

      @Histidine: Well, if you create the MarketAPI yourself, it'll exist. I just mean the ones defined in economy.json/related files don't exist at that point.


      I checked more, including cheating to teleport to heavy industries, and found out the issue is seemly volatiles and organics being undersupplied.

      That could be a potential issue that might trip up a mod's economy - a lack of up-the-chain raw resources could easily result in not enough supplies. So can "unexpected" demand due to crew/marines consuming more and more supplies as they're generated by the economy.

      When Alex updated to 0.7 he seemly boosted them both, spamming markets and making people complain, then he removed them back (and fixed a bug with volatiles being created in ludicrous amounts).

      Now everyone is missing those, if you change "minsupply" from 10 to 1 on the settings, then the problem become even more obvious, and almost all markets drop their "demand met" number visible on the interface to about 40%.

      This is wrong. The reduction of stuff for sale is purely a UI fix and did not touch the underlying production of volatiles/organics/etc.

      If your mod settles down with the global supply of supplies meeting half the global demand, with the vanilla starting conditions, yeah, it's definitely got a problem somewhere.
      Logged
      Pages: 1 [2]